4

I have a table in which data is coming from a database. I am using data tables on that table. But the problem is when there is no row in the database, it displays alert

DataTables warning (table id = 'table-filter'): Requested unknown parameter '0' from the data source for row 0

My jQuery code for table is:

$('#table-filter').dataTable({
    "bPaginate": true,
    "bProcessing": false,
    "bStateSave": false,
    "aLengthMenu": [[5, 10, 20, 50, 100 , -1], [5, 10, 20, 50, 100, "All"]],
    "iDisplayLength" : 5,
    "sPaginationType": "full_numbers",
    "aoColumnDefs": [
        { 'bSortable': false, 'aTargets': [ 0,7 ] }
    ],
    "oLanguage": {
        "sLengthMenu": "Show _MENU_ records per page",
        "sZeroRecords": "Nothing found - sorry",
        "sInfo": "Showing _START_ to _END_ of _TOTAL_ Entries",
        "sInfoEmpty": "Showing 0 to 0 of 0 records",
        "sInfoFiltered": "(filtered from _MAX_ total records)"
    }
}).columnFilter({
    aoColumns:[ null,
         { type: "text" },
         { type: "text" },
         { type: "text" }, { type: "text" },
         { type: "text" },
         { type: "text" }
    ],
});

What can I do for this?

4

1 回答 1

1

You need to include "aaData" inside your initialization, such as:

$('#table-filter').dataTable({
  ...
  "aaData": [2,3,5,7],
  ...
}

Alternately, you can avoid making the table if it doesn't exist (per Saranya Sadhasivam suggestion).

Could use something like:

 if ( $('#table-filter tr').length > 0 ) { ... }

Or if the database just takes time to load, add callback that start initialization after the data has arrived.

My experience with dataTables is that is don't like being initialized without at least one full and complete row. Once that is created, it can be sorted/filtered/etc to zero items and works fine, but it has to Start with something.

于 2013-09-25T22:38:37.197 回答