Getting selected row ID in javascript
Getting selected row ID in javascript
The scenario we have is a table with a comments field. Since comments can be very long the table displays a summary (stripped of HTML tags and limited to 80 characters - this is done at the server). The table uses an ajax call to display the full comments when a button is selected.
When editing the form I need to display the full comments rather than the summary so I've defined a preOpen event:
editor.on('preOpen', function (e) {
var that = this;
$.ajax({
async: false,
url: "getContactLogFullComments.php",
method: "GET",
data: { ID: <insert row ID here> },
cache: false,
success: function(result) {
that.val('Comments', result);
}
});
});
The getContactLogFullComments.php script takes the row ID and returns the full comment. How do I get the DT_RowID value of the selected row so I can pass this to the PHP script?
Thanks in advance
This question has accepted answers - jump to:
Answers
Sorry for the poor formatting of the code snippet!
Found it - all I need to do is to access the selected rows:
var data = table.rows( { selected: true } ).data()[0];
data.DT_RowId gives the required ID.
Use
row().data()
if you just want a single row (so you don't need to access array index 0).Allan
Thanks Allan.