Questions on: bStateSave

Questions on: bStateSave

BillyThaKidBillyThaKid Posts: 2Questions: 0Answers: 0
edited February 2013 in DataTables 1.9
Hey Allan,

Thanks for the extraordinarily useful plugin!!

So here's my scenario - I have a datatable with properties set to true for bServerSide, bStateSave, and bPaginate. I'm returning records using sAjaxSource (via jSon data). Each of the results links off to a news story on a separate page. Everything is pretty much working as expected, however, I'm wondering if anything can be done regarding the following -

After running a search for something, clicking on a result, and clicking the back button, my sAjaxSource method gets hit again - resulting in the 'Processing' text to come up again. You'd think that the method wouldn't be hit again and that the Ajax results would still be loaded from the first hit. I also noticed that this only seems to happen with Internet Explorer & Chrome. Firefox doesn't seem to have this issue (the method doesn't get hit after hitting the back button). Here's the code I'm using -

[code]
var oTable = $('#dTable').dataTable({
"bProcessing": true,
"bServerSide": true,
"bStateSave": true,
"fnStateSave": function (oSettings, oData) { save_dt_view(oSettings, oData); },
"fnStateLoad": function (oSettings) { return load_dt_view(oSettings); },
"bPaginate": true,
"bAutoWidth": false,
"sAjaxSource": "/Json/Results",
"bLengthChange": true,
"bFilter": true,
"iDisplayLength": 10,
"aLengthMenu": [[10, 20, 30, 50], [10, 20, 30, 50]],
"sPaginationType": "full_numbers",
"oLanguage": {
"sSearch": "Search:"
},
"sDom": '<"top"lf<"clear">>rt<"bottom"ip<"clear">>',
"fnDrawCallback": function () {
var filterId = document.getElementById('input_filter');
var filterChildNode = filterId.firstChild.childNodes[1].value;

$("#dTable").removeHighlight().highlight(filterChildNode);
},
"aaSorting": [[0, "desc"]]
});


[/code]

Any advice would be appreciated!

Thanks!!

Matt

Replies

  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin
    > You'd think that the method wouldn't be hit again and that the Ajax results would still be loaded from the first hit

    DataTables sets the jQuery anti-cache parameter by default, so that might well be what is causing the problem. You can either override using fnServerData or just after that one line in DataTables.

    DataTables 1.10 will make it possible to do:

    [code]
    $('#dTable').dataTable( {
    ajax: {
    url: '/Json/Results',
    cache: true
    },
    ...
    } );
    [/code]

    That's already in Git if you want to try it.

    Allan
  • BillyThaKidBillyThaKid Posts: 2Questions: 0Answers: 0
    The new version works pretty much as expected. The only thing I would note is that the page only seems to cache after clicking back the 2nd time. I.e. - enter in a search term, 5 results come up, click on one of the results, click the back button - the method is hit again along with the results Processing being call out. However, clicking on any result after clicking the 1st result and then clicking the back button - the method is not hit and the loading icon is not present (which is what I expected with the first result). If this was by design I understand. Just thought I'd mention it in case.

    Thanks again for your help!!

    Matt
This discussion has been closed.