【问题标题】:Not able to retrieve selected records in grid无法检索网格中的选定记录
【发布时间】:2020-03-31 10:43:50
【问题描述】:

我正在使用 ExtJS 7.1 并创建了一个网格面板。我无法使用代码检索选定的行 Ext.getCmp("tempGrid").getSelectionModel().getSelection(),这行代码总是返回长度为0。

Ext.getCmp("tempGrid").getSelectionModel().hasSelection(),这行代码总是返回false。

我不确定出了什么问题,想寻求建议或建议。谢谢

我有一个标签面板作为主面板(mainPanel),然后我附加/链接了另一个面板(称为 tempGrid) 在tempGrid里面,我会放网格,这里是网格配置

items: {
  xtype: 'gridpanel',
  id: 'tempGrid',
  header: false,
  forceFit: true,
  store: 'AStore',
  columns: [{
      xtype: 'gridcolumn',
      dataIndex: 'colA',
      text: 'A Column',
      filter: {
        type: 'string'
      }
    },
    {
      xtype: 'gridcolumn',
      dataIndex: 'colB',
      text: 'B Column',
      filter: {
        type: 'string'
      }
    }
  ],
  plugins: [{
    xtype: gridfilters ''
  }],
  dockedItems: [{
    xtype: 'pagingtoolbar',
    dock: 'bottom',
    displayInfo: true,
    inputItemWidth: 80,
    store: 'AStore'
  }]
}

【问题讨论】:

  • 这个问题可能看起来很傻,但同时您在网格中选择了行?
  • 是的,我选择了网格中的一行,然后使用 Chrome 控制台执行“Ext.getCmp("tempGrid").getSelectionModel().hasSelection()”,结果为假。我也尝试过“Ext.getCmp("tempGrid").getSelectionModel().getSelection()”,但长度为 0
  • 你能举个网格配置的例子吗?
  • 嗨,我已将网格配置复制到我的问题中。请指教。非常感谢

标签: extjs sencha-architect extjs7


【解决方案1】:

您的网格配置示例中的网格具有 id APanel。 你必须打电话给

Ext.getCmp("APanel").getSelectionModel().getSelection()

获取选定的记录。我认为tempGrid 是你的另一个网格

【讨论】:

  • 抱歉,我在向 StackOverFlow 输入代码时出错了。由于某种原因,我不能直接从 Sencha Architect IDE 复制并粘贴代码到 Stackoverflow。我实际上已经尝试过 Ext.getCmp("tempGrid").getSelectionModel().getSelection(),但总是给出长度 0,即使我在网格中选择了一条记录
【解决方案2】:

你的函数应该是这样的

var myGrid = this.getView();
var sl = myGrid.getSelectionModel().getSelection();
var items = new Array();
if (sl.length) {
  for (var i = 0; i < sl.length; i++) {
    items[i] = sl[i].get('recordId');
  }
}
return items;

你不应该是 xtype: 'grid' 这样的 xtype: 'gridcolumn', 请也检查一下。谢谢

希望有帮助

【讨论】:

  • 这是我在网格列上输入 xtype: 'grid' 的错字。对不起。我会尝试您的建议并尽快回复您。谢谢。
【解决方案3】:

我的问题得到了解决,希望对其他人有所帮助

var grid = Ext.getCmp('CenterGrid');
var selection= CenterGrid.getSelectionModel();

for(var i=0;i < grid.store.getCount();i++){
if(selection.isSelected(i)){
//these array assing to finalarray send to php below
c.push(
grid.store.getAt(i).data.Parameter_Name+ "||",
grid.store.getAt(i).data.Value + "||",
grid.store.getAt(i).data.Value2 + "||",
grid.store.getAt(i).data.Value3 + "||"

);
}
}
console.log("new:"+c);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-09
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    相关资源
    最近更新 更多