我有一个REST服务,它使用具有可编辑列的Dojo网格。我可以双击单元格并更改值,但是,当我尝试保存更改时——使用按钮中的REST Service 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="vocavocadatastore.nsf" keys="k28ts71zrjsw">
</xe:viewItemFileService>
</xe:this.service>
</xe:restService>
这是DataGrid:
<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的演示,06 Custom Control): <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中,它正确地检索了网格——Response是正确的,JSON格式是正确的——start=0,count=25。
在第二个GET中,它似乎丢失了网格——Response为空,JSON项为空,start=25,count=25。我曾尝试将REST服务中的start属性设置为0,但这没有任何作用。我也尝试过将count属性设置为500,但这也不能解决问题。
有趣的是,当视图在当前数据库中移动时——因此没有使用REST服务上的databaseName属性——Save按钮可以完美地工作。此外,在加载DataGrid时只有一个GET,而在指向同一服务器上另一个数据库中的视图时没有两个GET。我知道在查找另一台服务器时会出现一些问题,但这些数据库位于同一台服务器上。
提前感谢!
Dan,
在我目前的项目中,我的情况几乎完全相同。我的工作很完美,所以我想我可以帮上忙。我想你已经接受了Per Lausten的建议。如果你不这样做,你就根本无法储蓄。
您的代码和我的代码的区别在于,我使用的是xe:viewJSONService,而不是xe:viewFileItemService。扩展库的书中说,如果你想让viewFileItem更新,你必须使用它,但这不是真的。
我在viewItemFileService上遇到了麻烦,请参阅这篇博客文章了解我遇到的问题(http://notesspeak.blogspot.com/2013/07/going-with-extjs-grid-and-giving-up-on.html)我几乎完全放弃了dojo网格,但又回到了它,因为它可以在移动设备上工作。
使用viewJSONService就可以了。使用类别过滤器而不是keys属性。对于您的类别有类似于此的代码:
var category:String = lineItemBean.getThisUNID();
if(category == null){
return "show nothing"
} else {
return lineItemBean.getThisUNID();
}
//prevents all records from being returned
您需要小心,因为如果类别为null,则会返回所有记录,这可能是一个大问题或安全漏洞。在我的示例中,我从bean中提取,但您也可以在其中放置文档引用。