【问题标题】:Extjs locating individual comboboxes in a GridExtjs 在网格中定位单个组合框
【发布时间】:2013-11-06 04:43:44
【问题描述】:

我是 Extjs 的新手,急需帮助!我已经做了一些研究,并试图寻找解决方案 2 天,但没有找到解决我的问题的方法!我的问题如下:

我正在尝试创建包含 3 列组合框的网格。第一列将有一个组合框,可以禁用/启用该行中的其他组合框!当我更改第一列中的组合框时,第二列和第三列中的组合框全部更改!我不希望发生这种情况,我只想改变行!

我希望这是有道理的??如何在网格中的特定位置定位组合框并更改其配置?

谢谢各位!!!!

这是我到目前为止所拥有的......这是我所有组合框的格式:......

/***************/
/* COMBO BOXES */
/***************/

//PROTOCOL COMBO BOX!
var protocol_cbox = new Ext.form.ComboBox({
    typeAhead: true,
    triggerAction: 'all',
   // lazyRender: true ,
    mode: 'local',
    store: new Ext.data.ArrayStore({
       id: 0,
       fields: [
           'myId',
           'displayText'
       ],
       data: [[1, 'Ethernet'], [2, 'Serial']]
   }),
   valueField: 'myId',
   displayField: 'displayText',
}); 

这是我的选择模型......

/****************/
/* COLUMN MODEL */
/****************/
var rownum = new Ext.grid.RowNumberer();
var grid_column_model = new Ext.grid.ColumnModel([
  new Ext.grid.RowNumberer(),
  {header: "Program", dataIndex: "program", align: 'center', width: myGridColumnWidth/2, editor: program_tbox},
  {header: "Protocol", dataIndex: "Protocol", align: 'center', width: myGridColumnWidth/2, editor: protocol_cbox, renderer: Ext.util.Format.comboRenderer(protocol_cbox)},
  {header: "Hostname", dataIndex: "hostName", align: 'center', width: myGridColumnWidth/2, editor: hostname_tbox},
  {header: "Port", dataIndex: "Port_E", align: 'center', width: 100,  editor: port_tbox},
  {header: "Device", dataIndex: "Port_S", align: 'center', width: 100, editor: device_tbox},
  {header: "Baud", dataIndex: "Baud", align: 'center', width: 100, editor: baud_cbox, renderer: Ext.util.Format.comboRenderer(baud_cbox)},
  {header: "Data Bits", dataIndex: "DataBits", align: 'center', width: myGridColumnWidth/2, editor: dataBits_cbox, renderer: Ext.util.Format.comboRenderer(dataBits_cbox)},
  {header: "Parity", dataIndex: "Parity", align: 'center', width: myGridColumnWidth/2, editor: parity_cbox, renderer: Ext.util.Format.comboRenderer(parity_cbox)},
  {header: "Stop Bits", dataIndex: "StopBits", align: 'center', width: myGridColumnWidth/2, editor: stopBits_cbox, renderer: Ext.util.Format.comboRenderer(stopBits_cbox)},
  {header: "Flow Control", dataIndex: "FlowControl", align: 'center', width: 125  , editor: flowControl_cbox, renderer: Ext.util.Format.comboRenderer(flowControl_cbox)}

]);

最后是我的处理函数! ........

//DISABLE OR ENABLE CBOX HANDLER
function hide_unhide(){
 for(i=0; i<= store.getCount() - 1; i++){
  if(store.getAt(i).data.Protocol== 1){
    baud_cbox.setDisabled(false);
 } else {
    baud_cbox.setDisabled(true);
 }
}

}

【问题讨论】:

  • 这是我到目前为止所拥有的......:function hide_unhide(){ for(i=0; i
  • 您是否将这些组合框用作带有 RowEditing 或 CellEditing 插件的网格中的编辑器?
  • 嘿,马特 .... 我在列模型中使用组合框作为编辑器.. 我不确定我是否使用行或单元格编辑.. 我如何找出?
  • RowEditing 意味着所有编辑器一次显示(每行),CellEditing 将只显示您选择的单元格的编辑器。另外,您使用的是哪个 ExtJS 版本?
  • 我的选择模型是“rowSelectionModel”.. 所以我假设我正在使用行编辑。我正在使用 3.4 版的 Ext

标签: extjs combobox


【解决方案1】:

如果您禁用组合框,它将在该列的所有单元格中被禁用,因为每列只有一个编辑器(在本例中为组合框),用于所有行。

如果您想禁用特定行的组合框,我建议您在网格上的 beforeedit 事件中添加一个侦听器,这将在编辑开始之前启用/禁用组合框:

listeners: {
    beforeedit: function(e) {
        var condition = e.record.data.id == 1; // your condition here
        combo2.setDisabled(condition);
        combo3.setDisabled(!condition);
    }
}

【讨论】:

  • 谢谢马特!..我应该把这个监听器准确地添加到我的列模型或网格面板吗?
  • matt 我这样做了,它似乎可以工作,但是,如果我想选择更改控制器组合框的选择,我仍然会遇到同样的问题......绝对没有办法只找到单独的组合框??
  • 对不起,我不明白你到底想做什么。您能否更详细地描述该用例和预期结果?
  • 我仍然不明白它是如何工作的????...也许你可以向我解释一下..我似乎正在理解网格和列模型的工作原理...... beforeedit 事件仅在实际编辑网格之前发生..但是在我放入您建议的侦听器之后..当我为组合框选择不同的文本字段时它也可以工作..就好像它也在监听选择事件一样。无论如何它现在实际上工作了!非常感谢先生!
  • beforeedit 事件在编辑开始之前(即在显示编辑器之前)触发。在实际编辑记录之前(即在将更改应用于网格之前)发生的事件称为validateedit
猜你喜欢
  • 2017-05-25
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 2013-07-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多