1

I am modified a document library view and try to increase width of one column. I added a script editor web part and added following:

<script type="text/javascript">
$(document).ready(function() {
$("TH.ms-vh2:contains('Title')").css("min-width", "250px"); 
});
</script>

It works fine at first load. But when I click Quick Edit view, the "title" column width is no longer 250px. When I click back to normal view, the "title" column width is not 250px, too. I think my javascript only load at first time I called the page.

How can I solve it? Thanks.

2
  • Unrelated to your specific problem, but have you checked out JSLink / CSR in SP2013 ? It's a better way to customize components at runtime with JS. Jul 16, 2014 at 11:50
  • 1
    Cameron, I briefly take a look and it seems not easy to catch up compare to Script editor web part. But I will definitely look into JSlink later.
    – Mark L
    Jul 16, 2014 at 16:41

1 Answer 1

2

I would use a content editor web part with a text file for a content source, then put a style tag in there and not use JavaScript at all...

<style>
    TH.ms-vh2:contains('Title') {
        min-width:250px;    
    }
</style>

You could also do this by editing the HTML Source directly in the content editor, but I find SharePoint thinks it knows how to enter my markup better than I do, and is quite frequently wrong...

If you still want to use JavaScript, I would still use a content editor with a text file for a content source, I just think script editors are a little fiddly to work with though...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.