stateLoadParams is not firing at first visit or an empty state.
stateLoadParams is not firing at first visit or an empty state.
Mr_Pearl
Posts: 2Questions: 1Answers: 0
I'm trying to add a column filter manually if the particular column filter is empty using stateLoadParams. It works fine when the state is saved in localstorage. But once I delete the state from localstorage, the stateLoadParams is not getting fired. Is there any other way to do this.
this.dtOptions.stateLoadParams = function(settings, data) {
data.columns[0].search.search = 'filter';
}
Answers
Maybe you can use
searchCols
to define the initial search criteria if there is no state to load. Something like this:https://live.datatables.net/nirepela/1/edit
Kevin
It'll work if the initial filter value is a default one. But in my case it's not and I get this default filter from API request and datatable is rendered before the request complete. What I need is a function to set initial filter if the state is empty or null.
When the request is complete maybe you can use
state.loaded()
. If itsnull
then usecolumn().search()
to apply the search from the response.Kevin