record count with server side processing
record count with server side processing
Hi,
I'm trying to get a record count with server side processing. It works fine client side.
I'm updating a span element with the count.
My code, which works fine with client side processing is below:
[code]
"fnDrawCallback": function() {
var oSettings = this.fnSettings();
var iTotalRecords = oSettings.fnRecordsTotal();
$("#rightsearchcount").html(iTotalRecords);
},
[/code]
Any advice please?
I'm trying to get a record count with server side processing. It works fine client side.
I'm updating a span element with the count.
My code, which works fine with client side processing is below:
[code]
"fnDrawCallback": function() {
var oSettings = this.fnSettings();
var iTotalRecords = oSettings.fnRecordsTotal();
$("#rightsearchcount").html(iTotalRecords);
},
[/code]
Any advice please?
This discussion has been closed.
Replies
You could do it in one line if you wanted it to be smaller:
[code]
$("#rightsearchcount").html( this.fnSettings().fnRecordsTotal() );
[/code]
Allan
oSettings.fnRecordsTotal() is undefined on a drawcallback in this scenario.
[code]
searchTable = $('#searchtable').dataTable({
"oLanguage":
{
"sSearch": "Query",
"sProcessing": ""
},
"bJQueryUI": true,
"aoColumns": [
{ "bVisible": false } ,
null,
{ "sClass": "contact" },
{ "sClass": "main" },
null,
null
],
"asStripClasses": [ 'strip1', 'strip2' ],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "json_search2.asp",
"fnDrawCallback": function() {
var oSettings = this.fnSettings();
var iTotalRecords = oSettings.fnRecordsTotal();
$("#rightsearchcount").html(iTotalRecords);
},
"fnRowCallback": function( nRow, aData, iDisplayIndex )
{
var uid = aData[0];
$(nRow).addClass('UID'+uid);
$(nRow).bind("click", function(e)
{
loadcontact(uid);
});
return nRow;
}
}).fnSetFilteringDelay(500);
[/code]
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php",
"fnDrawCallback": function () {
console.log( this.fnSettings().fnRecordsTotal() );
}
} );
} );
[/code]
Does your returned JSON correctly include "iRecordsTotal"? If you filter the table, what does the "info" string say - it also gets it's value from fnRecordsTotal.
Allan
Thanks for your assistance. There was a type in my json. Working now.
[code]
"bServerSide": true,
"fnDrawCallback": function ( oSettings ) {
var record_count = this.fnSettings().fnRecordsTotal();
//console.log(record_count);
if(record_count==0) { //no records to show
$('.filter_refresh').val('0'); //resets all filters
//oTable.fnDraw(); //redraws table but I can't exit loop... Browser freezes
}
},
"sAjaxSource": "ajax_source.php",
"sServerMethod": "POST",
[/code]
Thanks for great DataTables script ;)
I'm using latest version.
Allan
[code]var draw = true; //before var oTable = ...
if(draw==true) { //in fnDrawCall back
oTable.fnDraw();
draw = false;
}[/code]
Allan