如何使用TooltipDialog(和DropDownButton)更新Dojo网格单元格值

时间:2009-08-19 14:05:07

标签: grid dojo

我有一个使用一些可编辑的dijit表单字段的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。

有什么想法吗?

谢谢, Harel的

3 个答案:

答案 0 :(得分:1)

//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)});

答案 1 :(得分:1)

这是我用来更新网格的内容

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);        
        }
    }
});

答案 2 :(得分:0)

我没有使用您的代码设置测试,但您应该只需在窗口小部件中创建一个名为getValue的方法来返回值。

看看其他示例(比如dojox.grid.cells.ComboBox),了解getValue应该是什么样子。