Prevent automatic ajax call with deferloading but without serverside processing
Prevent automatic ajax call with deferloading but without serverside processing
Just wondering is there a way to prevent an automatic ajax call on the initial load without using serverSide processing? I'm using asp core, and since the library isn't supported, I been replicating functionalities on the server. I read in the manual that deferLoading does what I need it to, but I need serverSide to be set to true. Is there a way around this? This is causing problems to fail on the server as certain criteria is not filled in yet.
This question has an accepted answers - jump to answer
Answers
Maybe you can describe the problem you are trying to solve in more detail. You could remove the
ajax
option from your Datatables config and use it externally when ready then userows.add()
to add the data to the blank Datatable. Not sure if that helps without knowing more about your requirements.Kevin
I'm not using rows.add(), I'm using datatables the same way as I'm using something like this example:
https://datatables.net/examples/ajax/objects.html
The problem is, it has automatic ajax fetching when you render the table. The web service needs a parameter to be sent, which isn't ready yet until a user inputs that information.
I'd like to defer the loading, hence, deferLoading, until I can call a redraw, or a ajax.reload() in order to send that new user input as the parameter.. initially this parameter is null -- which throws the error on the server.
I am creating a new way of handling this, by sending a piece of criteria info to the server, where if the data is null, just don't get the list. It will still make the call to the server regardless though.
Hi Dan,
This is one of @kthorngren 's examples here from a different thread - it shows how you can call the Ajax load after the table initialisation. In that example it's on a button press, but it could be anything. Is this something that would work?
Cheers,
Colin
It sounds like that isn't the full solution. And I'm afraid Dan, there isn't a complete solution for this one. The answer is that the
delayLoading
option was specifically implemented only for server-side processing. It was designed for cases when the table would be rendered in the default state by the server, and then new page requests in DataTable trigger a new data fetch.The closest you would get in client-side processing at the moment is to load the initial 10 (or whatever) rows from the DOM and then use an Ajax request to get the extra data.
delayLoading
isn't actually used much since it requires the data for the table to be laid out correctly (sorting, filtering, paging). Having that with client-side processing would increase the complexity of your code.I take the point that this would be a useful addition in some cases! But at the moment, I'm afraid its just not something that DataTables core supports. Something that would be good as a future enhancement though!
Allan
I understand Allan, thanks. The only work around I made was to send information to the server to dictate that nothing should be returned.
Colin's answer might be key though, where I can trigger some kind of event to fire off that ajax code.
I found a way to do this:
Declare a variable to determine initial state:
Then, make use of
ajax
as a function:Hello, Allan!
Are there any plans to include this functionality in the future? It's a shame to have to use workarounds for this.
One option is to not define the
ajax
option then useajax.url().load()
to load the data when ready, for example:http://live.datatables.net/wiqufunu/1/edit
This option is a bit limited as I don't think there is a way to provide other Ajax parameters.
Kevin
Note: Not specifying
ajax
will not render your custom toolbar. Just saying.@jhourlad Do you mean like this?
http://live.datatables.net/wiqufunu/12/edit
From this example.
Please provide an example oof the issue you are having.
Kevin