jQWidgets Forums
jQuery UI Widgets › Forums › Grid › phpdemos\server_side_grid_crud
Tagged: grid add row
This topic contains 8 replies, has 3 voices, and was last updated by Peter Stoev 11 years, 1 month ago.
-
Author
-
Hi,
Found an example to show how the add row function does not work correctly.
Could someone test one of your examples with a minor modification to index.php and data.php
This change only has to do with the Add row function.data.php
if (isset($_GET['insert'])) { // INSERT COMMAND //$insert_query = "INSERT INTO employees(<code>FirstName</code>, <code>LastName</code>, <code>Title</code>, <code>Address</code>, <code>City</code>, <code>Country</code>, <code>Notes</code>) VALUES ('".$_GET['FirstName']."','".$_GET['LastName']."','".$_GET['Title']."','".$_GET['Address']."','".$_GET['City']."','".$_GET['Country']."','".$_GET['Notes']."')"; //$result = mysql_query($insert_query) or die("SQL Error 1: " . mysql_error()); $data = array(); $data[] = array( 'EmployeeID' => '12', 'FirstName' => 'Peter', 'LastName' => 'Stoev', 'Title' => 'Keymaster', 'Address' => '123 Widget Street', 'City' => 'New York', 'Country' => 'USA', 'Notes' => 'Widgets are awsome.'); mysql_close($connect); //echo $result; echo json_encode($data); }
index.php
$("#addrowbutton").bind('click', function () { //var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount; //var datarow = generaterow(rowscount + 1); $("#jqxgrid").jqxGrid('addrow', null, {}); });
By making these simple changes we should get a new row with EmployeeID 12 and the remaining data.
What is produced is a new row with EmployeeID 10 and the other cells are blank.Why is the grid not filling with the returned data.php information? If I have an error please indicate.
Thanks,
EricHi,
I think you should have 2 arrays: One array is the “rows” array, the other one is the “columns” array.
So your data.php should look like that:
if (isset($_GET['insert'])) { // INSERT COMMAND //$insert_query = "INSERT INTO employees(<code>FirstName</code>, <code>LastName</code>, <code>Title</code>, <code>Address</code>, <code>City</code>, <code>Country</code>, <code>Notes</code>) VALUES ('".$_GET['FirstName']."','".$_GET['LastName']."','".$_GET['Title']."','".$_GET['Address']."','".$_GET['City']."','".$_GET['Country']."','".$_GET['Notes']."')"; //$result = mysql_query($insert_query) or die("SQL Error 1: " . mysql_error()); $rows = array(); $cols = array( 'EmployeeID' => '12', 'FirstName' => 'Peter', 'LastName' => 'Stoev', 'Title' => 'Keymaster', 'Address' => '123 Widget Street', 'City' => 'New York', 'Country' => 'USA', 'Notes' => 'Widgets are awsome.'); array_push($rows, $cols); mysql_close($connect); //echo $result; echo json_encode($rows); }
Hi hypertyper,
Our samples are tested and they work as they should. We will consider whether to return an Array of columns in order to build dynamically columns, if we enhance the example or create a new one.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi Peter,
There is something that is performing an auto count when the add row function is called. I have remarked that part of the code out in the index.php. When I perform the add row it fills the EmployeeID with the number 10.Here is the returning data from the data.php
[{“EmployeeID”:”12″,”FirstName”:”Peter”,”LastName”:”Stoev”,”Title”:”Keymaster”,”Address”:”123 Widget Street”,”City”:”New York”,”Country”:”USA”,”Notes”:”Widgets are awsome.”}]The add row function is return the row count as a data field.
The only reason I am trying to get someone to look at this closer is because I will be using the grid for everything I plan on designing. I have done alot of testing with the grid features and have found no problems. This is the only issue, I need to have resolved in order to move forward.
Hi everyone,
I have a solution to the problem. You will need to process the ajax call before the add row function.
Sample:$("#addrowbutton").bind('click', function () { //var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount; //var datarow = generaterow(rowscount + 1); var data = "insert=true"; $.ajax({ dataType: 'json', url: 'datatest.php', data: data, cache: false, success: function (data, status, xhr) { // insert command is executed. $("#jqxgrid").jqxGrid('addrow', null, data); } }); });
Hopefully this will help with anyone trying to add a row and needs to capture a key value to pass back to the grid.
Hi EricK,
According to me, it is more correctly to call addrow and implement the synchronization in the source object’s addrow callback function. On success, call commit(true, newRowID), on fail, call commit(false).
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
Yes, I would implement that technique if it worked correctly. If you can give me an example of this working. I would use it.
I have your example which I modified to recreate the issue. How can I send it to you.Thanks,
EricHi Peter,
Last question regarding the On success.call commit(true,newRowID)
can I pass other fields or only the newRowID?
ex. commit(true,newRowID, field1, field2…)
Hi EricK,
No, and there is no reason to pass other fields, too.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.