It’s possible to save data in virtual column to database.To save data in virtual column or calculated column back to database, you can use jqGridAddEditAfterSubmit event (FORM edit only) to post data to another script through a separate Ajax call. The catch is you need to supply your own save data script. Just iterate the $_POST variables and call appropriate functions to save posted data to database. Should be fairly simple to do.
Below is the code snippet. Replace “orders” with your own table name please. You need to implement save_virtual_column.php to save virtual column data to another page after submit through another Ajax call
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | $afterSubmit = <<<AFTERSUBMIT function (event, status, postData) { selRowId = $("#orders").jqGrid ('getGridParam', 'selrow'); virtual_data1 = $("#orders").jqGrid("getCell", selRowId, 'total'); // data in virtual column virtual_data2 = $("#orders").jqGrid("getCell", selRowId, 'foo'); console.log('going to post virtual column data ' + virtual_data1 + ', ' + virtual_data2 + ' to another page through a separate AJAX call'); $.ajax({ url: 'save_virtual_column.php', data: {v_data1: virtual_data1, v_data2: virtual_data2}, // replace customerNumber with your own field name type: 'post', success: function(output) { alert(output); } }); } AFTERSUBMIT; $dg->add_event("jqGridAddEditAfterSubmit", $afterSubmit); |
The screenshot illustrates values in virtual columns named “total” and “foo” are saved after users submit form. It posts to a file named “save_virtual_column.php” with posted form data v_data1, v_data2.
This is also a good technique to save any other additional data to database because it does not require modifying edit.php. Note that jqGridAddEditAfterSubmit works only in FORM edit mode.