1

我使用 extjs mvc 并且有一列有渲染器

{
        text: __('Profiler.Personage.Settings.Active'),
        name: 'AdminDeny',

        renderer: function (value, metaData, record, row, col, store, gridView) {
            if (value == null || value == true) {
                return '<a class="Deactive"  href="javascript:void(0);"><img src="' + icon.Deactive + '" alt="Is Default" title="' + __('Profiler.Personage.PhoneGrid.IsDefault') + '" class="grid-icon" /></a>';
            } else {
                return '<a href="javascript:void(0);"><img src="' + icon.IsDefault + '" alt="Is Default" title="' + __('Profiler.Personage.PhoneGrid.IsDefault') + '" class="grid-icon" /></a>';
            }
        }

在此处输入图像描述 当点击a我想在控制器中获取单元格的值

4

1 回答 1

1

这是一个简单的。你需要使用actioncolumn:

{
     text: 'Is active',
     xtype: 'actioncolumn',
     align: 'center',
     dataIndex: 'is_active',
     width: 70,
     renderer: function (value, metaData, record, row, col, store, gridView) {
         if (value == null || value == true) {
             return '<img action="disable" src="/path/to/image.png" title="Some title" class="grid-icon" />';
         } else {
             return '<img action="enable" src="/path/to/image.png" alt="Is Default" title="Some title" class="grid-icon" />';
         }
     }
}

在你的控制器中:

    init:function() {
        this.control({

            ...

            'panel[itemId=mygrid] actioncolumn': {
                click: function(grid, cell, row, col, e) {
                    var record = grid.getStore().getAt(row),
                        action = e.getTarget('.grid-icon', 3, true).getAttribute('action'),
                        message;

                    if(action == 'enable') {
                        message = 'Clicked "enable" for '+record.get('name');
                    }else if(action == 'disable') {
                        message = 'Clicked "disable" for '+record.get('name');
                    }
                    alert(message);
                }
            }

            ...

        });

        ...
    }

查看 github 上的实时示例: http ://htmlpreview.github.com/?https://github.com/werdender/ext4examples/blob/master/actioncolumns.html

于 2013-01-26T15:47:14.597 回答