Cant acces the data from createdRow: function( row, data, dataIndex )

Cant acces the data from createdRow: function( row, data, dataIndex )

huertoVerdehuertoVerde 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

  • huertoVerdehuertoVerde Posts: 24Questions: 7Answers: 0

    the same happens with this code

            $('#arbeitsTabelle').on('click', 'tr', function () {
                var data = arbeitsTabelle.row( this ).data();
                alert( 'You clicked on '+data[1]+'\'s row' );
            } );
    
  • kthorngrenkthorngren Posts: 21,325Questions: 26Answers: 4,949
    Answer ✓

    You are using objects for your data, ie columns.data, not arrays. Use data.status instead of data[9].

    Kevin

Sign In or Register to comment.