Getting selected row ID in javascript

Getting selected row ID in javascript

milled00milled00 Posts: 14Questions: 4Answers: 1

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

  • milled00milled00 Posts: 14Questions: 4Answers: 1

    Sorry for the poor formatting of the code snippet!

  • milled00milled00 Posts: 14Questions: 4Answers: 1
    Answer ✓

    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.

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    Use row().data() if you just want a single row (so you don't need to access array index 0).

    Allan

  • milled00milled00 Posts: 14Questions: 4Answers: 1

    Thanks Allan.

This discussion has been closed.