简体   繁体   English

如何确定单击了哪个单元格?

[英]How to determine what cell has been clicked?

I am new to JavaScript and I am having to use ExtJS 3.4. 我是JavaScript新手,必须使用ExtJS 3.4。 I have created a simple tree with 3 columns. 我创建了一个包含3列的简单树。 I would like to know either what cell was selected, or even, just what row and column were selected. 我想知道选择了哪个单元格,甚至选择了什么行和列。

I am just using the example that Sencha uses at http://dev.sencha.com/deploy/ext-3.4.0/examples/treegrid/treegrid.html : 我只是在http://dev.sencha.com/deploy/ext-3.4.0/examples/treegrid/treegrid.html使用Sencha使用的示例:

  var tree = new Ext.ux.tree.TreeGrid({
    title: 'Core Team Projects',
    width: 500,
    height: 300,
    renderTo: Ext.getBody(),
    enableDD: true,

    columns:[{
        header: 'Task',
        dataIndex: 'task',
        width: 230
    },{
        header: 'Duration',
        width: 100,
        dataIndex: 'duration',
        align: 'center',
        sortType: 'asFloat',
        tpl: new Ext.XTemplate('{duration:this.formatHours}', {
            formatHours: function(v) {
                if(v < 1) {
                    return Math.round(v * 60) + ' mins';
                } else if (Math.floor(v) !== v) {
                    var min = v - Math.floor(v);
                    return Math.floor(v) + 'h ' + Math.round(min * 60) + 'm';
                } else {
                    return v + ' hour' + (v === 1 ? '' : 's');
                }
            }
        })
    },{
        header: 'Assigned To',
        width: 150,
        dataIndex: 'user'
    }],

    dataUrl: 'treegrid-data.json'
});

Is it possible to do this in ExtJS 3.4? 在ExtJS 3.4中可以这样做吗? I can get the node but I do not see where it is telling me what cell or column or row was selected. 我可以得到该节点,但是看不到它告诉我选择了哪个单元格,列或行。

Any help would be greatly appreciated! 任何帮助将不胜感激!

you need to attach listeners eg 您需要附加监听器,例如

 listeners: {
                afterRender: function(p) {
                    p.body.on('click', function() { // Function tapping clicks on Panel
                    alert(p.getTargetEl().dom.innerHTML);

                                            });
                    });

             }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM