DataTable setState before loading initial server data

Hi,

I’m having issue with datatable state, I’m pulling datatable data from server, when I add $$('datatable').setState(datatable_state); in ready() method the state get set but after the first initial load (i.e that causes double ajax request)

my question is, how to set datatable state before initial server load ? to avoid double ajax call on first init.

Thank
Mustapha

Hello @mgraph2010,

when I add $$(‘datatable’).setState(datatable_state) in ready() method the state is set but only after the first initial load

The ready() handler is fired as soon as the component has been completely initialized (i.e. the component has been fully rendered and the data has been loaded as well). Essentially, by this point, the data loading is already done. That said, I am still not quite sure as to why there are multiple ajax calls in your case, since the setState() method is responsible for setting the overall structure of the datatable, and does not trigger data loading in any way. As far as I can see, the only reason why this is happening is because of the filters used within the table. In particular, if you are using server filters, an additional request will be issued each time you set the state to a table with a value inside the filter input.

my question is, how to set datatable state before initial server load ? to avoid double ajax call (initial server call & call after setting the state) ?

Incidentally, you could try setting the state right after the table has been rendered but the data has not yet been parsed to it. This exact moment can be caught with the help of the onAfterRender method. Please note that this inherently doesn’t change the way the function works, and the request containing filtering parameters will still be issued. Depending on the exact functionality you are looking for, certain workarounds are possible. For example, you could alter the state object to exclude any filtering queries, meaning you will not issue an additional request after the state is set. Here is how this could look like: https://snippet.webix.com/0b2amiqk.

avoid double ajax call

Could you please provide more information about the requests that are being issued? Are there actually any data filtering requests or do the requests simply relate to the initial data loading process? More information about the issue in general would be welcome as well.