jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Error trying to edit grid data
Tagged: edit grid
This topic contains 3 replies, has 2 voices, and was last updated by dujmovicv 9 years, 2 months ago.
-
Author
-
Hi All,
I’m trying to set up jqwidgets data grid within my Codeigniter application.
I managed to set it up and it displays all the data from mysql database. I’m having issues with making the EDIT function to work. I checked and tried everything that I thought to be correct but I got stucked…
Here’s the index file :<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content="dujmovicv@gmail.com"> <title>KAS-MPF System</title> <!-- Bootstrap core CSS --> <link href="<?php echo HTTP_CSS_PATH; ?>bootstrap.css" rel="stylesheet"> <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" /> <!-- Add custom CSS here --> <link href="<?php echo HTTP_CSS_PATH; ?>style.css" rel="stylesheet"> <!-- JavaScript --> <script src="<?php echo HTTP_JS_PATH; ?>jquery-1.10.2.js"></script> <script src="<?php echo HTTP_JS_PATH; ?>bootstrap.js"></script> <script src="<?php echo HTTP_JS_PATH; ?>das.js"></script> <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="<?php echo HTTP_JS_PATH; ?>html5shiv.js"></script> <script src="<?php echo HTTP_JS_PATH; ?>respond.min.js"></script> <![endif]--> <?php switch ($page) { case 'invoices': ?> <link rel="stylesheet" href="<?php echo HTTP_CSS_PATH; ?>jqx.base.css" type="text/css" /> <link rel="stylesheet" href="<?php echo HTTP_CSS_PATH; ?>jqx.classic.css" type="text/css" /> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jquery-1.11.1.min.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxmenu.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxcheckbox.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxdropdownlist.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxgrid.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxgrid.selection.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxgrid.edit.js"></script> <script type="text/javascript" src="<?php echo HTTP_JS_PATH; ?>jqwidgets/jqxgrid.sort.js"></script> <script type="text/javascript"> $(document).ready(function () { // prepare the data var data = {}; var theme = 'classic'; var source = { datatype: "json", datafields: [ { name: 'RecordID', type: 'number'}, { name: 'company_name', type: 'string'}, { name: 'no_so', type: 'string'}, { name: 'nilai_so', type: 'string'}, { name: 'pf_amount_net', type: 'string'}, { name: 'so_payment_paid', type: 'string'}, { name: 'point_after_fees', type: 'string'}, { name: 'so_payment_term', type: 'string'}, { name: 'payee_name', type: 'string'}, { name: 'payee_mobile_no', type: 'string'}, { name: 'payee_npwp', type: 'string'}, { name: 'account_no', type: 'string'}, { name: 'bank_name', type: 'string'}, { name: 'bank_address_branch', type: 'string'}, { name: 'sales_name', type: 'string'}, { name: 'application_date', type: 'string'}, { name: 'status', type: 'string'}, { name: 'kas_stats', type: 'string'} ], cache: false, id: 'RecordID', url: '../jqw/data.php', updaterow: function (rowid, rowdata, commit) { // synchronize with the server - send update command var data = "update=true&company_name=" + rowdata.company_name + "&no_so=" + rowdata.no_so; data = data + "&RecordID=" + rowdata.RecordID; $.ajax({ dataType: 'json', url: '../jqw/data.php', data: data, success: function (data, status, xhr) { // update command is executed. commit(true); }, error: function(data, status, xhr){ alert('Error loading document'); console.log(data); return false; }, }); console.log(data); } }; var dataAdapter = new $.jqx.dataAdapter(source); // initialize jqxGrid $("#jqxgrid").jqxGrid( { width: '100%', autoheight: true, sortable: true, selectionmode: 'singlecell', source: dataAdapter, theme: 'bootstrap', enabletooltips: true, editable: true, columns: [ { text: 'ID', editable: false, datafield: 'RecordID' }, { text: 'Company Name', datafield: 'company_name' }, { text: 'No SO', datafield: 'no_so' }, { text: 'Nilai SO', datafield: 'nilai_so' }, { text: 'Pf Amount Net', datafield: 'pf_amount_net' }, { text: 'SO Payment Paid', datafield: 'so_payment_paid' }, { text: 'Point After Fees', datafield: 'point_after_fees' }, { text: 'SO Payment Term', datafield: 'so_payment_term' }, { text: 'Payee Name', datafield: 'payee_name' }, { text: 'Payee Mobile No', datafield: 'payee_mobile_no' }, { text: 'Payee NPWP', datafield: 'payee_npwp' }, { text: 'Account No', datafield: 'account_no' }, { text: 'Bank Name', datafield: 'bank_name' }, { text: 'Bank Address Branch', datafield: 'bank_address_branch' }, { text: 'Sales Name', datafield: 'sales_name' }, { text: 'Application Date', datafield: 'application_date' }, { text: 'Status', datafield: 'status' }, { text: 'Kas Stats', datafield: 'kas_stats' } ] }); }); </script> <?php break; } ?> </head>
and here’s the controller (data.php) :
<?php // Include the connect.php file include ('connect.php'); // Connect to the database $mysqli = new mysqli($hostname, $username, $password, $database); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "SELECT id, company_name, no_so, nilai_so, pf_amount_net, so_payment_paid, point_after_fees, so_payment_term, payee_name, payee_mobile_no, payee_npwp, account_no, bank_name, bank_address_branch, sales_name, application_date, status, kas_stats FROM user_submissions"; if (isset($_GET['update'])) { // UPDATE COMMAND $query = "UPDATE <code>user_submissions</code> SET <code>company_name</code>=?, <code>no_so</code>=? WHERE <code>id</code>=?"; $result = $mysqli->prepare($query); $result->bind_param('sssssssi', $_GET['company_name'], $_GET['no_so'], $_GET['RecordID']); $res = $result->execute() or trigger_error($result->error, E_USER_ERROR); // printf ("Updated Record has id %d.\n", $_GET['EmployeeID']); echo $res; } else { // SELECT COMMAND $result = $mysqli->prepare($query); $result->execute(); $result->bind_result($id, $company_name, $no_so, $nilai_so, $pf_amount_net, $so_payment_paid, $point_after_fees, $so_payment_term, $payee_name, $payee_mobile_no, $payee_npwp, $account_no, $bank_name, $bank_address_branch, $sales_name, $application_date, $status, $kas_stats); // fetch values while ($result->fetch()) { $submissions[] = array( 'RecordID' => $id, 'company_name' => $company_name, 'no_so' => $no_so, 'nilai_so' => $nilai_so, 'pf_amount_net' => $pf_amount_net, 'so_payment_paid' => $so_payment_paid, 'point_after_fees' => $point_after_fees, 'so_payment_term' => $so_payment_term, 'payee_name' => $payee_name, 'payee_mobile_no' => $payee_mobile_no, 'payee_npwp' => $payee_npwp, 'account_no' => $account_no, 'bank_name' => $bank_name, 'bank_address_branch' => $bank_address_branch, 'sales_name' => $sales_name, 'application_date' => $application_date, 'status' => $status, 'kas_stats' => $kas_stats ); } echo json_encode($submissions); } /* close statement */ $result->close(); /* close connection */ $mysqli->close(); ?>
I would appreciate if someone could give some directions what may be wrong with this code, why the EDIT function doesn’t work?
Hi dujmovicv,
I suggest you to check what data comes to the PHP code and then check why the MySQL DB is not updated when it goes into the “update” part of your PHP code.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
thanks for the quick reply. I was trying to do that but I don’t get any error message from the php file : $res = $result->execute() or trigger_error($result->error, E_USER_ERROR);
How can I display errors from data.php?I managed to find out the error. It was the
$result->bind_param('ssi', $_GET['company_name'], $_GET['no_so'], $_GET['RecordID']);
statement where the parameters number didn’t match with the number of $_GET variables. THANKS for the directions!!! -
AuthorPosts
You must be logged in to reply to this topic.