· Apr 2, 2016

How to save changes in DataGrid


I am working on a DataGrid based upon ZenTest.Datagrid.cls

I want to save data after changes on a row.

The existing samples do not explain how to save changes on data in a grid.

I have tried something like zen(‘json’).save

Does anybody has some sample code?

Discussion (4)1
Log in or sign up to continue

Here's a simple example that'll run in the Samples namespace. It demonstrates saving all the data at the same time and saving it one row at a time after each cell is edited.

Class App.Sample.DataGridPage Extends

/// This Style block contains page-specific CSS style definitions.
XData Style
<style type="text/css">
#dataGrid {
    width: 100%;
    height: 500px;

/// This XML block defines the contents of this page.
XData Contents [ XMLNamespace = "" ]
<page xmlns="" title="dataGrid save sample">
<jsonSQLProvider id="json" OnSubmitContent="SubmitContent"
  targetClass="%ZEN.proxyObject" sql="select ID,Name,DOB,SSN from sample.person order by name" />
 <dataGrid pageSize="20" id="dataGrid" pagingMode="client" controllerId="json" sortMode="client"
  selectMode="cells" onchangecell="return zenPage.fireChangeCell(value);" onchange="zenPage.gridChanged();">
 <columnDescriptor caption="ID" type="string" readOnly="false"/>
 <columnDescriptor caption="Name" type="string" readOnly="false"/>
 <columnDescriptor caption="DOB" type="string" readOnly="false"/>
 <columnDescriptor caption="SSN" type="string" readOnly="false"/>
 <hgroup labelPosition="left" cellAlign="even">
 <radioSet id="modeRadio" valueList="edit,manual" displayList="After Each Edit,Manually"
  label="Save Data: " value="edit" />
 <button onclick="zen('json').submitContent()" caption="Save Everything" />

ClientMethod fireChangeCell(value) [ Language = javascript ]
    // Capture the number of the last row that was changed.
    zenPage._lastChangedRow = zen('dataGrid').getProperty('currRow');
    return value;

ClientMethod gridChanged() [ Language = javascript ]
    if (zen('modeRadio').getValue() == 'edit') {

Method SubmitContent(pCommand As %String,
pProvider As %ZEN.Auxiliary.jsonProvider,
pSubmitObject As %ZEN.proxyObject,
ByRef pResponseObject As %RegisteredObject) As %Status
    Set tSC = $$$OK
    Try {
        If (pCommand = "") {
            //Save everything.
            For {
                Set tProxy = pSubmitObject.children.GetNext(.tKey)
        } Else {
            Set tCommandInfo = $ListFromString(pCommand,":")
            If ($lg(tCommandInfo,1) = "saveRow") {
                //Save only the specified row (faster)
                Set tData = pSubmitObject.children.GetAt($lg(tCommandInfo,2))
                If $IsObject(tData) {
                    Set tObj = ##class(Sample.Person).%OpenId(tData.ID,,.tSC)
                    Set tObj.Name = tData.Name
                    Set tObj.SSN = tData.SSN
                    Set tObj.DOB = $zdh(tData.DOB)
                } Else {
                    $$$ThrowStatus($$$ERROR($$$GeneralError,"An error occurred saving row "_$lg(tCommandInfo,2)))
    } Catch anyException {
        Set tSC = anyException.AsStatus()
    Quit tSC

Method SavePersonProxy(pProxy As %ZEN.proxyObject) As %Status
    Set tObj = ##class(Sample.Person).%OpenId(pProxy.ID,,.tSC)
    Quit:$$$ISERR(tSC) tSC
    Set tObj.Name = pProxy.Name
    Set tObj.SSN = pProxy.SSN
    Set tObj.DOB = $zdh(pProxy.DOB)
    Quit tObj.%Save()


I think you're probably looking for the maxRows attribute of jsonSQLProvider, which defaults to 100 (hence 5 pages with page size 20, in the example) - try something like:

 <jsonSQLProvider id="json" OnSubmitContent="SubmitContent"
  targetClass="%ZEN.proxyObjectsql="select ID,Name,DOB,SSN from sample.person order by name" maxRows="1000" />