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 ?

simplerezosimplerezo 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

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765
    edited May 2023 Answer ✓

    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 this row[ 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 in columns.render. The columns.name can be used with APIs like column(). See the example in the column-selector docs.

    Kevin

  • simplerezosimplerezo Posts: 4Questions: 2Answers: 0
    edited June 2023

    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!

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765
    edited June 2023

    I tried this in my application, but it did not works

    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

Sign In or Register to comment.