Cant acces the data from createdRow: function( row, data, dataIndex )
Cant acces the data from createdRow: function( row, data, dataIndex )
huertoVerde
Posts: 24Questions: 7Answers: 0
Hello,
I want to add a class to the row depending the value of a specific cell, so i can the color the backrground with a color.
Following a response in an other thread I added the last 4 lines to my code.
the console.log shows this
91x: row: [object HTMLTableRowElement] Status: undefined
the data is bein loaded but it does not read the rows paramater correctly nor the data[9] or data[0]
arbeitsTabelle = $('#arbeitsTabelle').DataTable({
retrieve: true,
paging: false,
info: false,
searching: true,
ordering:false,
select:true,
scrollX: true,
columns: [
{ data: "id" },
{ data: "pid" },
{ data: "vorgaenger" },
{ data: "geschaeftsfeld" },
{ data: "marke" },
{ data: "zielgruppe" },
{ data: "verwendung" },
{ data: "detail" },
{ data: "name" },
{ data: "status" },
{ data: "datum" },
{ data: "betrag" },
{ data: "kommentar" },
{ data: "lieferant" },
{ data: "wurzel" },
],
dom: "Bfrt",
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor },
],
createdRow: function( row, data, dataIndex ) {
if ( data[9] == "ETAT" ) {$(row).addClass('red');}
console.log('row: ' + row + ' pid: ' + data[0])
}
});
This question has an accepted answers - jump to answer
Answers
the same happens with this code
You are using objects for your data, ie
columns.data
, not arrays. Usedata.status
instead ofdata[9]
.Kevin