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"" 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>
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