Custom search function being called many, many, many times on page load

Custom search function being called many, many, many times on page load

bblake8480bblake8480 Posts: 1Questions: 1Answers: 0

I have never worked with DataTables before and have inherited support for an existing application that uses it. Users are complaining of extremely slow page loads. What I found so far is that the DataTable has a custom search function defined for it using $.fn.dataTable.ext.search.push(functionName). When the page loads, it calls this function somewhere around 30,000 times, give or take a few hundred. The default data set is 930 rows with 15 columns. It's not a large data set.

The whole page takes nearly 3 minutes to load. I tried updating the reference to the datatables library to use the latest version from the CDN with no effect. Based on the documentation I have tried adding the following:
* Setting the searchDelay value (no effect)
* setting the search function to be use the util.throttle call (no effect)
* A basic JavaScript debounce in the custom search function (page loads quickly, because no data appears)
* Setting deferRender (loads faster initially, but scrolling becomes excruciating slow)

Not sure where to go from here. Looking for ideas on what the problem might be or what I can try next to solve this for the client.

Answers

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    For testing have you tried removing search plugin $.fn.dataTable.ext.search.push(functionName).?

    Here is an example with 57 rows that has a search plugin. The console output shows it is called once during the Datatable load.

    If yours is called 30,000 times on page load then there is probably some custom code in iniComplete, drawCallback or one of the other callbacks that is calling draw() which would invoke the search plugin. Please post your Javascript so we can see if there is anything obvious.

    Kevin

This discussion has been closed.