Row Selector

Row Selector

MoeYehyaMoeYehya Posts: 16Questions: 9Answers: 0
edited January 2023 in Free community support

Hello,

I have a table with first column called 'dataId' and also 'name' column, dataId is unique and its value is integer.
there is a way to find name where dataId = 5 for example?
i was trying this:
table.row({'dataId': 5}).data().pluck('name')[0];

Moreover, I will use dataId always but i prefer to not show it for user knowing that I am setting columns dynamically from options (i am getting them from backend).
there is a way to hide 'dataId' column but still use it?

thanks!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    there is a way to find name where dataId = 5 for example?

    Use row().data() with the row-selector as a function.

    there is a way to hide 'dataId' column but still use it?

    Use columns.visible to hide the column.

    Kevin

  • MoeYehyaMoeYehya Posts: 16Questions: 9Answers: 0

    for row().data(), most of the examples are using it inside click event and they are taking (this).
    in my case I am trying to find the row based on column (dataId) value.
    can i do that directly?

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954
    edited January 2023 Answer ✓

    Did you look at the function example I linked to? There is no click event. The function will return the row(s) that match the criteria you specify. If its one row use row().data(). if there is a possiblity of more than one row use rows().data().

    Kevin

  • MoeYehyaMoeYehya Posts: 16Questions: 9Answers: 0

    my bad, i was trying both methods but they returned null.
    I had to wait like 1-2 seconds for table creation before I get values.

    thank you!

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    Likely you need to wait for the asynchronous ajax response. You can use initComplete if you want the values immediately after initialization. Use 'this.api() to get the Datatables API instance, for example this.api().row().data();.

    Kevin

Sign In or Register to comment.