Note that there are some explanatory texts on larger screens.

plurals
  1. PODataTables (CRUD) - Server Side Adding New Record
    primarykey
    data
    text
    <p>I'm trying to use the DataTables (CRUD) plugin that can be found on <a href="http://jquery-datatables-editable.googlecode.com/svn/trunk/index.html" rel="nofollow">DataTables Data Manager (CRUD) Add-on</a></p> <p>So far everything is working fine except when I try to add a new record. I've followed the instruction on the example on this link <a href="http://jquery-datatables-editable.googlecode.com/svn/trunk/addingrecords.html" rel="nofollow">Adding Records</a> and the <a href="https://code.google.com/p/jquery-datatables-editable/wiki/AddingNewRecords#PHP_Example" rel="nofollow">WiKi Example</a></p> <p>This is the code I'm using to insert the new record</p> <pre><code> // Open the db connection $link = dbConnect('dbname'); $params = array(); $options = array( "Scrollable" =&gt; SQLSRV_CURSOR_KEYSET ); // Prepare the insert $updateQuery = "INSERT INTO $tblname ($columns) VALUES ($valuesTemp)"; $id = 0; $entity_id = array(); // Run the insert and if it's been succesful enter the if condition if(sqlsrv_query( $link, $updateQuery ) == true){ // Get the last inserted ID $getId = "SELECT MAX(Entity_Id) AS 'Id' FROM HoldingTable WHERE Client_Id = '$client_id' AND Project_Id = '$project_id'"; $result = sqlsrv_query( $link, $getId, $params, $options ); while ( $aRow = sqlsrv_fetch_array( $result, SQLSRV_FETCH_NUMERIC ) ) { $entity_id = $aRow; } $id = $entity_id[0]; // Close the connection. sqlsrv_close( $link ); // return the id echo $id; }else{ // If the insert failed display an error echo 'There\'s been an error: '; if( ($errors = sqlsrv_errors() ) != null) { foreach( $errors as $error ) { echo "SQLSTATE: ".$error[ 'SQLSTATE']."&lt;br /&gt;"; echo "code: ".$error[ 'code']."&lt;br /&gt;"; echo "message: ".$error[ 'message']."&lt;br /&gt;"; } } } </code></pre> <p>If run firebug and check the network, I'm getting the numeric ID correctly like on the examples on the website but I keep getting a popup message with the following error when trying to refresh the table after the insert.</p> <pre><code>DataTables warning (table id = 'dataTable'): Requested unknown parameter 'Entity_Id' from the data source for row 2 (This number changes depending on how many rows I've got) </code></pre> <p>That message was with two records and after inserting a third one.</p> <p>I've tried moving the select that gets the id to run before the insert but still get the same error and can't figure out why.</p> <p>This is the DataTables initialization:</p> <pre><code>oTable = $('#dataTable').dataTable({ "bJQueryUI": true, "sScrollX": "100%", "sScrollXInner": "400%", "sScrollY": calcDataTableHeight(), "bScrollCollapse": false, "bAutoWidth": false, "bDeferRender": true, "bPaginate": true, "bProcessing": true, "bServerSide": true, "sAjaxSource": "/scripts/jmevent/dbhelper.php?Client_Id=&lt;?php echo $client_id; ?&gt;&amp;Project_Id=&lt;?php echo $project_id; ?&gt;&amp;System_Id=&lt;?php echo $system_id; ?&gt;&amp;TableName=&lt;?php echo $tblname;?&gt;", "sServerMethod": "POST", "oLanguage": { "sProcessing": "&lt;img src='/content/images/spinner_squares_circle.gif' height='15px' width='15px' alt='' /&gt; Processing" }, "aaSorting": [[ 1, "desc" ]], "aoColumns": [ { "mDataProp": "Entity_Id" , "bSortable":true, "bVisible": false, "sWidth" : "1%" }, { "mDataProp": "External_Id" ,"bSortable":true, "sWidth" : "1%" }, { "mDataProp": "Family_Name" ,"bSortable":true, "sWidth" : "5%" }, { "mDataProp": "First_Name" ,"bSortable":true, "sWidth" : "5%" }, { "mDataProp": "Prefix_Title" ,"bSortable":true, "sWidth" : "1%" }, { "mDataProp": "Suffix_Title" ,"bSortable":true, "sWidth" : "1%" }, { "mDataProp": "Company" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "Address_1" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "Address_2" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "Address_3" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "Address_4" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "Zip_Code" ,"bSortable":true, "sWidth" : "1%" }, { "mDataProp": "City" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "Country_Code" ,"bSortable":true, "sWidth" : "1%" }, { "mDataProp": "Telephone" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "Telefax" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "EMail" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "EMail2" ,"bSortable":true, "sWidth" : "2%" }, { "mDataProp": "Session_Id" ,"bSortable":true, "bVisible": false, "sWidth" : "2%" }, { "mDataProp": "Gender" ,"bSortable":true, "sWidth" : "1%" }, { "mDataProp": "JMUser_Id" ,"bSortable":true, "bVisible": false, "sWidth" : "1%" }, { "mDataProp": "Password" ,"bSortable":true, "bVisible": false, "sWidth" : "1%" }, { "mDataProp": "ExtraField01" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ExtraField02" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ExtraField03" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ExtraField04" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ExtraField05" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ExtraField06" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ExtraField07" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ExtraField08" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ExtraField09" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ExtraField10" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "Mobile" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "URL" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "Passport_Number" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "Nationality" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "ID_Number" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "Date_Of_Birth" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "Special_Needs_Physical" ,"bSortable":true, "bVisible": true, "sWidth" : "3%" }, { "mDataProp": "Special_Needs_Dietary" ,"bSortable":true, "bVisible": true, "sWidth" : "3%" }, { "mDataProp": "First_Name_For_Badge" ,"bSortable":true, "bVisible": true, "sWidth" : "5%" }, { "mDataProp": "Family_Name_For_Badge" ,"bSortable":true, "bVisible": true, "sWidth" : "5%" }, { "mDataProp": "Biography" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "VAT_Number" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "Membership_No" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, { "mDataProp": "Participant_Template" ,"bSortable":true, "bVisible": true, "sWidth" : "1%" }, { "mDataProp": "Language_Code" ,"bSortable":true, "bVisible": true, "sWidth" : "1%" } ], "sPaginationType": "two_button", //full_numbers,two_button "bInfo": true, "sSearch" : true, "iDisplayStart": 0, "iDisplayLength": 50, "bLengthChange": true, "aLengthMenu": [[10, 25, 50, 100, 250, 500, -1], [10, 25, 50, 100, 250, 500, "All"]], "sDom": '&lt;"H"hflip&gt;rt&lt;"F"ip&gt;', "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { $(nRow).attr("id",aData['Entity_Id']); return nRow; } }).makeEditable({sUpdateURL: "updatedata.php?Client_Id=&lt;?php echo $client_id; ?&gt;&amp;Project_Id=&lt;?php echo $project_id;?&gt;&amp;System_Id=&lt;?php echo $system_id; ?&gt;&amp;TableName=&lt;?php echo $tblname;?&gt;", sAddURL: "adddata.php?Client_Id=&lt;?php echo $client_id; ?&gt;&amp;Project_Id=&lt;?php echo $project_id;?&gt;&amp;System_Id=&lt;?php echo $system_id; ?&gt;&amp;TableName=&lt;?php echo $tblname;?&gt;", sDeleteURL: "deletedata.php?Client_Id=&lt;?php echo $client_id; ?&gt;&amp;Project_Id=&lt;?php echo $project_id;?&gt;&amp;System_Id=&lt;?php echo $system_id; ?&gt;&amp;TableName=&lt;?php echo $tblname;?&gt;", fnShowError: function (message, action) { switch (action) { case "update": break; case "delete": break; case "add": $("#lblAddError").html(message); $("#lblAddError").show(); break; } }, fnStartProcessingMode: function () { $("#processing_message").dialog(); }, fnEndProcessingMode: function () { $("#processing_message").dialog("close"); }, "aoColumns":[ {}, //External_Id {}, //Family_Name {}, //First_Name {}, //Prefix_Title {}, //Suffix_Title {}, //Company {}, //Address_1 {}, //Address_2 {}, //Address_3 {}, //Address_4 {}, //Zip_Code {}, //City { tooltip: 'Click to select country code', // Country_Code drop down loadtext: 'Loading...', data: '&lt;?php print json_encode($country, JSON_HEX_APOS); ?&gt;', type: 'select', submit: 'Ok' }, {}, //Telephone {}, //Telefax { cssclass: "email" }, //Email {}, //Email2 {}, //Gender {}, //ExtraField01 {}, //ExtraField02 {}, //ExtraField03 {}, //ExtraField04 {}, //ExtraField05 {}, //ExtraField06 {}, //ExtraField07 {}, //ExtraField08 {}, //ExtraField09 {}, //ExtraField10 {}, //Mobile {}, //URL {}, //Passport_Number {}, //Nationality {}, //ID_Number { }, { //Date_Of_Birth type: 'text', cssclass: 'datefield' }, //Special_Needs_Physical {}, //Special_Needs_Dietary {}, //First_Name_For_Badge {}, //Family_Name_For_Badge {}, //Biography {}, //VAT_Number {}, //Membership_No {}, //Participant_Template { tooltip: 'Click to select participant template', // Participant Template drop down loadtext: 'Loading...', data: '&lt;?php print json_encode($template); ?&gt;', type: 'select', submit: 'Ok' }, { tooltip: 'Click to select a language', // Language Code drop down loadtext: 'Loading...', data: '&lt;?php print json_encode($language); ?&gt;', type: 'select', submit: 'Ok' } //Language_Code ] }); </code></pre> <p>I still haven't found a solution for this. I've been googling around and most of the post talk about null values in the JSON so I've modified the aoColumns and added this sDefaultContent: "" to have blank values instead of nulls. But I still get the same error.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload