stack: Error: Primary key element is not available in the data set

stack: Error: Primary key element is not available in the data set

ChrisLChrisL Posts: 12Questions: 3Answers: 0
edited June 4 in Editor

I'm using the registered version of Datatables/Editor widely on a new site.

I've found what might be a bug thought.

Im accessing a table with 3 columns:

id which is an auto increment primary key
name with is just a string - I forget the exact length
number which is just an integer.

I create the Datatables instance using all three fields but I set the 'id' field to be hidden using columnDefs because the value is only there so when a row is selected I can pick up the 'id' for further use.

I create the editor object with all three fields but again for the same reason I set the 'id' field to hidden.

In the node.js controller the 'id' field is listed with

.setFormatter(Format.ifEmpty(null)),

If I don't mention the ID field in the node.js controller, Datatables falls down because it can't populate the hidden column.

When I do mention the field and click the 'New' button and fill out the values and click 'Save' I get the following error message:

stack: Error: Primary key element is not available in the data set
    at Editor.pkeyToValue (/var/www/html/development.alltec.com/public_html/nodejs/Editor-NodeJS-2.0.2/node_modules/datatables.net-editor-server/dist/editor.ts:797:11)
    at Editor._pkeySubmitMerge (/var/www/html/development.alltec.com/public_html/nodejs/Editor-NodeJS-2.0.2/node_modules/datatables.net-editor-server/dist/editor.ts:1643:15)
    at Editor.<anonymous> (/var/www/html/development.alltec.com/public_html/nodejs/Editor-NodeJS-2.0.2/node_modules/datatables.net-editor-server/dist/editor.ts:1346:9)
    at step (/var/www/html/development.alltec.com/public_html/nodejs/Editor-NodeJS-2.0.2/node_modules/datatables.net-editor-server/dist/editor.js:56:23)
    at Object.next (/var/www/html/development.alltec.com/public_html/nodejs/Editor-NodeJS-2.0.2/node_modules/datatables.net-editor-server/dist/editor.js:37:53)
    at fulfilled (/var/www/html/development.alltec.com/public_html/nodejs/Editor-NodeJS-2.0.2/node_modules/datatables.net-editor-server/dist/editor.js:28:58)

yet the record is correctly created., but Editor seems to stall with its little progress bar cycling.

From logging it appears as expected since the row is created that it does an SQL insert setting all three fields, but setting the ID field to null and hence it gets an auto increment value as planned.

How do I stop this error stalling something that is otherwise functioning as intended as far as I can see?

Thanks in advance!

Replies

  • allanallan Posts: 54,181Questions: 1Answers: 8,456 Site admin

    Hi,

    Just to confirm, you have a Field instance for the primary key? If so, and it is auto-increment, you'll want to do:

    Field::inst('id')->set(false)
    

    (change id as needed) as Editor will handle the primary key value for you automatically. The only reason to have a Field::inst('id') is if you want to show the primary key value in the table or the form.

    Regards,
    Allan

Sign In or Register to comment.