In a render function, is it possible to access row through its name ?
In a render function, is it possible to access row through its name ?
simplerezo
Posts: 4Questions: 2Answers: 0
I need to use the value of another column in a render function of a column.
I can access datas through $row parameter using the index ($row[0]).
But I would like to use something more "robust" (like column "name"), but I did not succeed... how can I achieve this ?
Example (not working ): https://live.datatables.net/qugaqohi/1/edit?js,output
This question has an accepted answers - jump to answer
Answers
Your row data is array based. The
row
parameter is a Javascript variable and falls within Javascript rules to access array data. You could set a global variable,office
for example, with the index and access it like thisrow[ office [
. Or you can use object based rows, like this:https://live.datatables.net/qewabexa/1/edit
See the data docs for details.
To answer your question you can't access the column with the
columns.name
incolumns.render
. Thecolumns.name
can be used with APIs likecolumn()
. See the example in thecolumn-selector
docs.Kevin
OK, so basically just switching from "name" to "data" in my example make it works
That's weird, because I tried this in my application, but it did not works.... but now I know it should work
Thank you!
It depends on your data source. If your data is from ajax or javascript and is array based then it won't work. In this case you will need to convert your source data to use objects to use
columns.data
.Kevin