Not removing pagination div

Not removing pagination div

xtremer360xtremer360 Posts: 84Questions: 2Answers: 0
edited July 2011 in General
I'm trying to figure out how to have it remove the pagination div when there is no data returned into the table and the code I have is not working.

[code]
var oTable = $('#templatesPageList').dataTable( {
"sDom": 'rti<"pagination"p>',
"iDisplayLength": 10,
"sPaginationType": "full_numbers",
"fnDrawCallback":function(){
if(oTable.find("tbody tr").length == 0){
$('div.pagination').remove();
}
}
[/code]

Replies

  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited July 2011
    I'm not at a machine for testing unfortunately, but I suspect that it's just the comparator. Fire up your console of choice (Firebug, F12, Web Developer tools or whatever) and see if that "tbody tr" is in fact zero rather than 'null' or 'undefined'.

    This also assumes that there's a div called 'pagination'.
  • xtremer360xtremer360 Posts: 84Questions: 2Answers: 0
    Or better yet have it remove the pagination div when there are 10 rows or less.
  • xtremer360xtremer360 Posts: 84Questions: 2Answers: 0
    I came up with this but somethign isn't right here.

    [code]
    var oTable = $('#templatesPageList').dataTable( {
    "sDom": 'rti<"pagination"p>',
    "iDisplayLength": 10,
    "sPaginationType": "full_numbers",
    "fnDrawCallback":function(){
    if($('#templatesPageList tbody tr').length <= 10 || ($('#templatesPageList tbody td.dataTables_empty').length > 0)) {
    $('div.pagination').remove();
    }
    if($('#templatesPageList tbody td.dataTables_empty').length == 0) {
    $('div.pagination').remove();
    }

    });
    [/code]
  • GregPGregP Posts: 500Questions: 10Answers: 0
    Any clues in the console? Is there a live version we can peek at?
  • xtremer360xtremer360 Posts: 84Questions: 2Answers: 0
    I'll PM you.
  • xtremer360xtremer360 Posts: 84Questions: 2Answers: 0
    I went back through and found an older post by someone but I think this may have me confused because this isn't working for me.

    [code]
    var oTable = $('#templatesPageList').dataTable( {
    "sDom": 'rti<"pagination"p>',
    "iDisplayLength": 10,
    "sPaginationType": "full_numbers",
    "fnDrawCallback":function(){
    if(oTable.fnSettings().fnRecordsTotal() <= 10) {
    $('div.pagination').remove();
    } else {
    $('div.pagination').append();
    }
    if(oTable.fnSettings().fnRecordsTotal() == 0) {
    $('.bt_red').remove();
    $('.bt_blue').remove();
    }
    }

    });
    [/code]
  • GregPGregP Posts: 500Questions: 10Answers: 0
    Hi xtremer; you mentioned in PM that you had solved one of your recent questions. Is this the one? Just wanted to check and also see if you could share what the solution was in that case.
This discussion has been closed.