How to implement sorting of columns with checkboxes with a datatable the has an add row feature

How to implement sorting of columns with checkboxes with a datatable the has an add row feature

mkadusalemkadusale Posts: 10Questions: 0Answers: 0
edited March 2012 in General
Good Day!

I have implemented the sorting using this code
http://datatables.net/examples/plug-ins/dom_sort.html

But when I add a row an error will occur.
The scenario is that there are 2 rows currently in the table when I load the page everything is fine but when I add a new row
I get this error message
DataTables warning (table id = 'tble_China'): Requested unknown parameter '0' from the data source for row 2
This error message will occur if the current column being used for sorting has a checkbox in it.

And if the current used column for sorting is not using checkbox the add new row feature works fine.

Any inputs on what is the best approach to solve this error?

Thanks in advance

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Hi,

    Can you give us a link to the table please or at least run it through the debugger and give us a link to the debug code (after the error has occurred): http://debug.datatables.net .

    Allan
  • mkadusalemkadusale Posts: 10Questions: 0Answers: 0
    This is the code the part of the code http://pastie.org/3494940
    By the way I do not know if this is related but the error occurs maybe because the new row is not yet present.
  • mkadusalemkadusale Posts: 10Questions: 0Answers: 0
    edited March 2012
    Found out that the problem is when the sorted column has a checkbox when you add a new row dynamically and your using this solution to sort your table http://datatables.net/release-datatables/examples/plug-ins/dom_sort.html
    $.fn.dataTableExt.afnSortData will return lacking 1 row, the newly created row which is not yet created will not be included yet. So thats where the error starts.
    What I did was a little hack I recorded when the users clicks the add row button then when $.fn.dataTableExt.afnSortData is invoked I will check a variable to know if the add row button was clicked, if yes then I will add the initial value of that column so that there will be no missing row returned by $.fn.dataTableExt.afnSortData
This discussion has been closed.