English 中文(简体)
编程方式更改EditorGrid的单元格值
原标题:Programmatically change an EditorGrid s cell value

我有一个编辑网格,在其中,如果特定单元格正在焦点(正在编辑),则会弹出一个包含树形面板的窗口,允许用户选择来自树面板的节点作为单元格的新值。这样,用户实际上并没有编辑有问题的单元格,而是使用窗口选择新值。但是,我在以编程方式设置有问题的单元格的值方面遇到了困难。

以下是我用来设置网格的代码,包括选择单元格编辑器的列模型,取决于值类型:

var editorCM = new Ext.grid.ColumnModel({
  //config
  ,editors : {
    //rest of editors
     id  : new Ext.grid.GridEditor(new Ext.form.TextField({readOnly : true}))
  }
  ,getCellEditor : function(col, row) {
    //choose editor depending on the type value of a cell
  }
})

var editorGrid = new Ext.grid.EditorGridPanel({
  //rest of config
  ,cm : editorCM
})

以下是我的代码,当用户从treepanel中选择后可以更改单元格的值。

function submitNode(newValue) {
  var temp = editorGrid.GetSelectionModel().getSelectedCell(); //returns array containing column and row position of selected cell, which value we want to change.

  //temp[1] = column index, temp[0] = row index
  //Gets the cell editor at specific position and sets new value for that cell
  editorGrid.getColumnModel().getCellEditor(temp[1], temp[0]).setValue(newValue);
}

我也尝试了几种其他方法(都包括setValue(newValue)),但都没有结果。我查看了API和ExtJS论坛以寻找任何线索,但同样没有结果。

问题回答

我没有和编辑网格一起工作过,所以我有点摸不着头脑。

参考此链接:http://www.extjs.com/deploy/dev/examples/grid/edit-grid.js

看起来他们的做法(用于加法)是直接更新存储,如果你能确定存储记录,那么你肯定可以直接更新它。

看看 addPlant 的处理程序:

 handler : function(){
            // access the Record constructor through the grid s store
            var Plant = grid.getStore().recordType;
            var p = new Plant({
                common:  New Plant 1 ,
                light:  Mostly Shade ,
                price: 0,
                availDate: (new Date()).clearTime(),
                indoor: false
            });
            grid.stopEditing();
            store.insert(0, p);
            grid.startEditing(0, 0);
        }

如果失败了,我很想看看当您使您的字段不是只读时会发生什么:

  ,editors : {
//rest of editors
 id  : new Ext.grid.GridEditor(new Ext.form.TextField({readOnly : false}))  }

只是一些想法。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.