Getting DataTables warning: Requested unknown parameter '12' for row 0 sometimes

Getting DataTables warning: Requested unknown parameter '12' for row 0 sometimes

rannrann Posts: 3Questions: 1Answers: 0
edited July 2018 in Free community support

Depending on what the user selects, the table generated will have different number of columns. If I load a 14 column table then try to load a 12 column table, I get "DataTables warning: Requested unknown parameter '12' for row 0." But when I start from the 12 column table, then load the 14 column table, I do not get such a warning. I do not know what I am doing wrong. Everything is inserted fine, and when I go to the next page with pagination, the error doesn't appear. I also do not understand where the '12' is coming from, since I have 12 columns, and I think the warnings do zero-based warnings.

I'm doing server-side processing, and I am adding columns in with a loop, creating DOM elements (I do fnDestroy(), then fnClearTable(), then finally add in my DOM header elements in a loop). I checked the length of the columns, and they always match the length of the inserted rows as expected. Please help me find the part I am missing.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    First thing to remember is that DataTables column counting is 0 index based - so really the error is about a 13th column. Likely the number of cells in the tbody do not match the thead, or you are using columns / columnDefs and it doesn't match the HTML.

    If you give a link to a page showing the issue I can take a look.

    Allan

  • rannrann Posts: 3Questions: 1Answers: 0

    Hi, I recreated the issue here.

    http://jsfiddle.net/o6znk7qw/35/

    It appears if I submit the 14 column, then submit the 12 column, but not submitting the 12 column then the 14 column.

    Thank you!

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Try this: http://jsfiddle.net/o6znk7qw/51/

    You had multiple DataTable intialisations which was always going to get really confusing :).

    I removed the one from displaytable since you only want to initialise any one specific table in one location. I've also used $.fn.dataTable.isDataTable() to check it a table is a DataTable before destroying it and emptying out the old tbody:

        if ( $.fn.dataTable.isDataTable('#result-table') ) {
                $('#result-table').DataTable().destroy();
                $('#result-table tbody').empty();
              }
    

    Allan

  • rannrann Posts: 3Questions: 1Answers: 0

    Perfect!!! Thank you so much, I really appreciate this great tool and support you all give!

This discussion has been closed.