Extjs4 Tree Grid 综合示例(展开、编辑列、获取数据)

用json数据模拟后端传回来的结果,Extjs tree支持两种类型的结构,一种是带children属性的嵌套式的数据,一种是扁平的,每条记录带pid的数据,带pid的添加配置项可以自动解析成树形结构。
{
"text": "根目录",
"children": [
{
"id": "1",
"name": "基础设置",
"children": [
{
"id": "1-1",
"name": "部门档案",
"total": 3,
"children": [
{
"id": "1-1-1",
"name": "增加部门",
"nd": "1"
}, {
"id": "1-1-2",
"name": "修改部门"
}
]
}, {
"id": "1-2",
"name": "客户档案",
"nd": "2",
"total": 1,
"children": [
{
"id": "1-2-1",
"name": "增加客户"
}, {
"id": "1-2-2",
"name": "客户设置"
}
]
}
]
}, {
"id": "2",
"name": "综合业务",
"children": [
{
"id": "2-1",
"name": "凭证",
"nd": "1",
"total": 3,
"children": [
{
"id": "2-1-1",
"name": "填制凭证"
}, {
"id": "2-1-2",
"name": "凭证审核"
}
]
}, {
"id": "2-2",
"name": "采购",
"nd": "3",
"total": 1,
"children": [
{
"id": "2-2-1",
"name": "采购订单"
}, {
"id": "2-2-2",
"name": "采购结算"
}
]
}
]
}
]
}
Tree grid代码
Ext.require([ 'Ext.form.*', 'Ext.tip.QuickTipManager' ]);
Ext.onReady(function() {
Ext.define('myTreeModel', {
extend : 'Ext.data.Model',
idProperty: 'id',
fields : [
{name : 'id'},
{name : 'name'},
{name : 'nd'},
{name : 'total'},
]
});
// tree组件要求数据的叶子节点必须有leaf=true,此函数递归tree数据检查和自动添加leaf=true
function recursiveSetLeaf(treeNode) {
if (treeNode.children) {
console.log('当前节点有children');
Ext.each(treeNode.children, function(child){
recursiveSetLeaf(child);
});
} else {
console.log('当前节点为末级节点');
treeNode.leaf = true;
}
}
// 创建grid
var sdPaperRules = Ext.create('Ext.tree.Panel', {
id : "sdPaperRules",
store : new Ext.data.TreeStore({
model: "myTreeModel",
proxy: {
type: 'ajax',
url: '/exam_admin/admin/service/gkpapers_rule/tree_grid_test.json',
extractResponseData(response) {
// 非pid
/**
* 如果是扁平的带pid的记录,可参考
* http://t.zoukankan.com/love-omnus-p-4196603.html
*
*/
// var json = Ext.loadFilter(Ext.JSON.decode(response.responseText),{parentField : 'pid'});
console.log('response', response);
var rootNode = Ext.JSON.decode(response.responseText);
recursiveSetLeaf(rootNode);
response.responseText = Ext.JSON.encode(rootNode);
return response
},
},
folderSort: true
}),// 指定数据源
// 可编辑单元格插件,配置此插件后就可以在列配置中启用列的编辑
plugins: Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit : 1,
}),
viewConfig: {
// 给表格行添加样式
getRowClass(record, rowIndex, rowParams, store){
if (rowIndex % 2 !== 0) {
return "treegrid-row-style-even"; // 给偶数行设置样式
}
}
},
autoScroll : true,
bodyStyle : 'overflow-x:auto; overflow-y:auto',
autoHeight : true,
autoWidth : true,
rootVisible: false,
// border : true,
columns : [
{
xtype : 'treecolumn',
text : "功能点",
width : 250,
dataIndex : 'name',
headersDisabled : true,
menuDisabled : true,
editable: false
},
{
dataIndex: 'nd',
text: '难度',
width : 250,
// flex: 1,
align: 'left',
headersDisabled : true,
menuDisabled : true,
renderer(value, metaData, record, rowIndex, colIndex, store, view) {
if (!value) return;
var html = '';
html += `<div style="display:flex;justify-content: flex-start;align-items: center;">`;
var radioOptions = [{ "value": "1", "label": "简单" }, { "value": "2", "label": "普通" }, { "value": "3", "label": "困难" }];
for (option of radioOptions) {
// console.log('option', option);
var checked = option.value == value ? `checked='checked'` : '';
var name = "grid_column_radio_" + record.data.id;
var domId = 'radio_' + record.data.id + '_' + option.value;
html += `<div style="display:flex;justify-content: center;align-items: center;margin-right:16px;">`;
html += ` <input id="${domId}" name='${name}' type='radio' ${checked} value='${option.value}'/>`;
html += ` <label for="${domId}"> ${option.label}</label>`;
html += `</div>`;
}
html += `</div>`;
return html;
}
},
{
text : "数量",
width : 100,
dataIndex : 'total',
headersDisabled : true,
menuDisabled : true,
border: 1,
editor : {
xtype : 'textfield'
}
}
],
listeners: {
beforeitemcollapse() {
console.log('beforeitemcollapse');
return false; // 禁止收缩节点
},
itemclick(treePanel, record, rowTag, rowIndex, event) {
// 处理单选按钮选择事件
var radio = event.getTarget('input[type="radio"]');
if (radio) {
console.log('要更改的nd', radio.value);
record.set({nd: radio.value});
}
},
beforeedit(treePanel, cell, events) {
console.log('record', cell.record.data);
if (!cell.record.data.nd) { // 如果当前节点没有难度设置,则禁止编辑
return false;
}
}
},
bbar : Ext.create("Ext.toolbar.Toolbar", {
items: [
{
xtype: 'button',
text: '获取结果数据',
handler() {
getTreeGridData(sdPaperRules.getRootNode());
// console.log('1:1', sdPaperRules.getView().getCell(1, 1));
// Ext.encode(record.data)
// 好像grid有个dirty属性,判断修改过没有,可以把有修改的record过滤出来
}
},
{
xtype : 'tbtext',
text: 'test...<span style="color:red;">lsdjfoiej</span>'
}
]
})
});
window.getTreeGridData = function(node) {
// console.log('node', node);
if (node.data.nd) {
console.log('nd', node.data.nd)
}
if (node.childNodes) {
for (n of node.childNodes) {
getTreeGridData(n);
}
}
}
// 获得当前选中的tab,下面将向这个tab添加模块组件
var tab = Ext.getCmp("treeGridTest");
// 展开所有节点
sdPaperRules.expandAll();
// 向tab里添加一个按钮
tab.add(sdPaperRules);
});
由于Extjs的Tree组件和grid结合的话,默认情况数据行没有样式,在多列情况下,不易区分当前单元格属于哪一样。因此需要添加全局样式控制补充效果。
.treegrid-row-style-even .x-grid-cell {
border-top: 1px solid #ededed;
border-bottom: 1px solid #ededed;
background-color: #fafafa;
}
.treegrid-row-style-even:hover .x-grid-cell {
background-color: #ededed;
}
Extjs4 Tree Grid 综合示例(展开、编辑列、获取数据)的更多相关文章
- ExtJs4之Grid详细
ExtJs博客前奏 由于这段时间事情比较杂乱,博客就主要以项目中例子来说明编写. ExtJs4中的Grid非常强大,有展示,选中,搜索,排序,编辑,拖拽等基本功能,这篇博客我就这几个功能做写累述. 1 ...
- ExtJS4.2学习(七)EditorGrid可编辑表格(转)
鸣谢地址:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-14/176.html ------------- ...
- 图解DataGridView编辑列
WinForm中DataGridView功能强大,除了可以自动绑定数据源外,还可以根据需求编辑列.下面以截图说明添加编辑列的步骤(HoverTreeSCJ 项目实际界面). 1.选择DataGridV ...
- oracle+servlet+extjs4 分页表格布局示例代码
Log.java package com.example.entity; import java.util.Date; public class Log { private int id; priva ...
- Spring MVC 学习总结(四)——视图与综合示例
一.表单标签库 1.1.简介 从Spring2.0起就提供了一组全面的自动数据绑定标签来处理表单元素.生成的标签兼容HTML 4.01与XHTML 1.0.表单标签库中包含了可以用在JSP页面中渲染H ...
- C#与数据库访问技术总结(七)综合示例
综合示例 说明:前面介绍了那么多,光说不练假把式,还是做个实例吧. 表:首先你要准备一张表,这个自己准备吧.我们以学生表为例. 1.ExecuteScalar方法 ExecuteScalar方法执行返 ...
- 前端MVC Vue2学习总结(一)——MVC与vue2概要、模板、数据绑定与综合示例
一.前端MVC概要 1.1.库与框架的区别 框架是一个软件的半成品,在全局范围内给了大的约束.库是工具,在单点上给我们提供功能.框架是依赖库的.Vue是框架而jQuery则是库. 1.2.AMD与CM ...
- LayUI后台管理与综合示例
一.LayUI介绍 layui(谐音:类UI) 是一款采用自身模块规范编写的前端 UI 框架,遵循原生 HTML/CSS/JS 的书写与组织形式,门槛极低,拿来即用.其外在极简,却又不失饱满的内在,体 ...
- 分享我基于NPOI+ExcelReport实现的导入与导出EXCEL类库:ExcelUtility (续2篇-模板导出综合示例)
自ExcelUtility类推出以来,经过项目中的实际使用与不断完善,现在又做了许多的优化并增加了许多的功能,本篇不再讲述原理,直接贴出示例代码以及相关的模板.结果图,以便大家快速掌握,另外这些示例说 ...
- 在ASPxGridView的主从表显示中,有什么属性可以只让其每次选择只展开一列?
在ASPxGridView的主从表显示中,有什么属性可以只让其每次选择只展开一列?(效果图如下:): 在ASPxGridView的主从表显示中,有什么属性可以只让其每次选择只展开一列(效果图) 实现该 ...
随机推荐
- Axure RP Extension for Chrome 0.6.2安装和详解
1.当我们用网页访问一个本地页面时就会出现这种问题,提示你要安装浏览器的扩展程序包,以下有搜狗浏览器如何安装,qq浏览器
- springboot的websocket因IP问题无法连接
首先遇到这个问题有点奇葩,出现在项目上线时的客户现场,头两天一直都无法确定原因,因为它的表现方式很奇怪,基于springboot实现的websocket,同样的代码在公司研发环境不会有问题,客户现场会 ...
- Navicat Premium 16 永久破解激活
Navicat premium是一款数据库管理工具,是一个可多重连线资料库的管理工具,它可以让你以单一程式同时连线到 MySQL.SQLite.Oracle 及 PostgreSQL 资料库,让管理不 ...
- Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hive.DELETEME1643159643943' doesn't exist
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hive.DELETEME1643159643 ...
- mxnet的broadcast_power() 注释错误
用relationnet时,发现broadcast_power()的源码中的注释如下: 官方文档中的注释如下: 怎么算都算不出它这个结果... 自己用mxnet实验了一把,发现是注释错了,代码如下:
- AttributeError: module 'torch._six' has no attribute 'PY3'
修改:进到torch._six源码,看看里面是PY的哪个对象,修改成这对象名试试 _six.py 即将PY3修改为PY37
- Python学习笔记--文件的相关操作
文件的读取操作 读操作 实现: read()--读完 read(10)--读取10个字节 readline()--将所有行并到一行输出 readlines()--一次读取一行 文件的关闭: 实现: 上 ...
- 孙勇男:实时视频 SDK 黑盒测试架构丨Dev for Dev 专栏
Dev for Dev 专栏全称为 Developer for Developer,该专栏是声网与 RTC 开发者社区共同发起的开发者互动创新实践活动.透过工程师视角的技术分享.交流碰撞.项目共建等多 ...
- java选择结构-switch
java选择结构-switch java的另一个多选择结构switch-case case中的value为常数值. 不加break,会一直执行到最后,包括default(case穿透) switch( ...
- StyleGAN 调整面部表情,让虚拟人脸更生动
目录 人脸表情 调整步骤 调整结果 人脸表情 通过上一篇文章 StyleGAN 生成的人脸:https://www.cnblogs.com/tinygeeker/p/17236264.html 人脸图 ...