Ignoring empty rows in the table

Ignoring empty rows in the table

NikolaKGNikolaKG Posts: 2Questions: 0Answers: 0
edited April 2011 in General
Hi everybody,

I wasn't able to find the answer for my problem. What I'm trying to do is to have empty rows in the table which would be completely ignored, like they don't exist, that means they are not included in sorting, nor included in the row count. They just exist in there so the table would have minimum 20 rows... Any quick solution?

Replies

  • NikolaKGNikolaKG Posts: 2Questions: 0Answers: 0
    ok, I got some help... The idea is to initialize the dataTables like this
    [code]
    $(document).ready(function(){
    $('#contact').dataTable({
    sPaginationType: 'full_numbers',
    iDisplayLength: 25,
    aLengthMenu: [[25, 50, -1], [25, 50, "All"]],
    sScrollY: "320px",
    fnDrawCallback: function() { handleEmptyRows('contact', 240) }
    });

    $(window).resize(function(){
    handleEmptyRows('contact', 240);
    });
    });
    [/code]

    And here's the function handleEmptyRows:
    [code]
    function handleEmptyRows (table_name, height_offset){


    var empty_row_class = 'dataTables_empty_row';

    $('#' + table_name + ' tr.' + empty_row_class).remove();

    var row_count = $('#' + table_name + ' tr').length;

    var window_height = $(window).height();
    var available_height = window_height - height_offset;

    var table_wrapper = $('#' + table_name + '_wrapper');
    var header_table = table_wrapper.children('div.dataTables_scrollHead table:first');

    var row_height = header_table.children('thead tr:first').height();
    if (!row_height) row_height = 24;

    var max_rows = available_height / row_height;

    var column_count = $('#' + table_name + ' > thead > tr > th').length;

    var empty_cells = '';

    for (i = 1; i <= column_count; i ++){
    empty_cells += ' ';
    }

    console.log(max_rows);
    console.log(available_height);

    for (i = row_count + 1; i <= max_rows; i ++){
    empty_row = '' + empty_cells + '';
    $('#' + table_name).append(empty_row);
    }

    $('#' + table_name).closest('.dataTables_scrollBody').css('height', (available_height - 50) + 'px');

    }

    [/code]
This discussion has been closed.