如何使用TooltipDialog(和DropDownButton)更新Dojo网格单元格值
问题描述:
我有一个使用某些可编辑的dijit表单字段的dojo网格。一切都很好,直到我尝试执行一个国家(多)选择单元格作为工具提示对话框;即显示下拉按钮,其打开填充有复选框阵列的工具提示对话框以选择一个或多个国家。一旦选中并单击确定,单元格应该更新为所选国家/地区列表。很显然,我会照顾稍后通过商店更新服务器。如何使用TooltipDialog(和DropDownButton)更新Dojo网格单元格值
我已经实现了一个国家选择工具提示对话框,像这样工作正常:
dojo.provide("CountrySelector");
dojo.declare(
"CountrySelector",
[dijit.form.DropDownButton],
{
label: 'Countries',
dropDown: new dijit.TooltipDialog({ execute: function() {
console.log("EXECUTE : ", arguments[0]);
this.value = arguments[0].country;
}, href:'/cm/ui/countries' }),
postCreate: function() {
this.inherited(arguments);
this.label = this.value;
dojo.connect(this.dropDown, 'onClose', function() { console.log('close'); });
console.log("CountrySelect post create", this);
},
}
);
与网格单元的类型为:
{ name: 'Countries', field: 'targeting.countries', editable: true, hidden: false, type:dojox.grid.cells._Widget, widgetClass: CountrySelector },
所有工作正常,但我不能了解如何更新单元格的内容并在存储单元执行时进行存储。同样,我似乎没有更新行的行ID。
任何想法?
感谢, 哈雷尔
答
我没有设置你的代码的测试,但你应该能够只是创建一个在你的小工具,返回值命名getValue
的方法来做到这一点。
查看其他示例(如dojox.grid.cells.ComboBox)以了解getValue的外观。
答
//Layout:
gridLayout: {rows: [{name: 'Coll Name',field: 'colField', type: dojox.grid.cells.ComboBox, editable:'true', width:'8%',options: [], alwaysEditing:false}]}
//Grid Store:
this.gridStore = new dojo.data.ItemFileReadStore({data: {items: data}});
//
var setOptions = function(items, request){
this.gridLayout.rows[0].options.push('Val 1','Val 2');
this.gridLayout.rows[0].values.push('1','2');
dojo.connect(this.gridLayout.rows[0].type.prototype.widgetClass.prototype, "onChange",this, "_onComboChange");
}
this.gridStore.fetch({onComplete: dojo.hitch(this,setOptions)});
_onComboChange: function (selectedOption) {
console.info("_onComboChange: ",selectedOption);
},
// If you need to populate combos with different values you can use onItem
var getArray = function(item, request){
// populate one by one
// attach an event to each combo
}
this.gridStore.fetch({onItem: dojo.hitch(this,getArray)});
答
这是我用来更新我的网
var idx = yourGrid.getItemIndex(item);
if (idx >- 1) {
yourGrid.updateRow(idx);
}
更多细节
每一行由其标识符标识
yourGrid.store.fetchItemByIdentity({
identity: <yourIdentity>,
onItem: function(item){
// Update your attributes in the store depending on the server response
// yourGrid.store.setValue(item, <attribute>,<value>);
var idx = yourGrid.getItemIndex(item);
if (idx >- 1) {
yourGrid.updateRow(idx);
}
}
});
从来没有为我工作。 对我来说,最终的解决方案(对于这个和其他的小错误)是为了沟渠Dojo(我非常喜欢它)并且把所有东西都移到ExtJs。就稳定性和易用性而言,它就在前方。更不用说它实际上有适当的文档。 虽然感谢您的帮助! – Harel 2009-09-21 08:42:03