4

I have following code where in I want to display data from a Rest Doc Service into Dojo Data Grid. Output of Rest service is fine but Datagrid siplay displays the column titles and nothing else. Here is my code:

<xp:panel>
        <xe:restService id="restService1" pathInfo="docAccReq1"
            rendered="true" state="true">
            <xe:this.service>
                <xe:documentJsonService
                    contentType="application/json" systemItems="63" var="docAcc"
                    documentUnid="80EFAE936EA978A480257CE4002DBC67">
                    <xe:this.items>
                        <xe:restDocumentItem itemName="Name"
                            name="Name">
                        </xe:restDocumentItem>
                        <xe:restDocumentItem
                            itemName="ACCESSREQUESTER" name="ACCESSREQUESTER">
                        </xe:restDocumentItem>
                        <xe:restDocumentItem
                            itemName="ACCESSREQUESTEDDATE" name="ACCESSREQUESTEDDATE">
                        </xe:restDocumentItem>
                    </xe:this.items>
                </xe:documentJsonService>
            </xe:this.service>
        </xe:restService>

        <xe:djxDataGrid id="djxDataGrid1"
            storeComponentId="restService1" store="docStore">
            <xe:this.dojoAttributes>
                <xp:dojoAttribute name="autoWidth" value="true"></xp:dojoAttribute>
            </xe:this.dojoAttributes>
            <xe:djxDataGridColumn id="djxDataGridColumn1"
                field="Name">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn2"
                field="ACCESSREQUESTER">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn3"
                field="ACCESSREQUESTEDDATE">
            </xe:djxDataGridColumn>
        </xe:djxDataGrid>

        <xe:firebugLite id="firebugLite1"></xe:firebugLite>
</xp:panel>
<xp:panel>
    <xc:ccDebugToolbar defaultCollapsed="true"
        collapseTo="left"></xc:ccDebugToolbar>
</xp:panel>

Lothar Mueller
  • 2,528
  • 1
  • 16
  • 29
Arun
  • 229
  • 3
  • 14
  • here is the output of rest service:{"@unid":"80EFAE936EA978A480257CE4002DBC67","@noteid":"12C7A","@created":{"data":"2014-05-26T08:19:33Z","type":"datetime"},"@modified":{"data":"2014-05-26T11:13:39Z","type":"datetime"},"@authors":["CN=Arun Agnihotri\/O=XYZ"],"Name":"Arun","ACCESSREQUESTER":"Arun Agnihotri","ACCESSREQUESTEDDATE":{"data":"2014-05-26T08:19:31Z","type":"datetime"}} – Arun May 28 '14 at 12:28
  • 2
    Shouldn't you use "viewJsonService" instead to get documents from a view and not just one certain document? – Knut Herrmann May 28 '14 at 12:31

1 Answers1

3

The REST service should deliver a data array. This is what xe:djxDataGrid expects as it is a data grid control which shows data in multiple rows in a table.

The common way is to use the REST service viewJsonService. Define all columns you want to see in data grid in a view. You connect the view to REST service with parameter "viewName" and with defaultColumns="true" you make sure that all columns get delivered.

Your REST service definition would look like this then:

<xe:restService
    id="restService1"
    pathInfo="docAccReq1">
    <xe:this.service>
        <xe:viewJsonService
            viewName="AccessRequests"
            defaultColumns="true" />
    </xe:this.service>
</xe:restService>

The REST service delivers JSON data as an array:

[
  {
      "@entryid":"1-80EFAE936EA978A480257CE4002DBC67",
      "@unid":"80EFAE936EA978A480257CE4002DBC67",
      "@noteid":"12C7A",
      "@position":"1",
      "@read":true,
      "@siblings":200,
      "@form":"access",
      "Name":"Arun",
      "ACCESSREQUESTER":"Arun Agnihotri",
      "ACCESSREQUESTEDDATE":"2014-05-26T08:19:31Z"
  },
  {
      ...
  },
  ...
] 

The values "@position" and "@siblings" are important for Dojo Data Grid. They tell how many entries are in view and which position is the current data entry on. This allows to show a right sized vertical scroll bar at the right vertical position.

The Rest service documentJsonService you used delivers only one single JSON object (not an array) and doesn't provide those additional information.

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67