0

On my Sharepoint 2016 page I have a list and a search function created via Script Editor that filters the list. I have this exact same code working on a Sharepoint 2013 page fine, but on this 2016 page the script doesn't work unless I go into edit mode. Sometimes after saving and leaving edit mode it will then work until I refresh the page, then it doesn't work again. I think it's because the script is running before the list has loaded. I've tried various one-line solutions including Javascript and ServicePoint functions to delay the page loading/script running which haven't worked, maybe I'm just not using them correctly. Inexperienced Coder. I've included the full Script Editor code (exluding the local jquery source):

    <div style="padding: 5px; border: 1px solid #FF5646; width: 60%; margin: 10px auto 0pt; background: none repeat scroll 0% 0% #f2f2f2; display: block;">
  <h3 style="text-align: center;">Patient Search: <input type="text&quot;" style="padding: 10px;" id="filterInput" class="filter"</h3>
</div>
</style>

<script type="text/javascript" src="http://mydomain.com/js/jquery-3.3.1.min.js">

$(document).ready(function() {

 var list = $("table.ms-listviewtable");
 // Loads the list from table
 var listItems = $("table.ms-listviewtable tr:not(.ms-viewheadertr)");
 // Filters the table
 var input = $("input#filterInput");

 input.keyup(function() // When typing the search box, the function runs...
 {
    //Insert line or function here to convert first letter to uppercase?

        listItems.each(function() // For every item in the catalogue
     {
 var text = $(this).text().toLowerCase(); // Load all the text values

 if (text.indexOf(input.val().toLowerCase()) != -1) // Compare the user input to the text value
 {
      $(this).show();// If it matches, show it
 }
 else
 {
      $(this).hide(); // If not, hide it
 }
     });
 });

 });

 </script>​​​
  • Is Minimal Download Strategy feature enabled in your site? – Rohit Waghela Nov 14 at 7:32
  • Just checked and yes it is - do I need to disable it or is there a workaround that can be applied per page? – Celias Nov 14 at 8:20
  • Please try to disable and check..But Remember it is just a work around. – Rohit Waghela Nov 14 at 8:31
  • Basically MDS (when activated), it doesn't do a full page load when refirecting from one page to another to improve the performance. and the events like document.ready may not fire until the page is refreshed. May be this was causing the issue to your functionality :) – Rohit Waghela Nov 14 at 8:32
  • 1
    Disabling MDS has worked, I'm happy to use this as a workaround. Many thanks! – Celias Nov 14 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.