How to avoid using DT_RowId
How to avoid using DT_RowId
I'm sorry for the newbie question but I've already tried to look everywhere for this issue and found nothing.
In the database of the CRUD app I'm trying to build I've already defined a primary key, let's call it 'code'. When I use the prebuilt PHP libraries, the primary key that gets printed on the ajax object is called 'DT_rowId', and not 'code', and the values have a "row_" prefix.
How can I avoid this behaviour? I'd like the data to be 1:1 with the one on the database, both with column name and values.
Thank you in advance
Answers
Our Editor PHP libraries will always call the primary key
DT_RowId
- that is not configurable I'm afraid. Making it configurable has never come up before has never come up before as far as I can recall, although I do know it is nice to have full control over the data.The Editor libraries can use any column name as the primary key - it doesn't need to be the default
id
. It will always call itDT_RowId
over the wire though.At the client-side, both DataTables and Editor will look for
DT_RowId
by default. If changed (e.g. using a server-side that is not our published libraries), you'd need to changerowId
for DataTables andidSrc
for Editor.If you are happy adding that extra configuration, and really want to lose the
DT_RowId
over the wire, then there is a way to do it: use the->data()
method rather than->json()
of theEditor
class, and modify the data:I don't see much advantage though - there isn't any to the end user.
Allan
Honestly it wouldn't be an issue using DT_RowId if datatables is built this way, but the fact that the data gets a "row_" prefix makes it impossible to edit them, since it loads "row_XXX" and not "XXX".
I'm wondering if loading the primary key as a field, in addition to the primary key in the constructor, can let me load and edit the data 1:1 with the database letting the DT_RowId values hidden and only for the correct functioning of datatables.
I'm currently on free trial with Editor, but considering buying the full license if I can set things to work.
I forgot to address the point about the
row_
prefix - apologies. That can be controlled with theidPrefix
method.will remove the prefix. The reason it is there is two fold:
If you are using the DataTables PHP libraries for both fetching and editing data, it will handle the id prefix for you entirely.
Allan