【问题标题】:How to update a Dojo Grid cell value using a TooltipDialog (and DropDownButton)如何使用 TooltipDialog(和 DropDownButton)更新 Dojo Grid 单元格值
【发布时间】:2010-11-20 23:21:35
【问题描述】:

我有一个使用一些可编辑 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。

有什么想法吗?

谢谢, 哈雷尔

【问题讨论】:

    标签: grid dojo


    【解决方案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)});
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

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

        查看其他示例(如 dojox.grid.cells.ComboBox)以了解 getValue 的外观。

        【讨论】:

        • 这对我没有用。就我而言,最终的解决方案(解决这个问题和其他小问题)是放弃 Dojo(我非常喜欢它)并将所有东西都转移到 ExtJs。就稳定性和易用性而言,它仅领先几英里。更不用说它实际上有适当的文档。不过感谢您的帮助!
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-16
        • 1970-01-01
        • 2020-06-15
        • 1970-01-01
        • 1970-01-01
        • 2020-09-25
        • 1970-01-01
        相关资源
        最近更新 更多