【发布时间】:2013-11-18 19:17:18
【问题描述】:
我有一个使用具有可编辑列的 Dojo 网格的 REST 服务。我可以双击单元格并更改值,但是,当我尝试保存更改时——使用按钮中的 REST 服务 save() 方法——更改不会保存。
我可以保存此值的唯一方法是首先在 REST 服务上调用 revert() 方法——单击按钮中的 REST 服务 revert() 方法——然后更改我需要的任何可编辑单元格并单击“保存”按钮。
代码如下:
<xe:restService id="rsVictims" pathInfo="gridDataVictims">
<xe:this.service>
<xe:viewItemFileService defaultColumns="true"
viewName="InvoiceMPRVictims" contentType="application/json">
<xe:this.keys><![CDATA[#{javascript:viewScope.get("mprKeysValue");}]]></xe:this.keys>
<xe:this.databaseName><![CDATA[#{javascript:applicationScope.get("appConfig").keywords.appDataStore.join("!!")}]]></xe:this.databaseName>
</xe:viewItemFileService>
</xe:this.service>
</xe:restService>
<xp:button value="Save Changes" id="button1">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[// Save the changes...
rsVictims.save();]]></xp:this.script>
</xp:eventHandler>
</xp:button>
<xp:button value="Cancel Changes" id="button2">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[rsVictims.revert();]]></xp:this.script>
</xp:eventHandler>
</xp:button>
<xe:djxDataGrid id="djxDataGrid1" storeComponentId="rsVictims"
autoHeight="90">
<xe:djxDataGridColumn id="djxDataGridColumn1"
label="Target" width="35px" field="victimTarget">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn2" label="Oct"
width="35px" field="month_10" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn3"
label="Nov" width="35px" field="month_11" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn4"
label="Dec" width="35px" field="month_12" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn5"
label="Jan" width="35px" field="month_1" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn6"
label="Feb" width="35px" field="month_2" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn7"
label="Mar" width="35px" field="month_3" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn8"
label="Apr" width="35px" field="month_4" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn9"
label="May" width="35px" field="month_5" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn10"
label="June" width="35px" field="month_6" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn11"
label="July" width="35px" field="month_7" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn12"
label="Aug" width="35px" field="month_8" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn15"
label="Sept" width="35px" field="month_9" editable="true">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn13"
label="Total" width="45px" field="victimTotal">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn14"
width="200px" label="Description" field="$Desc">
</xe:djxDataGridColumn>
</xe:djxDataGrid>
我阅读了 Brad Balassastis 的优秀教程: http://xcellerant.net/2013/04/25/dojo-data-grid-11-editiable-columns/
任何帮助都会很棒——谢谢!
编辑/附加信息:
我们有一个 REST 服务和 Dojo DataGrid,它不会在初始加载时保存对可编辑列的更改——这意味着 XPage 加载并进行了更改。保存更改的唯一方法是在调用 REST 服务的 close() 或 revert() 方法之后,然后调用 save() 方法。 REST 服务指向同一服务器上的另一个数据库,并使用 keys 属性:
<xe:restService id="rsVictims" pathInfo="rsVictimsData">
<xe:this.service>
<xe:viewItemFileService defaultColumns="true"
viewName="InvoiceGridVictims" contentType="application/json"
databaseName="voca\vocadatastore.nsf" keys="k28ts71zrjsw">
</xe:viewItemFileService>
</xe:this.service>
</xe:restService>
这是数据网格:
<xe:djxDataGrid id="djxDataGrid1" storeComponentId="rsVictims"
autoHeight="90">
<xe:djxDataGridColumn id="djxDataGridColumn1"
label="Target" width="35px" field="victimTarget">
</xe:djxDataGridColumn>
<xe:djxDataGridColumn id="djxDataGridColumn2"
label="Oct" width="35px" field="month_10" editable="true">
</xe:djxDataGridColumn>
</xe:djxDataGrid>
它是这样流动的:
使用 REST 服务和 DataGrid 打开 XPage
更改可编辑列 单击调用此代码的保存按钮(代码复制自Brad Balassaitis' demo,06 自定义控件): <xp:button value="Save Changes" id="victimsSaveButton">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[// Save the changes...
editedRows = [-1];
var args = {onError: function() {alert('error!');}};
rsVictims.save(args);
//Refresh the grid
rsVictims.close();
dijit.byId('#{id:djxDataGrid1}')._refresh();]]></xp:this.script>
</xp:eventHandler>
</xp:button>
DataGrid 已关闭、刷新,但未保存更改
再次进行更改,然后单击保存按钮 DataGrid 已关闭、刷新,现在保存更改我注意到,当 XPage 打开时,DataGrid 被加载了两次——我看到这是 Net 选项卡中的 Firebug。在第一次 GET 中,它正确检索了网格——响应正确,JSON 格式正确,start=0,count=25。
在第二次 GET 中,似乎丢失了网格——响应为空,JSON 项为空,start=25,count=25。我尝试将 REST 服务中的 start 属性设置为 0,但这并没有做任何事情。我也尝试将 count 属性设置为 500,但这也不能解决问题。
关于这一点的有趣事实是,当视图在当前数据库中移动时——因此不使用 REST 服务上的 databaseName 属性——保存按钮可以正常工作。此外,加载 DataGrid 时只有一个 GET,而不是指向同一服务器上另一个数据库中的视图时的两个 GET。我知道在查看另一台服务器时会出现一些问题,但这些数据库位于同一台服务器上。
提前致谢!
【问题讨论】:
-
您的网站是否允许 HTTP PUT?
-
@Per Henrik Lausten -- 我在哪里检查这个?我知道我在某处读到了需要为应用程序/数据库创建的 Web Config 文档。谢谢!
-
Per 是对的,除非你这样做,否则你将一事无成。如果您计划允许用户也删除条目,您可能也需要 DELETE。
-
@Per -- 只是对原始帖子的快速重定向 -- save() 方法可以在没有 Web Config 文档的情况下工作,我只需要先调用 revert() 方法。我可以调用 revert() 一次,然后根据需要执行尽可能多的保存。这是否敲响了警钟——只是对为什么在首先调用 revert() 后它会起作用感到困惑——似乎 REST 服务或 dojo 网格在调用 revert 之前并不“存在”。我在 Firebug 中也看不到任何东西...非常感谢您的回复...
标签: javascript rest xpages dojox.grid.datagrid