Vue+abp树形表格

使用方法

首先安装插件

yarn add vue-table-with-tree-grid

在页面中引用

<template>
    <zk-table
        ref="table"
        sum-text="sum"
        index-text="#"
        :data="listdata"
        :columns="columns"
        :stripe="props.stripe"
        :border="props.border"
        :show-header="props.showHeader"
        :show-summary="props.showSummary"
        :show-row-hover="props.showRowHover"
        :show-index="props.showIndex"
        :tree-type="props.treeType"
        :is-fold="props.isFold"
        :expand-type="props.expandType"
        :selection-type="props.selectionType"
    >
        <template slot="selectChk" scope="scope">
        <Checkbox v-model="chkmodel(scope.row).isChecked"></Checkbox>
        </template>
    </zk-table>
</template>
<script lang="ts">
import { Component, Vue, Inject, Prop, Watch } from "vue-property-decorator";
import util from "@/lib/util";
import PageRequest from "@/store/entities/page-request";
import AbpBase from "@/lib/abpbase";
import ZkTable from "vue-table-with-tree-grid";
Vue.use(ZkTable);
export default class xxx extends AbpBase{
  props: any = {
    stripe: true, //是否显示间隔斑马纹
    border: true, //是否显示纵向边框
    showHeader: true, //是否显示表头
    showSummary: false, //是否显示表尾合计行
    showRowHover: true, //鼠标悬停时,是否高亮当前行
    showIndex: false, //是否显示数据索引
    treeType: true, //是否为树形表格
    isFold: false, //树形表格中父级是否默认折叠
    expandType: false, //是否为展开行类型表格(为 True 时,需要添加作用域插槽, 它可以获取到 row, rowIndex)
    selectionType: false //是否为多选类型表格
  };
  listdata: any = [];
  get list() {
    return this.listdata;
    //********这里不能直接用vuex的数据做属性,更新了数据界面不会跟新********
    //return this.$store.state.xxx.List;
  }
   async search() {
    request={};
    console.log(this.request)
    await this.$store.dispatch({
      type: "xxx/getList",
      data: request
    });
    this.listdata = this.$store.state.xxx.List;
  }
    chkmodel(row) {
    return this.getChkModel(row.id, this.listdata);
  }
  getChkModel(id, ls: Array<any>) {
    for (let index = 0; index < ls.length; index++) {
      const element = ls[index];
      if (element.id == id) {
        return element;
      }
      if (!!element.children) {
        let c = this.getChkModel(id, element.children);
        if (!!c) {
          return c;
        }
      }
    }
  }
columns = [
    // {
    //   label: "名称",
    //   type: "template",
    //   width: "100px",
    //   template: "namede"
    // },
    {
      label: "名称",
      prop: "name",
      resizable: true
    },
    {
      label: "类型",
      prop: "typeName"
    },
    {
      label: "选中",
      type: "template",
      width: "100px",
      template: "selectChk"
    }
  ];
}
</script>

嗯,就这样


参考资料

posted @ 2019-12-14 13:16  地对地捣蛋的大号  阅读(596)  评论(0编辑  收藏  举报
c#/.net core