Question
· Jul 25, 2016

Using altJSONProvider in ZEN application

Hi,

I want to create a table with a dynamic display of data using the DataGrid.

On the page there  dataCombo and the table.

According to the plan, when the user selects an item in dataCombo the table is filled with data. If select another item - data is updated.

But in fact, the data in the table are loaded once when the page is loaded, and when I select value in DataCombo, I receive an error:

I would be happy if you tell me how to fix it.

Thank you.

XData Contents [ XMLNamespace = "http://www.intersystems.com/zen]
{
<page xmlns="http://www.intersystems.com/zentitle="Test">
<dataController id ="source" modelClass="Community.Model/>
<altJSONProvider id="jsonProvider" OnGetArray="SrvGetData" />
<form id ="myForm" controllerId="source">
<dataCombo id="Item" sql="select Item from Community.Model" onchange="zenPage.updateTable();"/>
<dataGrid
id="dGrid"
controllerId="jsonProvider"
selectMode="cells"
hasFormulas="false"
gridTitle="myTable"
multiSelect="false"
hidden="false" >
<columnDescriptor caption="Column1" />
<columnDescriptor caption="Column2" />
<columnDescriptor caption="Column3" />
<columnDescriptor caption="Column4" />
</dataGrid>
</form>
</page>
}

Method SrvGetData(ByRef pParameters, Output pMetaData, Output pData) As %Status [ ZenMethod ]
{

Set pMetaData = $LB("Column1","Column2","Column3","Column4")
set item = ..%GetComponentById("Item").value

set ^a.test = item
if item = 1 set var1 = "one"
else 
if item = 2 set var1 = "two"
else 
if item = 3 set var1 = "three"
else 
if item = 4 set var1 = "four"
else 
if item = "" set var1 = "nothing"

Set pData(1) = $LB(var1,var1,var1,var1)
Set pData(2) = $LB(var1,var1,var1,var1)
Set pData(3) = $LB(var1,var1,var1,var1)
Set pData(4) = $LB(var1,var1,var1,var1)
Set pData(5) = $LB(var1,var1,var1,var1)
Set pData(6) = $LB(var1,var1,var1,var1)

Quit $$$OK
}

ClientMethod updateTable() [ Language = javascript ]
{
var provider zenPage.getComponentById("jsonProvider");
provider.reloadContents();
}

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