We are using a grid at the bottom of an order form as an input screen for the products ordered. We want all the rows to be sent to the database together and have set up the dataprocessor as such. However, when we click on the submit button, only the first row is saved. The remaining rows stay updated (bold) and generate an error. They do not save.
Please review and advise accordingly.
Code for grid setup:
var mygrid = new dhtmlXGridObject(blForm.getContainer(“productgrid”));
mygrid.setImagePath(“…/…/dhtmlxSuite/dhtmlxGrid/codebase/imgs/”);
mygrid.setHeader(“ID,BL#,Qty,Item,Lot#,Unit,Haz,Product Description,Weight”);
mygrid.setColumnIds(“id,BL_num,Qty,Item,Lot_num,Unit,Haz,ProductDescription,Weight”)
mygrid.setInitWidths(“50,75,75,100,100,100,50,*,100”);
mygrid.setColAlign(“left,left,left,left,left,left,center,left,left”);
mygrid.setColTypes(“ro,ed,ed,ed,ed,ed,ed,ed,ed”);
mygrid.init();
mygrid.setSkin(“dhx_skyblue”);
for (var i=0;i<10;i++){
mygrid.addRow(i,"");
}
Code for grid dataprocessor setup:
var mydpgrid = new dataProcessor(‘php/bl_addgridDetail.php’);
mydpgrid.setTransactionMode(“POST”,true);
mydpgrid.setUpdateMode(“off”);
mydpgrid.enableDataNames(true);
mydpgrid.init(mygrid);
Code to create unique ids for rows and then to send rows to database:
var submitButton = new dhtmlXForm(“footer”,formDatafooter);
submitButton.attachEvent(“onButtonClick”,function(id){
if(id==“submit_bttn”){
blForm.resetDataProcessor(“insert”);
blForm.save();
for (var rowId=0; rowId<mygrid.getRowsNum(); rowId++){
if(mygrid.cells(rowId,1).getValue() !==""){
var new_Id=(new Date()).valueOf();
mygrid.cells(rowId,0).setValue(new_Id);
mydpgrid.setUpdated(rowId,true,"inserted");
}
}
mydpgrid.sendData(); //send all "updated" rows at one time
window.close();
}
});
Finally, here is a copy of the screen:
Thank you in advance.