Vis*_*ioN 4 javascript extjs extjs4
需要在ExtJS 4网格面板中动态更改视图.
默认情况下,网格显示为表格,但在我的应用程序中,我需要一个功能将网格从表格视图切换到图块(或卡片)视图.下面我尝试表示它应该是什么样子.
Normal view: Tiles view:
====================================== ====================================
| Name | Description | | Name | Description |
====================================== ====================================
| Name 1 | First description |^| | ------ ------ ------ |^|
|----------------------------------|X| | | O O | | @ @ | | > < | |X|
| Name 2 | Second description |X| | | \__/ | | \__/ | | \__/ | |X|
|----------------------------------|X| | ------ ------ ------ |X|
| Name 3 | Third description | | | Name 1 Name 2 Name 3 | |
|----------------------------------| | | | |
| | | | | ------ ------ ------ | |
| ... | ... |v| | | o O | | - - | | * * | |v|
====================================== ====================================
Run Code Online (Sandbox Code Playgroud)
我发现了我需要的几乎完美的实现,名为Ext.ux.grid.ExplorerView.但是,扩展是为ExtJS版本2.x(3.x)开发的,不能重用于ExtJS 4.
我使用的网格创建简单如下:
Ext.create("Ext.grid.Panel", {
store: ...,
columns: [{
header: "Name",
dataIndex: "name",
}, {
header: "Description",
dataIndex: "description"
}],
tbar: [ ... ],
bbar: [ ... ],
listeners: { ... },
multiSelect: true,
viewConfig: {
stripeRows: true,
markDirty: false,
listeners: { ... }
}
});
Run Code Online (Sandbox Code Playgroud)
我试图更新tpl
内部视图组件的属性,但似乎没有任何工作.
您是否知道如何在单个网格面板的视图之间进行动态切换?
Harald Hanek开发的名为" Tileview "的网格面板的精彩功能很容易解决了这个问题.该解决方案专为ExtJS 4开发.
基本用法示例如下:
var grid = Ext.create("Ext.grid.Panel", {
store: ...,
columns: [{
header: "Name",
dataIndex: "name",
}, {
header: "Description",
dataIndex: "description"
}],
tbar: [ ... ],
bbar: [ ... ],
listeners: { ... },
multiSelect: true,
viewConfig: {
stripeRows: true,
markDirty: false,
listeners: { ... }
},
features: [Ext.create("Ext.ux.grid.feature.Tileview", {
getAdditionalData: function(data, index, record, orig) {
if (this.viewMode) {
return {
name: record.get("name").toLowerCase(),
};
}
return {};
},
viewMode: 'tileIcons', // default view
viewTpls: {
tileIcons: [
'<td class="{cls} ux-tileview-detailed-icon-row">',
'<table class="x-grid-row-table">',
'<tbody>',
'<tr>',
'<td class="x-grid-col x-grid-cell ux-tileview-icon" style="background-image: url("...");">',
'</td>',
'<td class="x-grid-col x-grid-cell">',
'<div class="x-grid-cell-inner">{name}</div>',
'</td>',
'</tr>',
'</tbody>',
'</table>',
'</td>'
].join(""),
mediumIcons: [ ... ].join(""),
largeIcons: [ ... ].join("")
}
})]
});
Run Code Online (Sandbox Code Playgroud)
要改变视图我们应该只使用setView()
方法,即
grid.features[0].setView("tileIcons");
Run Code Online (Sandbox Code Playgroud)
这就是这个特征在现实生活中的样子.
参考文献:
归档时间: |
|
查看次数: |
4873 次 |
最近记录: |