最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting a cell ID in ExtJS 4 Grid - Stack Overflow

programmeradmin5浏览0评论

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:

    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?

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:

    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?

Share Improve this question asked May 17, 2012 at 15:49 clopsclops 5,2556 gold badges43 silver badges53 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8 +50

Do not overwrite the tpl, just set a custom column renderer which will update a column metadata:

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:

oncellclick:function(grid, row, col, e){
        alert( row['id'])
    }
发布评论

评论列表(0)

  1. 暂无评论