【问题标题】:dynamic url inside a extjs table dont workextjs 表中的动态 url 不起作用
【发布时间】:2014-09-23 10:26:33
【问题描述】:

我有一个网格面板,每行都有一个子表。我试图包含双击功能(如果您连续单击 2 次,获取 id_amenaza 并使用 url 重定向)。该代码有效,但如果我双击折叠该行。如何添加此功能? (或插入充当链接的图像?)

//GRIDPANEL
Ext.create('Ext.grid.Panel', {
    renderTo: 'example-grid',
    store: amenazaStore,
    width: 748,
    height: 598,
    title: '<bean:write name="informesAGRForm" property="nombreActivo"/>',
    plugins: [{
        ptype: "subtable",
        headerWidth: 24,
        listeners: {
            'rowdblclick': function(grid, rowIndex, columnIndex, e){
              // Get the Record, this is the point at which rowIndex references a 
              // record's index in the grid's store.
              var record = grid.getStore().getAt(rowIndex);  

              // Get field name
              var fieldName = grid.getColumnModel().getDataIndex(columnIndex); 
              var data = record.get(fieldName);
              alert(data);
            }
        },
            columns: [{
            text: 'id_amenaza',
            dataIndex: 'id_amenaza',
            hidden: true,
            width: 100
        }, {
            width: 100,
            text: 'id_salvaguarda',
            dataIndex: 'id_salvaguarda'
        },
        {
            text: 'denominacion',
            dataIndex: 'denominacion',
            width: 100
        },{
            text: 'descripcion',
            dataIndex: 'descripcion',
            width: 100
        },{
            text: 'eficacia',
            dataIndex: 'eficacia',
            width: 100
        },
        ],
        getAssociatedRecords: function (record) {
            var result = Ext.Array.filter(
            salvaguardaStore.data.items,

            function (r) {
                return r.get('id_amenaza') == record.get('id');
            });
            return result;
        }
    }],
    collapsible: false,
    animCollapse: false,
    columns: [
        {
            text: 'ID',
            hidden: true,
            hideable: false,
            dataIndex: 'id'
        },   
        {
            text: 'Codigo',
            width: 50,
            sortable: true,
            hideable: false,
            dataIndex: 'codigo'
        },          
        {
            text: 'Denominación',
            width: 150,
            dataIndex: 'denominacion',
        },
        {
            text: ' Autenticidad',
            flex: 1,
            dataIndex: 'a_riesgo'
        },
        {
            text: 'Confidencialidad',
            flex: 1,
            dataIndex: 'c_riesgo'
        },
        {
            text: 'Integridad',
            flex: 1,
            dataIndex: 'i_riesgo'
        },
        {
            text: 'Disponibilidad',
            flex: 1,
            dataIndex: 'd_riesgo'
        },
        {
            text: 'Trazabilidad',
            flex: 1,
            dataIndex: 't_riesgo'
        },
        {
            text: 'Total',
            flex: 1,
            dataIndex: 'total_riesgo'
        }]
    });
}

提前谢谢你。

【问题讨论】:

    标签: javascript extjs extjs5


    【解决方案1】:

    首先,您必须将rowdblclick 附加到主网格。要检测点击了哪个子表行,您必须使用事件对象。

    例子:

    'rowdblclick': function (view, record, tr, columnIndex, e) {
        var cell = e.getTarget('.x-grid-subtable-cell');
        if (!cell) {
            return;
        }
        var row = Ext.get(cell).up('tr');
        var tbody = row.up('tbody');
        var rowIdx = tbody.query('tr', true).indexOf(row.dom);
    
        var records = view.up('grid').getPlugin('subtable').getAssociatedRecords(record);
    
        var subRecord = records[rowIdx];
        console.log(subRecord);
    }
    

    关闭插件上的扩展/折叠集expandOnDblClick: false

    工作样本:http://jsfiddle.net/7czs02yz/18/

    【讨论】:

    • 谢谢,但我还有一个问题。当我使用alert(subRecord); 时,我得到[object Object] 作为消息。如何获得id_salvaguarda 值?
    • 使用get方法:record.get('id_salvaguarda')record.data对象:record.data.id_salvaguarda
    • 这两种方法都不起作用(我对 javascript 来说绝对是新的)。也许问题是正确的表/行?在 Firefox 开发者模式下显示这个&lt;td class="x-grid-subtable-cell" style="width:100px"&gt; &lt;div id="ext-element-5" class="x-grid-cell-inner"&gt; 16 &lt;/div&gt; &lt;/td&gt;
    • 最后我打开了另一个问题,因为你从这里解决了这个问题。谢谢!)。 stackoverflow.com/questions/26016240/get-row-from-a-nested-grid
    • 适用于我的示例:jsfiddle.net/7czs02yz/21 subRecord 在我的示例中是Salvaguardas 模型的实例,而不是表中的行。 row 变量保存 Ext.Element 指向点击的行。
    猜你喜欢
    • 2014-07-01
    • 2012-02-26
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多