Adding new grid row with a form

This should be easy, but I’m having trouble finding the answer. I have a grid with grid1.load("contactsCategory.php", function(){ grid1.loadOrderFromCookie();});
A DataProcessor with var dp1 = new dataProcessor("contactsCategory.php"); dp1.init(grid1); dp1.sendData();
And a form with form1a.bind(grid1); form1a.attachEvent("onButtonClick", function(id){ if(id=="submit"){form1a.save(); dhxLayout.dhxWins.window("addContacts").hide();} else if(id=="cancel"){ form1a.clear(); dhxLayout.dhxWins.window("addContacts").hide() ;} });
But when I click submit, I get a javascript error from dhtmlxgrid.js, line 189 “d is null”. The debugger log has: Initiating data sending for all rows
row [object Object] marked [updated,valid]
Initiating data sending for [object Object]
Error! row with such ID not exists [object Object]
Initiating data sending for all rows

I tried adding grid1.addRow(); before form1a.save();, but that didn’t help. Any ideas?

Any ideas at all? Where would you start troubleshooting an error like this?

When calling form.save(), form will try to push data back to master grid, but if you have not selected row in grid previous, it will fail - as it is not linked to any row in grid and can’t push data.

Form binding is a good way for editing data, but if you want to add new row you need to

  • add new row
  • select it ( can be done programmatically )

After that form will show data of the newly created row, and calling form.save() will correctly update it in grid and will send data to the server side.

Thanks for getting back to me Stanislav. That was exactly the bit of information I needed. :stuck_out_tongue:

That seems to have introduced a new problem. Now the dhx.Layout.dhxWins.window().hide(); function isn’t working. I have:

[code]var popupWindow1a = dhxLayout.dhxWins.createWindow(“addContacts”,50,50, 735, 670);
dhxLayout.dhxWins.window(“addContacts”).centerOnScreen();
dhxLayout.dhxWins.window(“addContacts”).setText(“Add Contact”);
dhxLayout.dhxWins.window(“addContacts”).button(“park”).hide();
dhxLayout.dhxWins.window(“addContacts”).button(“minmax1”).hide();

				 form1a = dhxLayout.dhxWins.window("addContacts").attachForm();
					form1a.loadStruct("addContact.json", "json",function(){
						form1a.setFocusOnFirstActive();
					});
					
					form1a.bind(grid1);	
						var new_id=grid1.uid()
						grid1.addRow(new_id,"",0);
						grid1.selectRow(0);
				form1a.attachEvent("onButtonClick", function(id){
						if(id=="submit"){
							form1a.save();
							dhxLayout.dhxWins.window("addContacts").hide();}
						else if(id=="cancel"){
							form1a.clear();
							dhxLayout.dhxWins.window("addContacts").hide()
							;}
					});[/code]

The form adds data to the grid, but then won’t go away unless you click “cancel” or the window “close” button. How can I make this work?

Hi

please provide direct link or completed demo including all corresponding js/css files