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

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
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 therow().data()
API. Optionally you could put the data in a hidden column usingcolumns.visible
.There are lots of options
Kevin
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.