How to get other columns json variables?
How to get other columns json variables?
Chris230291
Posts: 34Questions: 10Answers: 1
I am trying to figure out how to build my tables using ajax and json as I heard it performs better than building the entire table using jinja2 and then letting datatables redraw it.
json
{
"data": [
{
"data": "enabled",
"data-2": "2",
"data-3": "3",
"data-4": "4",
"data-5": "5",
"data-6": "6"
},
...
]
}
javascript
{
"data": "enabled",
"data-2": "data-2",
"data-3": "data-3",
"render": function (data, data-2, data-3) {
let r ='<input type="checkbox" data-2="' + data-2 + '" data-3="' + data-3+ '"'
if (data == "enabled") {
r = r +' checked';
}
r = r + '>'
return r
}
},
I would like to reference data-2 and data-3 in the data column as well as some other columns.
Is this possible?
Or perhaps there is a better way to set "shared" data between all columns on that row?
Answers
I think I have figured it out after finding a previous answer by @colin
Then using
row.data-2
I can use the data-2 value from the json in the data column.Yes. See the
columns.render
docs for details. Also see this example.Kevin