Search code examples
javascriptjsonrestxpagesdojox.grid.datagrid

How to add a read/write customRestService to support editing in Dojo DataGrid?


I am trying to develop a Dojo DataGrid that returns a user's documents from the categorized BidsByDriver view and allows them to edit the Priority field in the grid. After getting past the hurdle of using the keys property to filter over the categoryFilter, this was easy to set up using an xe:viewFileItemService read/write service. However the problem with xe:viewFileItemService as a data source is it will display empty lines for each entry in the view after showing the user's documents in the grid.

enter image description here

To get around the blank lines I went down the path of creating an xe:customRestService that returned the jasonData for just the current user's documents. This fixes my blank lines problem but my data source is not in the correct read/write format to support the in-grid editing.

Here is the resulting Json data returned form the xe:customRestService ...

[{"Driver":"ddd","BidID":"123","Priority":"1","Trip":"644"},
 {"Driver":"ddd","BidID":"123","Priority":"2","Trip":"444"},
 {"Driver":"ddd","BidID":"123","Priority":"4","Trip":"344"},
 {"Driver":"ddd","BidID":"123","Priority":"4","Trip":"643"}
]

Here are the Dojo modules I am loading:

<xp:this.resources>
    <xp:dojoModule name="dojo.store.JsonRest"></xp:dojoModule>
    <xp:dojoModule name="dojo.data.ObjectStore"></xp:dojoModule>
</xp:this.resources>

And here is the script to develop the data store for the grid:

<xp:scriptBlock id="scriptBlock2">
      <xp:this.value><![CDATA[
    var jsonStore = new dojo.store.JsonRest({target: "InGridCustom.xsp/pathinfo"});  
    var dataStore = dojo.data.ObjectStore({objectStore: jsonStore});
  ]]></xp:this.value>
</xp:scriptBlock>

All of this works very nicely except for the bit on providing the in-grid editing support. Any ideas appreciated.


Solution

  • How are you trying to save the changes? With a custom REST service, I would not expect that saving the data store would make any changes to the back-end data, which is why a refresh would revert it to the original value.

    I would expect that you'd need to write a doPost method in your custom REST service to process the change on the server side, along with client-side code to call the post method and pass in the updates to process (along with the document ID).