Editor Primary Key
Editor Primary Key
werbeacc
Posts: 7Questions: 2Answers: 0
Hello,
i use the editor extension (1.3.3) and have a problem with the Primary Key.
My Primary Key is "ContentID" and i want to show the Keys in the first column.
The Problem is, that the generated SQL Statement selects two times the field and produce because of that an error:
SELECT ContentID as 'ContentID', ContentID as 'ContentID', ...
Editor::inst( $db, 'xContent')->pkey('ContentID')
->fields(
Field::inst( 'ContentID', 'test' ),
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The primary key (regardless of what the column name is in the database) is always called "DT_RowId" in the JSON sent to the client-side (that is one of DataTables' "magic" parameters and instructs it to used the value as the row id. So on the client-side you could do:
Note I've used
columns.render
as well, since the primary key is prefixed by letters to make it a valid DOM id (assuming that your primary key is a number).This way you don't need to specify the primary key in a field - Editor will do it automatically for you. The alternative is to alias the field name, but the method above I think is fairly easy to implement.
Regards,
Allan
Hello,
thanks for your help.
I tried your solution, but maybe because of the server side progression (serverSide: true)
all fields will be POST to the server for paging, sorting...:
and i get the following response:
{"error":"Unknown field: DT_RowId (index 0)","data":[]}
I also tried to alias the field name, but it doesent change the SQL Statement, only the JSON output.
Hi,
Sorry I forgot to reply to this the other day. You are right, server-side processing is going to make that a bit more difficult, I haven't realised you were using it. Unfortunately server-side processing currently makes it impossible without a modification to the PHP libraries.
Fortunately however, that modification is quite easy :-). If you open
Editor.php
and find the_ssp_field()
function, replace the function completely with:Then my above solution will work.
Let me know how you get on with this, but I think I'll probably include it in the next release. I can't see any reason why it shouldn't be since
DT_RowId
is always the primary key (in these libraries).Allan
Hi,
many thanks, thats work great.
Hope it will implemented in further releases.
Thanks for the feedback! Good to hear that works. Yes, I think I'll include it in the next release.
Allan