gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:53:58 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com