extjs 中怎么得到GridPanel中显示的列的id或者dataIndex

extjs 中怎么得到GridPanel中显示的列的id或者dataIndex,第1张

//extjs grid是没有列index的,他是只有行的index。

//你要获取列数据,其实也就是获取store里面的数据值。只能用遍历store的方法。

//比如你要获取name列的所有值,那么就遍历这个store。

var name_str;

for (var i = 0; i < storegetCount(); i++) {

var record = storegetAt(i);

alert(recordget('name'));

//name_str  = name_str + name;  //进行拼接

alert(name_str);

Ext4官方的案例第一个,array-grid,里面的actioncolumn xtype: 'actioncolumn', width: 50, items: [{ icon : '/shared/icons/fam/deletegif', // Use a URL in the icon config tooltip: 'Sell stock', handler: function(grid, rowIndex, colIndex) { var rec = storegetAt(rowIndex); alert("Sell " + recget('company')); } }, { getClass: function(v, meta, rec) { // Or return a class from a function if (recget('change') < 0) { thisitems[1]tooltip = 'Hold stock'; return 'alert-col'; } else { thisitems[1]tooltip = 'Buy stock'; return 'buy-col'; } }, handler: function(grid, rowIndex, colIndex) { var rec = storegetAt(rowIndex); alert((recget('change') < 0 "Hold " : "Buy ") + recget('company')); } }]可以那个getClass那里设置,用recget('xxx')来获取所在行xxx字段的值,根据不同的值返回css设置的图标。

方法一、给Grid绑定以下事件:

headerclick : ( Grid this, Number columnIndex, ExtEventObject e )

事件响应代码里面读取dataIndex:

var fieldName = thisgetColumnModel()getDataIndex(columnIndex);

这就是你要的数据列名。

说明:

Grid的headerclick事件虽然每个版本的Docs分别说:

Available since: Ext JS 420

Available since: Ext JS 230

可是它确实在Ext21/docs/output/ExtgridGridPanelhtml里就有的。

针对问题补充:

在你的show函数里如果可以访问到var column=Ext,utilJSONdecode这个变量,那可以尝试:

function show(value,metadata,record,rowIndex,colIndex,store){

alert(columngetDataIndex(colIndex));

}

你看下Ext的API,我看了下Ext 11的API

GridPanel是没有selModel这个属性的

你可以使用EditorGrid的getSelectionModel()getSelections();

获取到的是一个record对象数组

方案1: 循环 gridStore 内的数据 使用grid的selModel 的 isSelected ( Number/Record index ) 判断是否选中 并记录未选中行 或 用store的数据与 selModelgetSelections() 做对比 记录未选中行

方案2 : 获取grid的selModel 用selModeldeselectRange 反选所有内容 及时获取getSelections()

记录内容后 再次deselectRange 反选 变为正常(理论上可以)

以上就是关于extjs 中怎么得到GridPanel中显示的列的id或者dataIndex全部的内容,包括:extjs 中怎么得到GridPanel中显示的列的id或者dataIndex、怎么获取ext里grid中的ComboBox 并动态改变里面的值、在extjs的grid 如何点击某一列的时候取得这一列的dataIndex的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/10046665.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存