jQuery UI Widgets › Forums › Grid › Grid Commit to Database
Tagged: commit, database, DB, filter, filtered, getrows, grid, jqxgrid, row, server, synchronize, updaterow
This topic contains 4 replies, has 2 voices, and was last updated by Dimitar 10 years, 1 month ago.
-
AuthorGrid Commit to Database Posts
-
Hi Team,
Need help on best method to commit all rows visible/ filterd to Database.
Currently I’m editing each cell in loop to call the updaterow function.
But facing inconsistency in data commit to database.
Using 3.2.2 jqwidgets.
below is the code causing issue. Some rows are not getting committed with provided “doc seq no” value 2 and “RSP_APPROVED_IND” ‘Y’
$("#updaterowbutton").bind('click', function () { var rows = 0; rows = $('#jqxgrid2').jqxGrid('getrows'); var result = ""; var zeroRSPcnt=0; var zeroCstcnt=0; for(var i = 0; i < rows.length; i++) { var row = rows[i]; result+=row.FinalRSP+"\n"; if(row.FinalRSP==0) { zeroRSPcnt++; } if(row.EstTerrLndCst==0) { zeroCstcnt++; } } if (zeroCstcnt>0 ||zeroRSPcnt>0 ) { if(zeroCstcnt>0) { alert("There are one or more items where Estimated Landed Cost is zero.\n Please contact IT dept for the same."); } else { alert("There are one or more items where Final RSP is zero.\n Please Enter a valid RSP(s) to approve CPS"); } } else { var nextApprSeqNo=0; $("#jqxgrid2").jqxGrid('selectrow', 0); for(var i = 0; i <rows.length; i++) { //alert("Row number :"+i); $("#jqxgrid2").jqxGrid('begincelledit', i, "RSPAppInd"); $("#jqxgrid2").jqxGrid('setcellvalue', i, "RSPAppInd", 'Y'); $("#jqxgrid2").jqxGrid('endcelledit', i, "RSPAppInd", true); //$("#jqxgrid2").jqxGrid('ensurerowvisible', i); $("#jqxgrid2").jqxGrid('begincelledit', i, "DocCurrSqNo"); $("#jqxgrid2").jqxGrid('setcellvalue', i, "DocCurrSqNo",2); $("#jqxgrid2").jqxGrid('endcelledit', i, "DocCurrSqNo",true); //$("#jqxgrid2").jqxGrid('ensurerowvisible', i); } alert("Prices Approved"); } });
My update code.
updaterow: function (rowid, rowdata, commit) { // synchronize with the server - send update command var data = "update=true&" + $.param(rowdata); //alert(data); $.ajax({ url: 'data.php', //cache: false, data: data, success: function (data, status, xhr) { // update command is executed. commit(true); }, error: function(jqXHR, textStatus, errorThrown) { alert(JSON.stringify(errorThrown, null, 3)); commit(false); } }); }
Hi any help..?
Hello dippy,
You do not have to iterate through all cells. You can get all (filtered) rows with the getrows method and commit them to the database with a single Ajax call (not in the automatically-called updaterow, but in your click handler). The forum topic Save all updates on Grid with one Save button may also be helpful to you.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Dear Dimitar,
Thanks for the help. I saw the example illustrated in http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/editrowsrendering.htm?arctic
However the example shows commiting only in case of editing cells.
What I need is a updaterow automatic which will say data to the database as well as on button click “approved”.
While button click I want to want some additional values in the database against each row like a “Apporved flag” in the database table which I am doing in the iteration (above example). This I am doing thru updating/editing a hidden field in the grid. Which is calling the updaterow method again
Can you pls post an example for the something related to same.
regards
Hi dippy,
Here is a suggestion: when you update through the button, set a flag variable to false. In updaterow check for the flag and if it is false, do nothing. When the manual update has finished, set the flag to true, so that automatic updates are now allowed.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.