rowId - can't get this guy to work
rowId - can't get this guy to work

I'm adding the property "rowId": "id"
to a lengthy existing DataTables()
call expecting that the rowId will be set, but it doesn't seem to. Perhaps I misunderstand what this does?
The shape of the data passed to DataTables()
is simple: it's an Ajax call that returns a javascript array of objects. Each object has several properties, and id
is one of them. What I expect to happen is that each TR should have an id
property with the id of each object that makes up that row. However, no id
is set whatsoever.
Note that the creation of the DataTable works just fine, all columns are populated correctly.
Answers
Seems to work in this example:
http://live.datatables.net/voxofuze/1/edit
Maybe you can provide more specifics (example) of your data and the Datatables init code. Better yet maybe you can update my example with a sample of your data and table structure.
Kevin
Here's an example of what I'm working with:
The shape of the data returned by the Ajax call looks like this (Chrome console log):
Note that not all fields are shown above. Here's an example of item 0:
Not sure what the problem is. I updated my example which seems to work:
Here is the live example:
http://live.datatables.net/voxofuze/2/edit
I might be missing something but it seems your ID value works in a generic test. Can you post a link to your page for troubleshooting?
Kevin
That it does, so it appears there's a more complex bug, perhaps a conflict in properties with the DataTables library. Hopefully a contributor can locate the issue and solve this quickly!
Unfortunately the forums here are pretty broken, so it's difficult for me to make an edit, so I'll make a second comment.
Re: posting link to page -- I cannot post a link to the page as it's a private repository used internally.
Maybe you can generate debugger output and post s link to the result. This provide the full data set returned.
https://datatables.net/manual/tech-notes/10
Kevin
My guess is that you are using an old version of DataTables which doesn't support
rowId
- as the documentation shows you need DataTables 1.10.8 or newer.Kevin has already kindly posted an example showing it working. We would need a test case showing it not working to be able to help debug and resolve the issue.
Allan
No, sorry, the version of DataTables is 1.10.9. I forgot to list that.
Over the evening we managed to solve this. It's unrelated to DataTables. I really appreciate the effort you guys put in, thank you!
The row-id is not set when e.g. "rowId": "id" is set and the (ajax) datastring provided is like
{"sColumns":"id,device,name","aaData":[["9317","MyPC","My computer"],["5247....
This is tested on DataTables version 1.10.18.
It would be an improvement when the datatable accepts this data/config as well. Thank you!
@weijgaert ,
Using
"rowId": "id"
indicates that the data is in object form and usingcolumns.data
to define the columns. But the example you show the data is in array form. Looks like you can set an array position to define therowId
. For example:http://live.datatables.net/huhaquju/1/edit
I set
rowId: 1
to show that it works. You can change it torowId: 0
as that is likely your true ID.There isn't an option to set the columns when using the
ajax
option. However you can use an external jQuery Ajax request to get both the data and columns and set them accordingly. For example:http://live.datatables.net/huyexejo/1/edit
Instead of processing the first data element for the columns you would process the
sColumns
object.Kevin