Why fnGetData() is returning the last row added to the table?

Why fnGetData() is returning the last row added to the table?

srivpuneet01srivpuneet01 Posts: 1Questions: 1Answers: 0

Hi all,

Forgive me if I am going absurd here, I need help as I found none on google.

I have a dataTable in which I am trying to add and update the rows through js directly. When I added more than one new rows, I found that dataTable was adding the same row_id to every new created row. Some how I managed to create unique ids for the rows (did in fnRowCallback).

    "fnRowCallback": function (nRow, aData) {
        if (!$(nRow).attr("id"))
            $(nRow).attr("id", aData.DT_RowId);
    }

Every row in my dataTable has an edit icon, clicking on which I have to populate the data associated with the underlying row into the text boxes available in a form. Please have a look at the following script;

$('#banks-local').dataTable( ........ ).on('click', '.edit', function () {
reset();
selectedRow = $(this).parents('tr');
var t = localTable.fnGetData(selectedRow[0]);
selectedId = t.DT_RowId;
selectedBank = t;
$('#bankId').val(selectedBank.S_Bank_Master_GUID);
$('#name').val(selectedBank.Bank_Name);
$('#description').val(selectedBank.Bank_Description);
$('#comments').val(selectedBank.Comments);
});

NOTE: '.edit' is the class for edit icon.

What problem I'm facing is that, although I am getting correct "selectedRow[0]", I am getting the data associated with the last inserted row only (not the one I am clicking on).
It has blown me up completely.. Does anyone has any idea what I'm doing wrong here?
Thanks, in advance for your help....

This discussion has been closed.