Reputation: 15
How to get id of the selected row, i using jtable
.
I sow event selectionchanged but i do not know how to get first cell of the selected row which is the id.
Name of the table is tModelIndex
selectionChanged: function () {
var $selectedRows = $('#tModelIndex').jtable('selectedRows');
if ($selectedRows.length > 0) {
// alert(1);
}
}
Upvotes: 0
Views: 2690
Reputation: 916
Check this link here you can find simple example
Make sure you have used this features in jTable
selecting: true, //Enable selecting
multiselect: true, //Allow multiple selecting
selectingCheckboxes: true //Show checkboxes on first column
And then in selectionChanged event
selectionChanged: function () {
//Get all selected rows
var $selectedRows = $('#tModelIndex').jtable('selectedRows');
if ($selectedRows.length > 0) {
//Show selected rows
$selectedRows.each(function () {
var record = $(this).data('record');
alert(record.StudentId);
alert(record.Name);
});
} else {
//No rows selected logic here
}
}
In this
, StudentId means your column name in jTable
record.StudentId
Upvotes: 4