ExtJS - TreeGrid 上的自定义列渲染器没有被触发

标签 extjs

我有一个 ExtJS TreeGrid,我正在尝试向特定列添加自定义渲染器。不幸的是它不起作用 - 事件没有被触发,也没有发出警告。我也找不到 TreeGrid 的 API。有没有其他人经历过这种情况?

这是代码:

    var tree = new Ext.ux.tree.TreeGrid({
        title: 'My Tree Grid',
        loader: treeLoader,
        columns:[{
            header: 'Title',
            dataIndex: 'title',
            width: 500
        },{
            header: 'Testing',
            width: 100,
            dataIndex: 'testing',
            renderer: function(value) {
              console.log('Test');
            },
            align: 'center'
        }]
     });

谢谢!

最佳答案

TreeGrid 没有 API,因为它是一个用户扩展 (Ext.ux)。您必须查看源代码以获取更多信息。如果您的项目中没有源代码,请转到以下页面:

http://dev.sencha.com/deploy/dev/examples/treegrid/treegrid.html

并点击“查看源代码”Ctrl + U .从那里您可以链接到 TreeGrid.js和其他支持 js 文件。

我注意到 TreeGrid扩展 TreePanel ,这反过来又扩展了普通的旧 Panel .似乎没有对 GridPanel 的任何引用,所以我不相信有任何列渲染器,如果您正在使用该组件,则不会像您期望的那样。根据我收集的信息,示例 (tree-grid.js) 改为使用 XTemplate 来呈现列数据:

    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',
            // ================================== //
            // this acts as your column renderer
            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'
    });

尝试将 XTemplate 用于您的目的。如果这不能满足您的需求,您将不得不提供更多信息。

关于ExtJS - TreeGrid 上的自定义列渲染器没有被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4791729/

相关文章:

javascript - ExtJS Ext.Button 复用

javascript - ExtJs 4.2 从扩展 Controller 访问变量

javascript - ExtJS v4.0 - 带有自定义纯色条的条形图

extjs - extjs4 mvc 中基于角色的 View

javascript - Sencha Ext 中的 float 图像

ExtJS:如何使用 BorderLayout 扩展 Ext.Panel?

javascript - 如何使用卡片触发点击事件?

javascript - 我如何使用 sencha 选项卡上的按钮来放置覆盖面板

css - ExtJS、组合、列表框、文本对齐

java - RESTful - 在 Queryparam 中获取 null