Defer loading with bServerSide as 'false'.

Defer loading with bServerSide as 'false'.

AlelAlel Posts: 3Questions: 0Answers: 0
edited March 2013 in General
So, I have a table that I wish to populate with data from an AJAX source, but wish to use client-side sorting only. However, I also wish to defer the loading until I trigger it within an event callback (When a user clicks a button.) But this doesn't seem to work.

[code]
$profilesTable.dataTable({
sAjaxSource: Globals.base_url + '/accounts/ajax_list_profile_source',
iDeferLoading: 0,
bServerSide: false,
aaSorting: [[4, 'desc']],
fnServerParams: function(data){
var currentAccount = $(this).data('currentAccount');
if(currentAccount != null){
data.push({name: 'account_id', value: currentAccount});
}
}
});

[/code]

I tried turning bServerSide to 'true', which causes the XHR request to be deferred, but it is really imperative that I use client-side sorting.

How can I achieve this?

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Deferred loading is tied to server-side processing at this time. To be able to do a sort, DataTables requires the full dataset, with it wouldn't have the above situation. Indeed you'd also need to implement sorting on the server-side for the output HTML table to have the first 10 rows drawn correctly.

    So currently, iDeferLoading requires server-side processing, not client-side. This might change in future, but I'm not sure I see a huge advantage in it since, as I say, you'd need to reimplement the first sort on the server. However, patches / pull requests for this are very welcome.

    Allan
  • AlelAlel Posts: 3Questions: 0Answers: 0
    Hi allan,

    I understand.

    However is there a way to effectively delay the fetching of the data until a certain trigger, given that I wish to use client-side only?

    (Back-story: My data is being stored in such a way that sorting server-side is resource-heavy. This is why I require this particular behavior. And the reason why I want the initial loading deferred is that the server call requires a set of parameters that I mine from a form in the page. Until the form is filled up and ready, then I'd like the DataTable to fetch.)

    Regards,

    Alel
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Can you not just wait to initialise the table at the point you want it to retrieve the data, rather than having an empty table?

    Allan
This discussion has been closed.