rowId option as a function
rowId option as a function
Due to having multiple tables in the DOM at one time, each requiring rows have DOM id
attributes I can use rowId
to give the tr
nodes id
attributes. However, id
values across tables may clash so it's useful prefix them by using specifying rowId
as a function, such as:
rowId: function(data) {
return "countryPrefix_" + data.id;
},
However, the documentation for rowId
makes no reference to using a function. Is this an official part of the DataTable API?
Obviously it's extremely useful but it would be an issue if it was to suddenly disappear from being unofficial/undocumented and I shouldn't have been using it in the first place
This question has an accepted answers - jump to answer
Answers
I don't know if there is a specific way to do it using the
rowId
option, but you could create a specific field in your data that has the prefix added and use that for therowId
value.Data:
Set
rowId
:That's an option, I can easily intercept the JSON data and use
to add the new node to each array element but one I was hoping to avoid by using rowId as a function.
Using a function for rowId works nicely so my question really boils down to whether it's an official feature and won't disappear without notice. If it's official it would be nice to be in the documentation and would be my preferred method, if not it's official the option above is probably safer.
Using it as a function works because it basically uses the same method that
columns.data
uses to get and set data - i.e. everything listed there, including functions, should work, but it isn't something that I've explicitly tested, which is why it isn't documented.I don't foresee that being removed in future. If anything it is more likely to documented and correctly supported.
Allan
Excellent, thanks @allan , and thanks for the speedy response!
I'm also using rowId as a function, very useful for me.