Server side processing re-initilize datatable problem

Server side processing re-initilize datatable problem

chandrashekarchandrashekar Posts: 8Questions: 0Answers: 0
edited October 2010 in General
Hi All,

i am new to jquery and datable. I am using the 1.7.3 and I am having issues with the tables re-initializing using the destroy code. i am doing server side processing for pagination and sorting.

datatable has following functions
[code]
oTable = $('#asatable').dataTable( {
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"bFilter": false,
"bRetrieve": false,
"bDestroy": true,
"bStateSave": false,
"sPaginationType": "full_numbers",
"sAjaxSource": 'mypage_json.jsp?fromDate='+fromDate+'&toDate='+toDate,
"sDom": 'T<"clear"><"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>',
"fnServerData": function ( sSource, aoData, fnDataTablesPipeline ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnDataTablesPipeline
} );
},
"aaSorting": [[ 2, "desc" ]],
"oLanguage": {
"sLengthMenu": ' show 1020304050 per page',
"sZeroRecords": "No records to display" }
});
[/code]

i need to generate table after form is submitted, table and form are in same page.
on re-submitting the form table should be re-initializing with new data. this is working as expected.
but when i click on the header to sort, previous data is loading back.

i add this piece of code to clear cache on form submit. but this approach is not working.

[code]
var oCache = {
iCacheLower: -1
};
[/code]


please help me with any suggestion to solve this issue.

thanks
chandru

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi chandru,

    Does it work correctly without using the pipining? I presume it does, in which case there just needs to be a way to clear out the cache, which is probably just oCache.iCacheLower = -1 (although I've not tried it! :-) ).

    Allan
  • chandrashekarchandrashekar Posts: 8Questions: 0Answers: 0
    Hi Allan,

    Thanks for the response,

    I have tried oCache.iCacheLower = -1 to clear cache, but i was not working,

    pipining looks likes like
    [code]
    function fnDataTablesPipeline ( sSource, aoData, fnCallback ) {
    var iPipe = 1; /* Ajust the pipe size */

    var bNeedServer = false;
    var sEcho = fnGetKey(aoData, "sEcho");
    var iRequestStart = fnGetKey(aoData, "iDisplayStart");
    var iRequestLength = fnGetKey(aoData, "iDisplayLength");
    var iRequestEnd = iRequestStart + iRequestLength;
    oCache.iDisplayStart = iRequestStart;

    /* outside pipeline? */
    if ( oCache.iCacheLower < 0 || iRequestStart < oCache.iCacheLower || iRequestEnd > oCache.iCacheUpper )
    {
    bNeedServer = true;
    }

    /* sorting etc changed? */
    if ( oCache.lastRequest && !bNeedServer )
    {
    //alert(oCache.lastRequest)
    for( var i=0, iLen=aoData.length ; i
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    So does it work if you don't use pipelining? Also you've got the paging size set to 1 - is there any need to use pipelining at all?

    Allan
  • chandrashekarchandrashekar Posts: 8Questions: 0Answers: 0
    Hi Allan,

    I am new to this, so sorry if i am wrong. also iam spiting message because it dont allow more than 500 char

    code for datatable
    [code]
    oTable = $('#asatable').dataTable( {
    "bJQueryUI": true,
    "bProcessing": true,
    "bServerSide": true,
    "bFilter": false,
    "bRetrieve": false,
    "bDestroy": true,
    "bStateSave": false,
    "sPaginationType": "full_numbers",
    "sAjaxSource": 'mypage.jsp?fromDate='+fromDate+'&toDate='+toDate,
    "sDom": 'T<"clear"><"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>',
    "fnServerData": fnDataTablesPipeline,
    "aaSorting": [[ 2, "desc" ]],
    "oLanguage": {
    "sLengthMenu": ' show 1020304050 per page',
    "sZeroRecords": "No records to display" }
    });
    [/code]
  • chandrashekarchandrashekar Posts: 8Questions: 0Answers: 0
    code for pipelining -
    [code]
    var oCache = {
    iCacheLower: -1
    };
    function fnSetKey( aoData, sKey, mValue )
    {
    for ( var i=0, iLen=aoData.length ; i
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    That's a lot of code to scan read :-). If you simply remove the line ""fnServerData": fnDataTablesPipeline", does it work as you would expect? If so, the issue is in the pipe line. If not then we need to look else where. I still don't see the point of doing pipelining at all when the page size is 1.

    Allan
  • chandrashekarchandrashekar Posts: 8Questions: 0Answers: 0
    i have more 50,000 rows as result, so using pipeline loading page for pagination. i will be changing page size to 10.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Okay that makes sense. So does it work if you remove the pipelining?

    Allan
  • chandrashekarchandrashekar Posts: 8Questions: 0Answers: 0
    no, still the issues remains, i get this issue only when i do sorting. sorting is doing Ajax submit.

    when i recreate new table with new data, then if i click to sort, its sorting for my previous sSource, my assumption was when i destroy data-table, sSource associated will also be removed.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I'm afraid I'm not seeing what the problem would be - I don't understand why you would be getting the original data back, in the second table, unless there is some kind of caching going on. Are you using IE, Firefox, Safari, something else? Can you give us a link which would be very helpful?

    Allan
  • chandrashekarchandrashekar Posts: 8Questions: 0Answers: 0
    I am working on local dev environment so link could be shared.

    in IE 7 i am not able to generated datatable.
    "DataTables warning: JSON data from server failed to load or be parsed, this is most likely to be caused by a JSON formatting error"
This discussion has been closed.