Reputation: 37
I have a JFiddle that is able to recognise the table row and return the table data as required but need to return the last two cells of the row, which are write-able, modify and return modified values? How can I modify the jQuery as follows?
$(document).ready(function () {
var table = $('#example').DataTable();
$('#example tbody').on('click', 'tr', function () {
$(this).toggleClass('selected');
});
$('#button').click(function () {
var ids = $.map(table.rows('.selected').data(), function (item) {
return item[0]
});
console.log(ids)
for(var i =0;i<table.rows('.selected').data().length;i++){
alert(table.rows('.selected').data()[i] + ' row(s) selected');
}
});
});
http://jsfiddle.net/arunpjohny/f4bppa43/
Upvotes: 1
Views: 1875
Reputation: 37
This pretty much does it after painstaking testing and experimenting!
$(document).ready(function () {
var table = $('#example').DataTable();
$('#example tbody').on('click', 'tr', function () {
$(this).toggleClass('selected');
});
$('#button').click(function () {
var ids = $.map(table.rows('.selected').data(), function (item) {
return item[0]
});
console.log(ids)
for(var i =0;i<table.rows('.selected').data().length;i++){
alert(table.rows('.selected').data()[i] + ' row(s) selected');
}
});
var ids = table.rows('.selected').data()
$('#button').click(function( row, data, index ) {
row=table.rows('.selected');
data=table.rows('.selected').data();
if ( data[0] == "1,System Architect,Edinburgh,61,2011/04/25,$320,800" ) {
alert($('td:eq(4)',row[1]).text());
}
});
});
http://jsfiddle.net/f4bppa43/480/
Upvotes: 0
Reputation: 5719
Based on original documentation there are a couple of ways to do this:
https://datatables.net/reference/type/cell-selector
1- By Id:
var table = $('#example').DataTable();
var data = table.cell('#cell-2-42').data();
2- By Class
var table = $('#example').DataTable();
var cells = table.cells('.priority');
3- By Multiple selectors:
var table = $('#example').DataTable();
var cells = table.cells('.important, .intermediate');
Upvotes: 1