jQWidgets Forums
jQuery UI Widgets › Forums › Grid › ADD NEW to grid
This topic contains 3 replies, has 3 voices, and was last updated by Peter Stoev 10 years, 7 months ago.
-
AuthorADD NEW to grid Posts
-
for addnew it inserts a new empty row which I can edit but I don’t see the customerid field and hence the edit doesnot sync with the database
here is my code
addrow: function (rowid, rowdata, position, commit) {
var datasent = “insert=true&” + $.param(rowdata);
$.ajax({
dataType: ‘json’,
url: ‘test_data.php’,
data: datasent
});
commit(true);
},the call is as below –
$(“#addrowbutton”).on(‘click’, function (event) {
// add new empty row.
var datarow = { CompanyName: ‘Enter Company Name’, ContactName: ‘Enter Contact Name’,ContactTitle:’Enter Contact Title’};
var res = $(“#jqxgrid”).jqxGrid(‘addrow’, null, datarow);
});the php file –
else if (isset($_GET[‘insert’]))
{
// INSERT COMMAND
$insert_query = “INSERT INTO Customers (CompanyName,ContactName,ContactTitle) VALUES (‘”.$_GET[‘CompanyName’].”‘,'”.$_GET[‘ContactName’].”‘,'”.$_GET[‘ContactTitle’].”‘);SELECT @@identity AS id”;
$result = sqlsrv_query($connect, $insert_query) or die(“SQL Error 1: ” . sqlsrv_errors());
sqlsrv_next_result($result);
sqlsrv_fetch($result);
$custid=sqlsrv_get_field($result, 0);
$data[] = array(
‘CustomerID’ => $custid,
‘Success’=>True
);
echo json_encode($data);
}the row gets added to the database but on commit I don’t see the customerid populated means the grid doesn’t show the id
refreshing the page I can see itcan I redraw the page after every insert?? please help
Hello hk,
Do you mean you do not see the customerid field in the database? Or do you have such a column in your grid and the cell of the new row in this column is blank? You may try calling updatebounddata after adding the row, but usually this is not necessary.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/manually refreshing the page or using updatebounddata to refresh the page shows the customerid but I was expecting it to show right after it got added.
This is my addrow logic
addrow: function (rowid, rowdata, position, commit) {
var datasent = “insert=true&” + $.param(rowdata);
$.ajax({
dataType: ‘json’,
url: ‘test_data.php’,
data: datasent
});
commit(true,’data’);data returns uid=3 where 3 is the index and not the actual customer id
This is what calls the addrow –
$(“#addrowbutton”).on(‘click’, function (event) {
// add new empty row.
var datarow = { CompanyName: ‘Enter Company Name’, ContactName: ‘Enter Contact Name’,ContactTitle:’Enter Contact Title’};
$(“#jqxgrid”).jqxGrid(‘addrow’, null, datarow);
$(‘#jqxgrid’).jqxGrid(‘updatebounddata’);
});
},if I don’t use $(‘#jqxgrid’).jqxGrid(‘updatebounddata’); the database gets updated but commit does not repaint the customerid field all other fields are good, even if I edit the field it returns uid=the index number and not customerid=
the php logic is as below
if (isset($_GET[‘insert’]))
{
// INSERT COMMAND
$insert_query = “INSERT INTO Customers (CompanyName,ContactName,ContactTitle) VALUES (‘”.$_GET[‘CompanyName’].”‘,'”.$_GET[‘ContactName’].”‘,'”.$_GET[‘ContactTitle’].”‘);SELECT @@identity AS id”;
$result = sqlsrv_query($connect, $insert_query) or die(“SQL Error 1: ” . sqlsrv_errors());
sqlsrv_next_result($result);
sqlsrv_fetch($result);
$custid=sqlsrv_get_field($result, 0);
$data[] = array(
‘CustomerID’ => $custid,
‘Success’=>True
);
echo json_encode($data);
}and I see the custid on this page
thanks
Hi hk,
It seems that you missed what we wrote you in another post which you posted recently: http://www.jqwidgets.com/community/topic/delete-database-customerid/
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.