How to reinitialize dataTable???
How to reinitialize dataTable???
kavittp
Posts: 12Questions: 0Answers: 0
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]
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]
This discussion has been closed.
Replies
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..
Also for urgent help, DataTables priority support is available: http://datatables.net/support .
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..
Why are you trying to initialise it again after calling fnDraw?
Allan
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
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..
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
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..