Access cell value in rowCallback

Access cell value in rowCallback

yaylitzisyaylitzis Posts: 6Questions: 2Answers: 0
edited October 2020 in Free community support

Hello,
I would like to ask a question about my code..The data that I show to my table is like:

data: [
{
"shiftDate":"2020-10-30",
"weights":{
"3":8.6,
"4":8.8,
}
}

and I define my columns :

columns: [
{"data": "shiftDate"},
{"data": "weights.3"},
{"data": "weights.4"}
]

And the table is visible and constructed fine!

Now, I want inside rowCallback: function (row, data) { to check the value of the column weights.3. So I write:

var weight= data.weights.3

I get an error Uncaught SyntaxError: Unexpected number

However the

var shiftDate= data.shiftDate returns 2020-10-30.

So how can I get this cell value?
Thank you a lot!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    Answer ✓

    rowCallback: function (row, data) {

    Try using the browser's debugger or console.log( data ); to see what the structure of the data parameter is. Maybe you need to use something like var weight= data.weights[3]. I'm not sure without putting it into code. Maybe you can build a simple test case if you still need help.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • yaylitzisyaylitzis Posts: 6Questions: 2Answers: 0

    Thank you!!
    The command var weight= data.weights[3] worked !

This discussion has been closed.