Custom Primary Key

Custom Primary Key

Matthew2051Matthew2051 Posts: 13Questions: 1Answers: 0
edited January 2014 in Editor
Hello,

Really struggling to implement the Editor plugin. The MySQL tables I am working with rarely have a primary key name of 'id'. I have been trying to search for a solution with little luck. Played around with the example called browser and altered the MySQL primary key column name to idTest and altered the .js to show the following:

[code]
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "php/browsers.php",
"domTable": "#example",
'srcId': 'idTest',
"fields"...
[/code]

This produces the following alert;
[quote]DataTables warning (table id = 'example'): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field list[/quote]

Any help would be much appreciated. Please bear in mind I am only a novice wishing to use this great tool! Thank you.

Replies

  • Matthew2051Matthew2051 Posts: 13Questions: 1Answers: 0
    edited January 2014
    Apologies, the snippet is actually as follows (using idSrc);

    [code]
    $(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
    "ajaxUrl": "php/browsers.php",
    "domTable": "#example",
    "idSrc": "idTest",
    "fields"
    [/code]
  • Matthew2051Matthew2051 Posts: 13Questions: 1Answers: 0
    Solved, sorry for the topic. Found that setting the pkey in the third parameter of the Editor class constructor worked.
  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    That's it :-). There is also a `pkey()` method which can be used in the chaining to set / get the primary key if needed.

    Allan
  • MbdesignMbdesign Posts: 17Questions: 0Answers: 0
    for me "idSrc": "idTest", do not work in Editor 1.2.4
  • MbdesignMbdesign Posts: 17Questions: 0Answers: 0
    http://www.datatables.net/forums/discussion/19295/editor-1-2-4-change-name-of-primary-key#Item_3
This discussion has been closed.