If loading JavaScript by CEWP onto a SharePoint page you can do nice things like changing background color of the list items by value or adding datepicker functionality for items on the list view.

Example here: enter image description here

Example picture shows list item backgrounds controled by value and date picker in list view to update column.

This works fine as long as the list view is not "updated". If the list is manually filtered by value or sorted by a column all script functionality seems to be lost - no more background color and no more date picker functionality.

Both just works because the script in the CEWP is loaded after the list webpart was loaded. When changing the appearance of the list webpart by filtering/sorting the scripts seem to lose "connectivity". Any ideas to get around this?

  • What version of SharePoint are you using? Also, just to clarify, are you loading a JS file with the CEWP and then using that to customize a listview on the page? Commented Jan 25, 2018 at 14:02
  • It is SharePoint 2013 on premise. I am using a page with 2 webparts -> App webpart of the list and CEWP loading a textfile with javascript from the site assets. Part of the textfile: <script src="PartOfTheUrl/SiteAssets/Scripts/jquery-3.1.0.min.js"; type="text/javascript"></script><script> $(document).ready(function(){ $Text = $("td .ms-vb2:contains('SAP')").filter(function() {SomeJsHere}); </script>
    – PhilFancy
    Commented Jan 25, 2018 at 14:06
  • The recommended approach for applying customizations to a listview in SP2013 is to use JSLink either at the list or field level. You can also still use XSLT but I suspect that will be much harder for your jQuery customizations. Your approach relies on timing and is unaware of rendering events. You could try and attach events to the sorting columns, etc. but even then, your approach will remain fragile. Commented Jan 25, 2018 at 14:12


Your Answer

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

Browse other questions tagged or ask your own question.