fnDraw not working
fnDraw not working
lvaughan
Posts: 3Questions: 0Answers: 0
I have recently started using datatables and it is working perfectly. The main problem that I experienced was that I was trying to implement a custom filter when a button is clicked to redraw a table to hide certain rows or show them again. However when the button is clicked the fnDraw function does nothing. I know the click event is firing because alerts before or after the draw work. I am using server side processing but no call is made to the server. While testing other options I also found that fnClearTable also does nothing, but fnDestroy will work.
Help would be greatly appreciated.
[code]
// DEFINE the datatable and set all options
var oTable = $('#compList').dataTable( {
"bProcessing": true, // shows the "Processing Box" when the table data is changing
"bServerSide": true, // Initializes the server side data option
"bNeedServer": true,
"sAjaxSource": "ajax/contactList_call.php", // the location of the server side data call
"fnServerData": fnDataTablesPipeline, // sets the table to pipeline data in advance
"sScrollX": "100%", // sets the window to scroll when the width exceeds 100%
"bScrollCollapse": true, // forces the data that is beyond 100% to collapse until scrolled to.
"sDom": 'Rlrtip', // sets the tables dom for Left Changing, Filtering, processing, on the table information with pagination
"bAutoWidth": false, // turns off autowidth (this caused issues with the hiding of the columns when left on)
"aaSorting": [[ 1, "asc"]], // set the default sort order using the company name column
"aoColumns": [ // defines all the columns manually (used primarily to hide columns on load
{ "sName" : "Id", "sType": 'numeric', "bVisible": false},
{ "sName" : "Name" },
{ "sName" : "Company Name" },
{ "sName" : "Phone"},
{ "sName" : "eMail" ,
"fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
if(sReturn != null){
return ""+sReturn+"";
} else {
return sReturn;
}
}
},
{ "sName" : "Address1", "bVisible": false},
{ "sName" : "Address2", "bVisible": false},
{ "sName" : "Address3", "bVisible": false},
{ "sName" : "City", "bVisible": false},
{ "sName" : "State", "bVisible": false},
{ "sName" : "Zip", "bVisible": false},
{ "sName" : "Country", "bVisible": false},
{ "sName" : "Record Manager", "bSearchable": false },
{ "sName" : "Category", "bVisible": false},
{ "sName" : "Job Title", "bVisible": false},
{ "sName" : "Create Date", "bVisible": false},
{ "sName" : "Record Creator", "bSearchable": false, "bVisible": false},
{ "sName" : "Edit Date", "bVisible": false},
{ "sName" : "Edit By", "bSearchable": false, "bVisible": false},
{ "sName" : "Active", "bSearchable": false, "bVisible": false, "bSortable": false},
{ "sName" : "Deleted", "bSearchable": false, "bVisible": false, "bSortable": false},
{ "sName" : "edit", "bSearchable": false, "bSortable": false }
],
"fnCreatedRow": function(nRow, aData ) {
if(aData[19] == 0){
$(nRow).addClass('deactive');
}
if(aData[20] == 1){
$(nRow).addClass('deleted');
}
}
} );
[/code]
Here is the click for the button. I have tried with and without the oTable declaration, but it makes no difference
[code]
$('#hideInactive').click(function(){
// oTable.fnDraw();
// $('#compList').dataTable().fnDraw();
$('#compList').dataTable().fnClearTable(0);
});
[/code]
There are no errors in firefox console, and the table loads initially just fine, I am using pipelining and pagination and that will reload new data correctly every 5 pages as per my settings, its just manual calls to fnDraw.
Datatables debugger: olavon
Help would be greatly appreciated.
[code]
// DEFINE the datatable and set all options
var oTable = $('#compList').dataTable( {
"bProcessing": true, // shows the "Processing Box" when the table data is changing
"bServerSide": true, // Initializes the server side data option
"bNeedServer": true,
"sAjaxSource": "ajax/contactList_call.php", // the location of the server side data call
"fnServerData": fnDataTablesPipeline, // sets the table to pipeline data in advance
"sScrollX": "100%", // sets the window to scroll when the width exceeds 100%
"bScrollCollapse": true, // forces the data that is beyond 100% to collapse until scrolled to.
"sDom": 'Rlrtip', // sets the tables dom for Left Changing, Filtering, processing, on the table information with pagination
"bAutoWidth": false, // turns off autowidth (this caused issues with the hiding of the columns when left on)
"aaSorting": [[ 1, "asc"]], // set the default sort order using the company name column
"aoColumns": [ // defines all the columns manually (used primarily to hide columns on load
{ "sName" : "Id", "sType": 'numeric', "bVisible": false},
{ "sName" : "Name" },
{ "sName" : "Company Name" },
{ "sName" : "Phone"},
{ "sName" : "eMail" ,
"fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
if(sReturn != null){
return ""+sReturn+"";
} else {
return sReturn;
}
}
},
{ "sName" : "Address1", "bVisible": false},
{ "sName" : "Address2", "bVisible": false},
{ "sName" : "Address3", "bVisible": false},
{ "sName" : "City", "bVisible": false},
{ "sName" : "State", "bVisible": false},
{ "sName" : "Zip", "bVisible": false},
{ "sName" : "Country", "bVisible": false},
{ "sName" : "Record Manager", "bSearchable": false },
{ "sName" : "Category", "bVisible": false},
{ "sName" : "Job Title", "bVisible": false},
{ "sName" : "Create Date", "bVisible": false},
{ "sName" : "Record Creator", "bSearchable": false, "bVisible": false},
{ "sName" : "Edit Date", "bVisible": false},
{ "sName" : "Edit By", "bSearchable": false, "bVisible": false},
{ "sName" : "Active", "bSearchable": false, "bVisible": false, "bSortable": false},
{ "sName" : "Deleted", "bSearchable": false, "bVisible": false, "bSortable": false},
{ "sName" : "edit", "bSearchable": false, "bSortable": false }
],
"fnCreatedRow": function(nRow, aData ) {
if(aData[19] == 0){
$(nRow).addClass('deactive');
}
if(aData[20] == 1){
$(nRow).addClass('deleted');
}
}
} );
[/code]
Here is the click for the button. I have tried with and without the oTable declaration, but it makes no difference
[code]
$('#hideInactive').click(function(){
// oTable.fnDraw();
// $('#compList').dataTable().fnDraw();
$('#compList').dataTable().fnClearTable(0);
});
[/code]
There are no errors in firefox console, and the table loads initially just fine, I am using pipelining and pagination and that will reload new data correctly every 5 pages as per my settings, its just manual calls to fnDraw.
Datatables debugger: olavon
This discussion has been closed.
Replies
In order to filter the row results, I had to modify the pipeline submit, and then add a conditional if clause in my server side processing.
In the fnDataTablesPipeline, (near the top)
[code]
if($("#hideInactive").attr('checked') == "checked"){
aoData.push({'name':'showInactive','value':'1'});
} else {
aoData.push({'name':'showInactive','value':'0'});
}
[/code]
Then, in my php file that the filter calls to:
[code]
if($_GET['showInactive'] == 1){
$sql_where = "WHERE C.active = '1'";
} else {
$sql_where = "WHERE (C.active = '1' || C.active = '0')";
}
[/code]