Basically, I have a button in every row in the third column, and when the user clicks on the button, I would like to call a function with parameters (they are from the table row). I saw that someone use row.errorType (for example), but that's gave me 'undefined' value :( Any ideas?
columns: [
{
"data": "errorType",
"render": function (data) {
return data;
}
},
{
"data": "errorDescription",
"render": function (data) {
return data;
}
},
{
"data": "entityId",
"render": function (data, row) {
return `<button onclick="openModal(${row.errorType}, ${row.errorDescription}, ${data})"><i ></i></button>`;
}
}
],
CodePudding user response:
You are using the DataTables columns.render
option, but you are not supplying the expected parameters.
You are using:
"render": function (data, row) { ... }
You should be using:
"render": function (data, type, row, meta) { ... }
So, what you are referring to as row
is actually type
. Change your parameters as shown above to pick up the row
data object correctly - and then you should be able to use variables such as row.errorType
in your string builder.
You still need to ensure that variables which resolve to strings are themselves enclosed in quotes, so your string template may need to be adjusted.
For example, you may need "${row.errorDescription}"
instead of ${row.errorDescription}
.