php - DataTables (CRUD) - Server Side Adding New Record -
i'm trying use datatables (crud) plugin can found on datatables data manager (crud) add-on
so far working fine except when try add new record. i've followed instruction on example on link adding records , wiki example
this code i'm using insert new record
// open db connection $link = dbconnect('dbname'); $params = array(); $options = array( "scrollable" => sqlsrv_cursor_keyset ); // prepare insert $updatequery = "insert $tblname ($columns) values ($valuestemp)"; $id = 0; $entity_id = array(); // run insert , if it's been succesful enter if condition if(sqlsrv_query( $link, $updatequery ) == true){ // last inserted id $getid = "select max(entity_id) 'id' holdingtable client_id = '$client_id' , 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 connection. sqlsrv_close( $link ); // return id echo $id; }else{ // if insert failed display error echo 'there\'s been error: '; if( ($errors = sqlsrv_errors() ) != null) { foreach( $errors $error ) { echo "sqlstate: ".$error[ 'sqlstate']."<br />"; echo "code: ".$error[ 'code']."<br />"; echo "message: ".$error[ 'message']."<br />"; } } }
if run firebug , check network, i'm getting numeric id correctly on examples on website keep getting popup message following error when trying refresh table after insert.
datatables warning (table id = 'datatable'): requested unknown parameter 'entity_id' data source row 2 (this number changes depending on how many rows i've got)
that message 2 records , after inserting third one.
i've tried moving select gets id run before insert still same error , can't figure out why.
this datatables initialization:
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=<?php echo $client_id; ?>&project_id=<?php echo $project_id; ?>&system_id=<?php echo $system_id; ?>&tablename=<?php echo $tblname;?>", "sservermethod": "post", "olanguage": { "sprocessing": "<img src='/content/images/spinner_squares_circle.gif' height='15px' width='15px' alt='' /> 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": '<"h"hflip>rt<"f"ip>', "fnrowcallback": function( nrow, adata, idisplayindex, idisplayindexfull ) { $(nrow).attr("id",adata['entity_id']); return nrow; } }).makeeditable({supdateurl: "updatedata.php?client_id=<?php echo $client_id; ?>&project_id=<?php echo $project_id;?>&system_id=<?php echo $system_id; ?>&tablename=<?php echo $tblname;?>", saddurl: "adddata.php?client_id=<?php echo $client_id; ?>&project_id=<?php echo $project_id;?>&system_id=<?php echo $system_id; ?>&tablename=<?php echo $tblname;?>", sdeleteurl: "deletedata.php?client_id=<?php echo $client_id; ?>&project_id=<?php echo $project_id;?>&system_id=<?php echo $system_id; ?>&tablename=<?php echo $tblname;?>", 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 select country code', // country_code drop down loadtext: 'loading...', data: '<?php print json_encode($country, json_hex_apos); ?>', 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 select participant template', // participant template drop down loadtext: 'loading...', data: '<?php print json_encode($template); ?>', type: 'select', submit: 'ok' }, { tooltip: 'click select language', // language code drop down loadtext: 'loading...', data: '<?php print json_encode($language); ?>', type: 'select', submit: 'ok' } //language_code ] });
i still haven't found solution this. i've been googling around , of post talk null values in json i've modified aocolumns , added sdefaultcontent: "" have blank values instead of nulls. still same error.
it seems there wrong json.
i've added sdefaultcontent:"" each 1 of column declarations in aocolumns , error gone now.
so aocolumns now
"aocolumns": [ { "mdataprop": "checkbox" ,"bsortable":false ,sdefaultcontent:"", "swidth" : "1%"}, { "mdataprop": "entity_id" , "bsortable":true, "bvisible": false, sdefaultcontent: "", "swidth" : "1%" }, { "mdataprop": "external_id" ,"bsortable":true, sdefaultcontent: "", "swidth" : "1%" }, { "mdataprop": "family_name" ,"bsortable":true, sdefaultcontent: "", "swidth" : "5%" }, { "mdataprop": "first_name" ,"bsortable":true, sdefaultcontent: "", "swidth" : "5%" }, { "mdataprop": "prefix_title" ,"bsortable":true, sdefaultcontent: "", "swidth" : "1%" }, { "mdataprop": "suffix_title" ,"bsortable":true, sdefaultcontent: "", "swidth" : "1%" }, { "mdataprop": "company" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "address_1" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "address_2" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "address_3" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "address_4" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "zip_code" ,"bsortable":true, sdefaultcontent: "", "swidth" : "1%" }, { "mdataprop": "city" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "country_code" ,"bsortable":true, sdefaultcontent: "", "swidth" : "1%" }, { "mdataprop": "telephone" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "telefax" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "email" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "email2" ,"bsortable":true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "session_id" ,"bsortable":true, sdefaultcontent: "", "bvisible": false, "swidth" : "2%" }, { "mdataprop": "gender" ,"bsortable":true, sdefaultcontent: "", "swidth" : "1%" }, { "mdataprop": "jmuser_id" ,"bsortable":true, sdefaultcontent: "", "bvisible": false, "swidth" : "1%" }, { "mdataprop": "password" ,"bsortable":true, sdefaultcontent: "", "bvisible": false, "swidth" : "1%" }, { "mdataprop": "extrafield01" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "extrafield02" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "extrafield03" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "extrafield04" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "extrafield05" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "extrafield06" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "extrafield07" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "extrafield08" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "extrafield09" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "extrafield10" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "mobile" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "url" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "passport_number" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "nationality" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "id_number" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "date_of_birth" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "2%" }, { "mdataprop": "special_needs_physical" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "3%" }, { "mdataprop": "special_needs_dietary" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "3%" }, { "mdataprop": "first_name_for_badge" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "5%" }, { "mdataprop": "family_name_for_badge" ,"bsortable":true, sdefaultcontent: "", "bvisible": true, "swidth" : "5%" }, { "mdataprop": "biography" ,"bsortable":true, "bvisible": true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "vat_number" ,"bsortable":true, "bvisible": true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "membership_no" ,"bsortable":true, "bvisible": true, sdefaultcontent: "", "swidth" : "2%" }, { "mdataprop": "participant_template" ,"bsortable":true, "bvisible": true, sdefaultcontent: "", "swidth" : "1%" }, { "mdataprop": "language_code" ,"bsortable":true, "bvisible": true, sdefaultcontent: "", "swidth" : "1%" } ],
all sorted!
Comments
Post a Comment