How to reinitialize dataTable???

How to reinitialize dataTable???

kavittpkavittp Posts: 12Questions: 0Answers: 0
edited July 2013 in DataTables 1.9
Dear Allan,
I am having a problem with jquery dataTable plugin. I am using two text box and a button and onclick event of that button i am calling my dataTable.
After Page load..FIRST time when i clicked on button , dataTables working fine and populates records and performs all its functionality..
but when i change some values in text box and again click on button SECOND time to populate dataTables with new records...Its give me error like "Cannot reinitialize dataTables"...Then to resolve these error i used "fnClearTable" and "fnDestroy" function of dataTables (as i used it in my following code)...But still i am not able to reinitialize dataTable and GETTING OLD VALUES NOT FRESH ONE...

Below is my javascript code to call dataTables and trying to reinitialize it.... please help me to solve these problem...i am waiting for ur reply..
thanks in advance..


[code]



$('#id_prepack').click(function() {


//alert("clicked");
var button_id=$(this).attr('id');
alert(button_id);

var str_mtr_from=document.getElementById("id_mtr_from").value;
var str_mtr_to=document.getElementById("id_mtr_to").value;

var str_cca_from=document.getElementById("id_cca_from").value;
var str_cca_to=document.getElementById("id_cca_to").value;

if((str_mtr_from!="" && str_mtr_to!="") || (str_cca_from!="" && str_cca_to!=""))
{

var settings={
"bDestroy":true,
"bRetrieve": false,
"bJQueryUI": true,
"bServerSide": true,
"bAutoWidth": true,
"sAjaxSource": "/web_trial_one/SourceMeter?button_name="+button_id+"&txt_mtr_from="+str_mtr_from+"&txt_mtr_to="+str_mtr_to,
"bProcessing": true,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"aButtons": [ "copy","csv","xls","pdf",
{
"sExtends": "download",
"sButtonText": "Download Excel",
"sUrl": "/web_trial_one/prepack_download"
}

],
"sSwfPath": "./table_tool2.0/media/swf/copy_cvs_xls_pdf.swf"
}

};


if(typeof oTable=='undefined')
{
oTable = $("#prepack").dataTable(settings);

}
else
{

oTable.fnClearTable();
oTable.fnDestroy();
oTable=$("#prepack").dataTable();
oTable=$("#prepack").dataTable(settings);

}


}
else
{
alert("To Proceed..Please Enter any Search Dimension Field");
}

});



[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You've got server-sid processing enabled. Why not just call fnDraw rather than trying to reinitialise the table? That will get the latest data from the server.

    Allan
  • kavittpkavittp Posts: 12Questions: 0Answers: 0
    Dear Allan..,
    As you suggested...

    I also tried with "fnDraw" function just like following way:


    [code]

    if((str_mtr_from!="" && str_mtr_to!="") || (str_cca_from!="" && str_cca_to!=""))
    {

    var settings={
    "bDestroy":true,
    "bRetrieve": false,
    "bJQueryUI": true,
    "bServerSide": true,
    "bAutoWidth": true,
    "sAjaxSource": "/web_trial_one/SourceMeter?button_name="+button_id+"&txt_mtr_from="+str_mtr_from+"&txt_mtr_to="+str_mtr_to,
    "bProcessing": true,
    "sPaginationType": "full_numbers",
    "sDom": 'T<"clear">lfrtip',
    "oTableTools": {
    "aButtons": [ "copy","csv","xls","pdf",
    {
    "sExtends": "download",
    "sButtonText": "Download Excel",
    "sUrl": "/web_trial_one/prepack_download"
    }

    ],
    "sSwfPath": "./table_tool2.0/media/swf/copy_cvs_xls_pdf.swf"
    }

    };


    if(typeof oTable=='undefined')
    {
    oTable = $("#prepack").dataTable(settings);

    }
    else
    {

    oTable.fnDraw(); // oTable.fnDraw(settings); i tried in this way also...

    }


    }
    else


    [/code]


    ..but still my dataTable is not reinitializing...means still i am getting the old data not the updated data..

    please guide me how to implement it and how to get new updated records through dataTables...

    Actually i am facing these problem from couple of days and now its very urgent for me to implement it in my application... So I am waiting for ur reply... please..thanks in advance..
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Look like it should work to me. Please link to a test case showing the issue: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read .

    Also for urgent help, DataTables priority support is available: http://datatables.net/support .

    Allan
  • kavittpkavittp Posts: 12Questions: 0Answers: 0
    Dear Allan..,

    As you told me.. i already put my javascript and HTML code on following link :

    http://live.datatables.net/idinat/46/edit

    Please just go through it...may be its helpful for you to sort out my problem...

    As i mentioned earlier.. I already use "fnDraw()" function as shown in above link..

    please allan... help me so that i come out from the problem..
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > oTable = $("#prepack").dataTable(Settings);

    Why are you trying to initialise it again after calling fnDraw?

    Allan
  • prinsssprinsss Posts: 1Questions: 0Answers: 0
    .fnFilter option filters the data as searched. But for the second time it searches the queried string in the output of first query, needed to be fired on all the rows, how this could be done? .
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    @prinsss - How does this release to the discussion in this thread? PLease start a new thread for new questions.

    Allan
  • kavittpkavittp Posts: 12Questions: 0Answers: 0
    Dear Allan..,
    Yes..you are right..there is no need to initialize it again after "fnDraw"....
    Actually i was just applying hit and try process ..so i put that code there to check the result....and now already remove it from there... please see the following code..

    [code]

    var oTable;

    $(document).ready(function () {

    $('#id_prepack').click(function() {


    //alert("clicked");
    var button_id=$(this).attr('id');
    alert(button_id);

    var str_mtr_from=document.getElementById("id_mtr_from").value;
    var str_mtr_to=document.getElementById("id_mtr_to").value;



    if(str_mtr_from!="" && str_mtr_to!="")
    {

    else
    {
    var Settings={
    "bDestroy":true,
    "bRetrieve": false,
    "bJQueryUI": true,
    "bServerSide": true,
    "bAutoWidth": true,
    "sAjaxSource": "/web_trial_one/SourceMeter?button_name="+button_id+"&txt_mtr_from="+str_mtr_from+"&txt_mtr_to="+str_mtr_to,
    "bProcessing": true,
    "sPaginationType": "full_numbers",
    "sDom": 'T<"clear">lfrtip', //'<"H"Tfr>t<"F"ip>' to print tabletool in UI theme within border.
    "oTableTools": {
    "aButtons": [ "copy","csv","xls","pdf",
    {
    "sExtends": "download",
    "sButtonText": "Download Excel",
    "sUrl": "/web_trial_one/prepack_download"
    }

    ],
    "sSwfPath": "./table_tool2.0/media/swf/copy_cvs_xls_pdf.swf"
    }


    };


    if(typeof oTable=='undefined')
    {

    oTable = $("#prepack").dataTable(Settings);

    }
    else
    {
    alert("test");

    //oTable.fnClearTable();
    //oTable.fnDestroy();

    oTable.fnDraw(Settings); // oTable.fnDraw() i also used these..

    }



    }
    }
    else
    {
    alert("To Proceed..Please Enter any Search Dimension Field");
    }

    });

    });


    [/code]


    but the main point is still i am not able to reinitialize th dataTables and when click on button at SECOND TIME...still getting old value..not the updated records...

    I already applied "fnDestroy", "fnClearTable" and fnDraw" functions...but not getting the proper output...please guide me .. i am waiting for your apply .. thanks in advance
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Just call `oTable.fnDraw();` . If that doesn't work, then please link me to a page which shows the error live. I'd need to see the code actually running, not just the code.

    Allan
  • kavittpkavittp Posts: 12Questions: 0Answers: 0
    Dear Allan..,
    Again i tried "oTable.fnDraw();"
    and it doesn't work...one thing i would like to ask that... you want to see the code actually running,not just code.
    But how it is possible...?? means if i send my code..you will not be able to see the populated records from database...

    one thing i can do that i send you some dummy data in excel and you just made Database Connection by your own and then use that with my code....

    but my question is ...where i should send code and data to you...i think it may be risky to put on this Forum..

    so please help me or guide me...how can i send you the actual running code....so that you sort out my problem..
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You can PM me a link my clicking on my name above and selecting the "Send message" option. That way it will only be myself that sees it and I'll not send it to anyone else.

    As I say, the code above, in principle, looks like it should work to me, so I'm not sure what is going wrong.

    Allan
  • kavittpkavittp Posts: 12Questions: 0Answers: 0
    Dear Allan..,
    is it possible to send a zip folder as attachment... actually i thought to send whole code in a zip folder to you.... so u can run it properly...
    i am waiting for ur reply..
This discussion has been closed.