【问题标题】:Get Grid Cell Value on Hover in ExtJS4在 ExtJS4 中悬停时获取网格单元格值
【发布时间】:2011-12-31 18:35:25
【问题描述】:

我在网格中有以下代码:

    var grid = Ext.create('Ext.grid.Panel', {
        store: store,
        stateful: true,
        stateId: 'stateGrid',
        columns: [
            {
                text     : 'Job ID',
                width : 75,
                sortable : true,
                dataIndex: 'id'
            },
            {
                text     : 'File Name',
                width    : 75,
                sortable : true,
                dataIndex: 'filename', 
                listeners : {
                    'mouseover' : function(iView, iCellEl, 
                                  iColIdx, iRecord, iRowEl, iRowIdx, iEvent) {
                       var zRec = iView.getRecord(iRowEl);
                       alert(zRec.data.id);
                    }
                }

...等等...

我不知道如何获取行中第一列的单元格值。我也试过:

        var record = grid.getStore().getAt(iRowIdx); // Get the Record
        alert(iView.getRecord().get('id'));

有什么想法吗?

提前致谢!

【问题讨论】:

  • 我觉得你很亲密。试试alert(record.get('id')); 而不是iView.getRecord...

标签: javascript extjs extjs4 javascript-framework


【解决方案1】:

您可以添加处理程序而不是侦听器。

{
    header: 'DETAILS',
    xtype:'actioncolumn', 
    align:'center', 
    width: 70, 
    sortable: false, 
    items: [
        {
            icon: '/icons/details_icon.png',  // Use a URL in the icon config
            tooltip: 'Show Details',    
            handler: function(grid, rowIndex, colIndex) {
                var record = grid.getStore().getAt(rowIndex);
            }

【讨论】:

    【解决方案2】:

    这比你拥有的更容易。

    在此处查看 Company 列配置以获取示例 - http://jsfiddle.net/qr2BJ/4580/

    编辑:

    部分网格定义代码:

    ....
    columns: [
        {
            text     : 'Company',
            flex     : 1,
            sortable : false,
            dataIndex: 'company',
            renderer : function (value, metaData, record, row, col, store, gridView) {
                metaData.tdAttr = 'data-qtip="' + record.get('price') + ' is the price of ' + value + '"';
                return value;
            }
        },
        ....
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-03
      • 2012-08-29
      • 1970-01-01
      • 2010-11-22
      • 2012-08-25
      • 1970-01-01
      相关资源
      最近更新 更多