2

I am using jQuery dataTables version 1.9.2

Table is created with class datatable and displayed properly but now I want to use fnPageChange hence I need object of the table.

$(document).ready(function(){
        var oTbl = $(".datatable").dataTable();
    });

This code gives alert that says -

DataTables warning (table id = 'tblCat'): Cannot reinitialise DataTable.    
To retrieve the DataTables object for this table, pass no arguments or
see the docs for bRetrieve and bDestroy.

I read that Version 1.7 fixed this issue regarding popup here.

How can I get the existing object of the table to work with ?

2 Answers 2

4

What I have done is- while initializing the datatable 'bRetrieve':true was added to the code.

And the I was able to get the object of the existing table and further I am able to navigate through the page using fnPageChange.

This worked for me at least for now, lets c if this generates any new problems in future...:)

Following code worked.

    $(document).ready(function($){
  // column count starts with 0
  var oTbl = $('.datatable').dataTable(
   {"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
   "sPaginationType": "bootstrap",
   "bFilter": false,
   "bInfo" : false,
   // list of columns those will be unsortable
   "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 6 ] }],
   "bRetrieve":true,
   "oLanguage": {"sLengthMenu": "_MENU_ records per page"}} );
   // default sorting on this column
   oTbl.fnSort( [ [5,'desc'] ]);
  });
Sign up to request clarification or add additional context in comments.

1 Comment

It sounds like you solved the problem. Please post your code to "get the object of the existing table".
1
$(document).ready(function(){
          $content.find("table.datatable").dataTable({
        "sPaginationType": "full_numbers",
        "bRetrieve":true,
        "bDestroy": true
    });
};

5 Comments

It would be better if you could add an explanation of what this code is doing.
@BilltheLizard I came across this answer in the Review Queue, and sorry to be off-topic. But do you 'Recommend Deletion' here, or do you leave a comment like yours and say "Looks Good"?
@Gray I don't recommend deletion for this type of answer because the code might be useful by itself. The answer would be greatly improved if it had an explanation, but half an answer is better than no answer. I just leave a comment and click "Looks Good."
line 1:- Find the data table plugin initialization. add Line 2,3 and 4 to get rid of warning message when customized the grid. for example: $(function() {var table= $('#id').data table({"a a Sorting":[[0,"desc"]]}}););
This is incorrect: if bRetrieve is set, bDestroy is ignored. Pick the one you want and remove the other one, because including both does nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.