possible bug in latest version of datatables js download when retrieving data from selected row

possible bug in latest version of datatables js download when retrieving data from selected row

joannazjoannaz Posts: 12Questions: 2Answers: 0

I have some code that worked until I updated the datatables javascript library to the latest version (to try and fix a different issue) and now it doesn't.

The code just returns the row id of a main table when selected. In the current version of the library, this code returns 'undefined' until the row is deselected or another row selected (i.e. always one click behind).

I reverted to the old library and the problem went away.

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/dt-1.10.11,cr-1.3.1,fc-3.2.1,fh-3.1.1,r-2.0.2,sc-1.4.1,se-1.1.2/datatables.min.css"/>

My code:

function GetTableRowID() {
var table = $('#tblDSResults').DataTable();
var id = table.cell(table.row('.selected'), 4).data();
return id;
};

$('#tblDSResults').on('click', 'tr', function () {
var id = GetTableRowID();
console.log(id);
};

As I don't know if the current version would fix my other problem or not with the destroy function, I don't know how much of a problem this is.

Answers

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

    Can you give me a link to the broken page so I can debug what is going wrong please?

    Thanks,
    Allan

  • kthorngrenkthorngren Posts: 21,351Questions: 26Answers: 4,955

    Looks like you are using the select extension. Wonder if it some sort of timing issue with the selected class being added to the row and your GetTableRowID() executing. You might be better of using the Select select event to get the row ID. Also you won't need to worry about getting undefined if no rows are selected.

    Kevin

This discussion has been closed.