How to prevent asSorting is null error when no data is present

How to prevent asSorting is null error when no data is present

KevKev Posts: 2Questions: 0Answers: 0
edited September 2012 in General
I am dynamically creating the datatable with information. But there are times when there is no data present so only the table tags are returned.
Example:


Based on info from previous discussions I can set some variables with the following check.

if ($('#tableinfo thread th').length < 1) {
//set variables in datatable

}

Is there a way I can set the datatable so it sees it as zero records (I can use setting already in datatable).

Here is my code for my dataTable (version 174):

$(document).ready(function(){


oTable = $('#tableinfo').dataTable({
"bJQueryUI": false,
"sPaginationType": "full_numbers",
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bInfo": true,
"bAutoWidth": false,
"bStateSave": true,
"bSort": true,

"oLanguage": {
"sSearch": "Filter all records:",
"sZeroRecords": "ZERO records to display",
"sProcessing": "Getting data..."
},


"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["nosort"] }
]

})

})


Any help would be appreciated.

Kev

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    It isn't currently possible to have zero TH (or TD) elements in the header - that must be columns defined in the initialisation since dynamic addition and deletion of columns is not a feature yet available in DataTables.

    If you have cells in the header and are still getting this error, then please link us to an example showing the problem so we can see what is happening.

    Allan
  • KevKev Posts: 2Questions: 0Answers: 0
    Allan,

    Thanks - Not doing a true dynamic. I am changing based on selections from a drop down. I guess my best bet is to check to see if the thead exists and if it does not - don't initialize the datatable. I did see something about using "aoData":[{}]; but that messed up sorting on all but the first column.
    BTW - like your product and left a contribution yesterday.

    V/R,

    Kev
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Hi Kev,

    Thanks very much for the donation - hugely appreciated!

    I think that check you suggest sounds like a good way to go. I do plan on making columns dynamic in future, so this will be supported in later DataTables versions (not yet sure if it will make it into 1.10).

    Allan
This discussion has been closed.