stateLoadParams is not firing at first visit or an empty state.

stateLoadParams is not firing at first visit or an empty state.

Mr_PearlMr_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

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    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

  • Mr_PearlMr_Pearl Posts: 2Questions: 1Answers: 0

    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.

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    I get this default filter from API request and datatable is rendered before the request complete.

    When the request is complete maybe you can use state.loaded(). If its null then use column().search() to apply the search from the response.

    Kevin

Sign In or Register to comment.