Storing additional 'hidden' information (e.g. database ID) in Datatables

Storing additional 'hidden' information (e.g. database ID) in Datatables

auris2018auris2018 Posts: 11Questions: 3Answers: 0

I am presenting a database (in my case Project List) on a datatable where some of the fields are foreign keys (in my case Client). There's a client per project and each client has a database ID and a name. In the datatable, I want to display the name (e.g. Amazon) but I'd also like to 'hide' and access the client primary key (e.g. 58) so I could grab it for processing afterwards. Would a datatable be suitable for storing the primary key in, say, <td id=58></td> or is this a bad idea? Many thanks.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,673Questions: 26Answers: 5,018
    Answer ✓

    You can return the id field in your data for each row. There is no requirement to display it in the table. Datatables uses a cache for all the data whether in the table or not. You can access the Datatables data using the row().data() API. Optionally you could put the data in a hidden column using columns.visible.

    There are lots of options :smile:

    Kevin

  • auris2018auris2018 Posts: 11Questions: 3Answers: 0

    Thanks. I am already using the hidden column option but would to prefer to set it as ID just to make it neater. Just wanted to make sure it won't mess anything else up. I'll give it a try.

This discussion has been closed.