Add a setting for a client side DT_RowID prefix
Add a setting for a client side DT_RowID prefix
paulhickman
Posts: 21Questions: 1Answers: 0
The natural row ID in my data is an integer. However, I can't pass this in the DT_RowId element of my ajax data because it would lead to integer id attributes on tags. This is invalid in HTML 4 and, although supported in HTML 5, would lead to name clashes when there is more than one data table on a page.
Therefore, I would like to request an "sRowIdPrefix" setting in the options for the data table which would be added in front of the actual DT_RowId when it is converted to an id attribute for the tag, and is removed again whenever something queries the ID of a row, such as the editor.
Without this, it greatly complicates things as I have to:
- pass some custom data to my webservice call so the web service can prefix each row id with it (to avoid clashes when 2 tables call the same web service, I need the ajax call to send this rather than hard coding it server-side)
- add the prefix server side increasing the data size
- remove the prefix again in my edit and delete web services
Also, because the ID data type doesn't match the data type of my actual data, it complicates Asp.Net MVC model binding.
An alternative solution would be to store the row ID in an attribute of the tag other than id.
Therefore, I would like to request an "sRowIdPrefix" setting in the options for the data table which would be added in front of the actual DT_RowId when it is converted to an id attribute for the tag, and is removed again whenever something queries the ID of a row, such as the editor.
Without this, it greatly complicates things as I have to:
- pass some custom data to my webservice call so the web service can prefix each row id with it (to avoid clashes when 2 tables call the same web service, I need the ajax call to send this rather than hard coding it server-side)
- add the prefix server side increasing the data size
- remove the prefix again in my edit and delete web services
Also, because the ID data type doesn't match the data type of my actual data, it complicates Asp.Net MVC model binding.
An alternative solution would be to store the row ID in an attribute of the tag other than id.
This discussion has been closed.
Replies
Depending upon your use case (perhaps you could explain it?), what you could do is simply leave the id in the data source object and use fnGetData or `_` to get the data, with the id, when required (submitting by ajax?).
One thing i have thought about before us having a `DT_Data_{...}` type variable which would add HTML5 `data` attributes to the TR element. That might be suitable?
Allan
As I understand it, the editor uses the DT_RowID to tell me which rows it is updating/deleteing in the callbacks, therefore this needs to be set. If there is some other way of telling the editor which column to treat as the ID, then I don't need to use DT_RowID.
In that case, you are quite correct, Editor currently does need the ID to be given in the DOM ID. In retrospect that seems unnecessarily restrictive and there should be an option for it to read from the data source object since it will always have that available (in one way or another). I will ensure that goes into the next version.
Until then, the client-side option is to use fnServerData in the DataTables initialisation to make an Ajax call, and in the success callback, loop over the data provided adding the DOM prefix needed to DT_RowId. You'd also need to provide an `ajax` method for Editor which modifies the values sent to the server. A bit messy :-(
I'm tied up with other stuff at the moment, but I'll try to find time as soon as possible to get this implemented.
Regards,
Allan