[英]Setting a cell ID in ExtJS 4 Grid
I am in the process of porting quite a large chunk of old HTML code to an ExtJS 4 grid and have stumbled upon the following challenge: I want to be able to set a custom ID for the TD elements in the grid. 我正在将相当大量的旧HTML代码移植到ExtJS 4网格中,并且偶然发现了以下挑战:我希望能够为网格中的TD元素设置自定义ID。 As I understand, I need to override the default template used for cell creation. 据我了解,我需要覆盖用于创建单元格的默认模板。 My current template looks like this: 我当前的模板如下所示:
Ext.view.TableChunker.metaRowTpl = [
'<tr class="' + Ext.baseCSSPrefix + 'grid-row {addlSelector} {[this.embedRowCls()]}" {[this.embedRowAttr()]}>',
'<tpl for="columns">',
'<td class="{cls} ' + Ext.baseCSSPrefix + 'grid-cell ' + Ext.baseCSSPrefix + 'grid-cell-{columnId} {{id}-modified} {{id}-tdCls} {[this.firstOrLastCls(xindex, xcount)]}" {{id}-tdAttr}><div class="' + Ext.baseCSSPrefix + 'grid-cell-inner ' + Ext.baseCSSPrefix + 'unselectable" style="{{id}-style}; text-align: {align};">{{id}}</div></td>',
'</tpl>',
'</tr>'
];
What placeholder could I use in order to be able to manipulate the "id=" attribute of the table cell? 我可以使用什么占位符来操作表格单元格的“id =”属性?
Do not overwrite the tpl, just set a custom column renderer which will update a column metadata: 不要覆盖tpl,只需设置一个自定义列渲染器 ,它将更新列元数据:
columns: [{
text: 'Blah',
dataIndex: 'blah',
renderer: function(value, metaData, record) {
metaData.tdAttr = 'id="someprefix-' + record.get('blah') + '"';
return value;
}
}, ... ]
The 1st answer worked fine for me and for the id extraction was easy like this: 第一个答案对我来说很好,并且id提取很简单,就像这样:
oncellclick:function(grid, row, col, e){
alert( row['id'])
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.