Assigning Row_Ids to dynamically added rows in Datatables

95 Views Asked by At

I am working on making an editable Datatable using Jeditable. I need to be able to dynamically add rows, which I have successfully done. By default, it appears that Datatables will add everything with a row_id of 0, which makes it impossible to differentiate added rows from each other.

So I am working on a function that assigns the row_id. There are no errors, but it also does not seem to work as it still returns a row_id of 0 for all added rows.

$('#addRow').on( 'click', function () {
        var rowIndex = $('#example').dataTable().fnAddData([ "column1Data", "column2Data"]);
        var row = $('#example').dataTable().fnGetNodes(rowIndex);
    $(row).attr('id', row_id_counter);
    row_id_counter ++;

Entire code:

http://jsfiddle.net/j2frzerj/

1

There are 1 best solutions below

1
Woodrow On

I tested your code in the fiddle provided, and it is adding new table rows with sequential id's, starting with index 0. I am not seeing any duplicate id's of 0?

http://prntscr.com/ew3tg9

http://prntscr.com/ew3tlr