Referencing column elements
Referencing column elements
kgprasad
Posts: 6Questions: 4Answers: 0
Hello, I would like to set the button id to the pkey of the row, in a dynamically
created button (based on the 'status' column, see below). I am not able to get
the specific "id" I need :
$('#lidarSaas').DataTable( {
dom: 'Bfrtip',
buttons: [
'columnsToggle'
],
//"processing": true,
"ajax": {
"url": "http://127.0.0.1:8000/lidarSaas/uploads",
"dataType" :"json",
"dataSrc": "data"
},
columns: [
{ "data": "id"}, // The id I want in the code below ..
{
"data": "status",
render: function(data, type, row) {
// Dynamically add buttons indicating the rowId in the DB for easy
// reference when the function needs to be executed with that rowId
// on the server side
if (data == 'Processing') {
return '<button type="button" id=table.row(this).id onclick="handleStop(table.row(this).id)">Stop</button>';
}
return data;
}
..
}
function handleStop(id) {
alert(id);
// do stuf ..
..
}
This discussion has been closed.
Answers
Try replacing
table.row(this).id
withrow.id
.Kevin
Yup. Just to refine what Kevin says a bit, replace
table.row(this).id
withAlso:
While it won't work, the intention appears to be to assign the row id to the button, which doesn't seem like a good idea to me, since you might have two elements with the same id (the row and the button).
Two other points:
table
is not defined anywhereAllan