dhtmlxGrid can be used as a part of an HTML form, so that the grid's data could be sent to the server as a part of form submitting. It can be used to save changes in the grid, if you don't want to use the dataprocessor library.
To use the grid as a part of an HTML form, do the following:
<!DOCTYPE html>
<html>
<head>
<link rel="STYLESHEET" type="text/css" href="../codebase/dhtmlx.css">
<script src="../codebase/dhtmlx.js"></script>
</head>
<body>
<form action="php/form.php" method="post" target="result"> <table width="600">
<tr>
<td>
<div id="gridbox" style="width:100%; height:270px;"></div> </td>
</tr>
</table>
<input type="submit">
</form>
<script> //here you will place your JavaScript code
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="STYLESHEET" type="text/css" href="../codebase/dhtmlx.css">
<script src="../codebase/dhtmlx.js"></script>
</head>
<body>
<form action="php/form.php" method="post" target="result"> <table width="600">
<tr>
<td>
<div id="gridbox" style="width:100%; height:270px;"></div> </td>
</tr>
</table>
<input type="submit">
</form>
<script> mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("./codebase/imgs/");
mygrid.setHeader("Book title,Author,Price");
mygrid.init();
</script>
</body>
</html>
Related sample: FORM integration
Note,
grid.cells(i,j).cell.wasChanged=true;
dhtmlxGrid can work in the following modes:
This is the default mode. In this mode the grid will include only the data of the changed rows in the process of form submitting.
For each changed row a virtual input field will be added - [GRIDID][ROWID][CELLINDEX]
where
The value of the field is equal to the cell value.
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("./codebase/imgs/");
mygrid.setHeader("Book title,Author,Price");
mygrid.init();
mygrid.addRow("row1",["The Rainmaker", "John Grisham", "7.99"]);
For example, if the user changes the price of the added book from 7.99 to 10.99 and submits the form, you will get an input with the following name:
gridbox_row1_3=“10.99”
Sending the information about the added/deleted rows is enabled by default. To disable it use the submitAddedRows method:
mygrid.submitAddedRows(false);
To include into submitting all rows (changed and unchanged), call the submitOnlyChanged method with the 'false' value:
mygrid.submitOnlyChanged(false);
In this mode a virtual input field will be created for each cell in the grid.
In this mode the grid will create a single virtual field: [GRIDID]_SELECTED. This field will contain the list of rows' IDs that are selected (in the single select mode it will be a single ID). The mode can be enabled by:
To enable the mode, use the submitOnlySelected method:
mygrid.submitOnlySelected(true)
mygrid.submitOnlyRowID(true);
This mode works almost in the same way as the default one. It will send only the updated values of the selected rows:
mygrid.submitOnlySelected(true);
mygrid.submitOnlyRowID(false);
If you are sending form's values not by some submit button, but by the direct form.submit() call, the grid won't add its data automatically. To correct this call the parentFormOnSubmit() method before sending form's values to the server:
mygrid.parentFormOnSubmit();
form.submit();
Back to top