在ExtJS 4 Grid中设置单元ID

时间:2022-08-24 11:39:20

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. As I understand, I need to override the default template used for cell creation. My current template looks like this:

我正在将相当大量的旧HTML代码移植到ExtJS 4网格,并且偶然发现了以下挑战:我希望能够为网格中的TD元素设置自定义ID。据我了解,我需要覆盖用于创建单元格的默认模板。我当前的模板如下所示:

    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 =”属性?

2 个解决方案

#1


8  

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;
    }
}, ... ]

#2


0  

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'])
    }

#1


8  

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;
    }
}, ... ]

#2


0  

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'])
    }