Reputation: 1929
I have one question. What I"m attempting to do is if there are no returned results for the table then do NOT display the pagination. What I have no does not work.
var oTable = $('#templatesPageList').dataTable( {
"sDom": 'rti<"pagination"p>',
"iDisplayLength": 10,
"sPaginationType": "full_numbers",
"fnDrawCallback":function(){
if(oTable).find("tbody tr").length(0){
$(oTable 'div.dataTables_paginate')[0].style.display = "none";
} else {
$(oTable 'div.dataTables_paginate')[0].style.display = "block";
}
}
Upvotes: 1
Views: 937
Reputation: 12226
Nicola's code did not work for me because table always contain rows (at least header). What did the trick was:
"fnDrawCallback": function (o) {
if (o.aiDisplay.length > 0) {
$("#templatesPageList_paginate").show();
} else {
$("#templatesPageList_paginate").hide();
}
Upvotes: 0
Reputation: 76870
You should do:
"fnDrawCallback":function(){
if((oTable).find("tr").length > 0)){
$(oTable).find('div.dataTables_paginate').show();
} else {
$(oTable).find('div.dataTables_paginate').hide();
}
Upvotes: 0
Reputation: 81988
This strikes me as a bit strange: if(oTable).find("tbody tr").length(0){
It will certainly cause errors in JS. Do you mean if(oTable.find("tbody tr").length == 0){
?
Also: $(oTable 'div.dataTables_paginate')
won't work. You need to concatenate if you're only passing one argument, or better still, use the original selector: $('#templatesPageList div.dataTables_paginate')
Upvotes: 3