vue-table-with-tree-grid-树形表格组件

vue-table-with-tree-grid-树形表格组件

目录




内容

1、简介

  • 应用场景:需要展示表格数据,表格数据中有分级或者树形结构的数据。
  • 效果图示1-1: [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-unRzmb5b-1597763989457)(./images/2020-08-18_vue-table-with-tree-grid.png)]

官方地址:https://github.com/MisterTaki/vue-table-with-tree-grid,有详细使用示例。

2、详解

2.1、table 常用属性

属性名类型参数默认描述
dataarray-[]表格要展示的数据
columnsarray-[]表格列配置,对应数据中对象中的key
show-indexboolean-true是否显示索引
index-textstring-‘序号’索引列列名
stripeboolean-false是否显示斑马纹
borderboolean-false是否显示纵向边框
show-row-hoverboolean-true鼠标悬停时,是否高亮当前行

2.2、columns 配置

属性类型默认值说明
labelstring‘’列标题名称
propstring‘’对应列内容的属性名 ,与data数组中对象key对应
typestring‘’列类型,默认文本,可选’template’(自定义模板)
templatestring‘’列类型为 ‘template’(自定义列模板) 时,对应的作用域插槽(它可以获取到 row, rowIndex, column, columnIndex)名称

3、示例

  • 效果图示3-1同1-1

  • 源代码3-1:

      <template>
      	...
      	<tree-table
      		class="tb-cate"
      		index-text="#"
      		show-index
      		stripe
      		border
      		:data="cateList"
      		:columns="columns"
      		:expand-type="false"
      		:selection-type="false"
      	  >
      		<template slot="isok" slot-scope="scope">
      		  <i class="el-icon-success" v-if="scope.row.effective" style="color: lightGreen"></i>
      		  <i class="el-icon-error" v-else style="color: red"></i>
      		</template>
      		<template slot="level" scope="scope">
      		   <el-tag type="primary" effect="plain" size="mini" v-if="scope.row.level === 1">一级</el-tag>
      		   <el-tag type="success" effect="plain" size="mini" v-else-if="scope.row.level === 2">二级</el-tag>
      		   <el-tag type="warning" effect="plain" size="mini" v-else>三级</el-tag>
      		</template>
      		<template slot="opt" scope="scope">
      			<el-button type="primary" icon="el-icon-edit" size="mini">编辑</el-button>
      			<el-button type="danger" icon="el-icon-delete" size="mini">删除</el-button>
      		</template>
      	  </tree-table>
      	...
      </template>
      <script>
      	...
      	export default {
        data() {
      	return {
      	  cateList: [],
      	  columns: [
      		{ label: "分类名称", prop: "name" },
      		{
      		  label: "是否有效",
      		  prop: "effective",
      		  type: "template",
      		  template: "isok",
      		},
      		{
      		  label: "分类等级",
      		  prop: "level",
      		  type: "template",
      		  template: "level"
      		},
      		{
      			label: '操作',
      			type: 'template',
      			template: 'opt'
      		}
      	],
      	props: {
      		expandType: false,
      		selectionType: false,
      	  },
      	...
      	methods: {
      	getCateList() {
      	  this.$http.get("/category/page", { params: this.query }).then((resp) => {
      		this.total = resp.total;
      		this.cateList = resp.items;
      		console.log(resp);
      	  });
      	},
      </script>
    

完整页码代码参考博文‘全栈项目-乐优商场-分类管理-前端-页面渲染’。

后记

本项目为参考某马视频开发,相关视频及配套资料可自行度娘或者联系本人。上面为自己编写的开发文档,持续更新。欢迎交流,本人QQ:806797785

前端项目源代码地址:https://gitee.com/gaogzhen/leyou_bms    // 前端后台管理系统
后端JAVA源代码地址:https://gitee.com/gaogzhen/leyou-backend        // 后端项目
  • 5
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 31
    评论
treegrid插件 当前选中的行: var config = { id: "tg1", width: "800", renderTo: "div1", headerAlign: "left", headerHeight: "30", dataAlign: "left", indentation: "20", folderOpenIcon: "images/folderOpen.gif", folderCloseIcon: "images/folderClose.gif", defaultLeafIcon: "images/defaultLeaf.gif", hoverRowBackground: "false", folderColumnIndex: "1", itemClick: "itemClickEvent", columns:[ {headerText: "", headerAlign: "center", dataAlign: "center", width: "20", handler: "customCheckBox"}, {headerText: "名称", dataField: "name", headerAlign: "center", handler: "customOrgName"}, {headerText: "拼音码", dataField: "code", headerAlign: "center", dataAlign: "center", width: "100"}, {headerText: "负责人", dataField: "assignee", headerAlign: "center", dataAlign: "center", width: "100"}, {headerText: "查看", headerAlign: "center", dataAlign: "center", width: "50", handler: "customLook"} ], data:[ {name: "城区分公司", code: "CQ", assignee: "", children:[ {name: "城区卡品分销中心"}, {name: "先锋服务厅", children:[ {name: "chlid1"}, {name: "chlid2"}, {name: "chlid3", children: [ {name: "chlid3-1"}, {name: "chlid3-2"}, {name: "chlid3-3"}, {name: "chlid3-4"} ]} ]}, {name: "半环服务厅"} ]}, {name: "清新分公司", code: "QX", assignee: "", children:[]}, {name: "英德分公司", code: "YD", assignee: "", children:[]}, {name: "佛冈分公司", code: "FG", assignee: "", children:[]} ] }; /* 单击数据行后触发该事件 id:行的id index:行的索引。 data:json格式的行数据对象。 */ function itemClickEvent(id, index, data){ window.location.href="ads"; } /* 通过指定的方法来自定义栏数据 */ function customCheckBox(row, col){ return ""; } function customOrgName(row, col){ var name = row[col.dataField] || ""; return name; } function customLook(row, col){ return "查看"; } //创建一个组件对象 var treeGrid = new TreeGrid(config); treeGrid.show(); /* 展开、关闭所有节点。 isOpen=Y表示展开,isOpen=N表示关闭 */ function expandAll(isOpen){ treeGrid.expandAll(isOpen); } /* 取得当前选中的行,方法返回TreeGridItem对象 */ function selectedItem(){ var treeGridItem = treeGrid.getSelectedItem(); if(treeGridItem!=null){ //获取数据行属性值 //alert(treeGridItem.id + ", " + treeGridItem.index + ", " + treeGridItem.data.name); //获取父数据行 var parent = treeGridItem.getParent(); if(parent!=null){ //jQuery("#currentRow").val(parent.data.name); } //获取子数据行集 var children = treeGridItem.getChildren(); if(children!=null && children.length>0){ jQuery("#currentRow").val(children[0].data.name); } } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 31
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gaog2zh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值