# RenderTable 表格

集成分页的 table 组件, 支持 jp-table 组件的功能

提示

因为分页组件封装到 table 内部,所以请查看 demo 注意网络请求的方式

1、调用 rendertable 内部reset方法,触发回调函数load

2、load函数返回分页信息(pageNum, pageSize),调用接口

# 基础用法

本示例关注:文本过长,tooltip展示, slot的使用,type='money' 的效果,具体看 demo.

showToolbar 控制是否显示 toolbar

暂无数据

自动计算高度测试

<template>
  <div>
    <jp-render-table
      :max-height="300"
      ref="table"
      v-loading="loading"
      :data="tableData"
      :columns="tableColumns"
      @load="doLoad"
      :total="100"
      @row-click="doRowClick"
      :visibleCloumns="visibleCloumns"
      :sortColumn="true"
    >
      <jp-table-column label="单号" slot="order" min-width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <jp-number-copy v-if="scope" code="121232323233221888888212"></jp-number-copy>
        </template>
      </jp-table-column>

      <jp-table-column label="操作" slot="opration" width="180">
        <template slot-scope="scope">
          <jp-button type="primary" size="small">编辑({{ scope.$index }})</jp-button>
          <jp-button type="danger" size="small">删除</jp-button>
        </template>
      </jp-table-column>
    </jp-render-table>
    <h4>自动计算高度测试</h4>
    <jp-render-table
      ref="table"
      :data="[{ code: '1', name: '测试名称', owner: '货主名称', barcode: 0, money: 12 }]"
      :columns="tableColumns"
      @load="doLoad"
      :total="100"
      :startMinHeight="false"
      :visibleCloumns="visibleCloumns"
      id="mytable"
      :calcHeight="true"
    >
      <jp-table-column label="单号" slot="order" width="120">
        <template slot-scope="scope">
          <jp-number-copy
            v-if="scope"
            code="很长-换号-很长-换号很长-换号很长-换号很长-换号很长-换号很长-换号很长-换号很长-换号很长-换号"
          ></jp-number-copy>
        </template>
      </jp-table-column>

      <jp-table-column label="操作" slot="opration" width="180">
        <template slot-scope="scope">
          <jp-button type="primary" size="small">编辑({{ scope.$index }})</jp-button>
          <jp-button type="danger" size="small">删除</jp-button>
        </template>
      </jp-table-column>
    </jp-render-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      tableColumns: [],
      visibleCloumns: []
    }
  },
  mounted() {
    this.setupColumns()
    this.loadData()

    setTimeout(() => {
      // console.log(JSON.stringify(this.$refs.table.allColumns))
      // this.visibleCloumns = [
      //   { key: 0, label: '序号', visible: true },
      //   { key: 1, label: '单号', visible: false },
      //   { key: 2, label: '商品编码', visible: true },
      //   { key: 3, label: '商品名称', visible: true },
      //   { key: 4, label: '货主', visible: true },
      //   { key: 5, label: '商品条码', visible: true },
      //   { key: 6, label: '价格type=money', visible: false },
      //   { key: 7, label: '操作', visible: false }
      // ]
    }, 5000)
  },
  methods: {
    doRowClick(data) {
      console.log(data)
    },
    setupColumns() {
      this.tableColumns = [
        { type: 'index', label: '序号', width: 60 },
        { slot: 'order', label: '单号' },
        { prop: 'code', label: '商品编码' },
        { prop: 'name', label: '商品名称' },
        { prop: 'owner', label: '货主' },
        { prop: 'barcode', label: '商品条码' },
        { prop: 'money', label: '价格type=money', type: 'money' },
        { slot: 'opration', label: '操作' }
      ]
    },
    loadData() {
      this.$refs.table.reset()
    },
    doLoad(params) {
      console.log(params)
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.tableData = [
          { code: '1', name: '测试名称', owner: '货主名称', barcode: 0, money: 12 },
          { code: '12', name: '测试名称22222223333333333333333334', owner: '货主名称1', barcode: '22222', money: 0 },
          { code: '13', name: '测试名称3', owner: '货主名称2', barcode: '', money: 123456 },
          { code: '14', name: '测试名称4', owner: '货主名称3', barcode: '444444', money: 12454444444 },
          { code: '15', name: '测试名称5', owner: '货主名称4', barcode: '5555555', money: 1244 },
          { code: '16', name: '测试名称6', owner: '货主名称5', barcode: '66666666666666666', money: 12222222 }
        ]
      }, 1000)
    }
  }
}
</script>
显示代码

# 固定列

关注 slot 的固定列和传参中的固定列, 同时演示了type: selection

暂无数据

<template>
  <div>
    <jp-render-table
      ref="table"
      v-loading="loading"
      :data="tableData"
      :columns="tableColumns"
      @load="doLoad"
      :total="100"
      @selection-change="handleSelectionChange"
      :row-key="(row) => row.code"
    >
      <jp-table-column label="操作" slot="opration" fixed="right" width="180">
        <template slot-scope="scope">
          <jp-button type="primary" size="mini">编辑({{ scope.$index }})</jp-button>
          <jp-button type="danger" size="mini">删除</jp-button>
        </template>
      </jp-table-column>
    </jp-render-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      tableColumns: []
    }
  },
  mounted() {
    this.setupColumns()
    this.loadData()
  },
  methods: {
    handleSelectionChange(val) {
      console.log(val)
    },
    setupColumns() {
      this.tableColumns = [
        { type: 'selection', label: '', width: 60, 'reserve-selection': true },
        { prop: 'code', label: '商品编码' },
        { prop: 'name', label: '商品名称' },
        { prop: 'owner', label: '货主' },
        { prop: 'barcode', label: '商品条码' },
        { prop: 'barcode1', label: '商品条码1' },
        { prop: 'barcode2', label: '商品条码2' },
        { prop: 'barcode3', label: '商品条码3' },
        { prop: 'barcode4', label: '商品条码4' },
        { prop: 'barcode5', label: '商品条码5' },
        { prop: 'barcode6', label: '商品条码6' },
        { prop: 'barcode7', label: '商品条码7' },
        { prop: 'barcode8', label: '商品条码8' },
        { prop: 'barcode9', label: '商品条码99' },
        { prop: 'barcode10', label: '商品条码10' },
        { prop: 'barcode11', label: '商品条码11', fixed: 'right' },
        { slot: 'opration', label: '操作' }
      ]
    },
    loadData() {
      this.$refs.table.reset()
    },
    doLoad(params) {
      console.log(params)
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.tableData = [
          { code: `1${params.pageNum}`, name: '测试名称', owner: '货主名称', barcode: '121212', barcode11: 'text' },
          { code: `2${params.pageNum}`, name: '测试名称22222223333333333333333334', owner: '货主名称1', barcode: '22222', barcode11: 'text2' },
          { code: `3${params.pageNum}`, name: '测试名称3', owner: '货主名称2', barcode: '333333', barcode11: 'text3' },
          { code: `4${params.pageNum}`, name: '测试名称4', owner: '货主名称3', barcode: '444444', barcode11: 'text4' },
          { code: `5${params.pageNum}`, name: '测试名称5', owner: '货主名称4', barcode: '5555555', barcode11: 'text5' },
          { code: `6${params.pageNum}`, name: '测试名称6', owner: '货主名称5', barcode: '66666666666666666', barcode11: 'text6' }
        ]
      }, 1000)
    }
  }
}
</script>
显示代码

# table 顶部的按钮和嵌套 table

slot=action

smallPagination小型分页的分页样式不可自定义

暂无数据

smallPagination 控制展示小型分页

<template>
  <div>
    <jp-render-table ref="table" v-loading="loading" :data="tableData" :columns="tableColumns" @load="doLoad" :total="100" @row-click="doRowClick">
      <div slot="action" class="action-wrapper">
        <jp-button type="primary" size="small" @click="doAdd">新增</jp-button>
        <jp-button type="danger" size="small">导入</jp-button>
      </div>
      <jp-table-column label="操作" slot="opration" width="180">
        <template slot-scope="scope">
          <jp-button type="primary" size="small">编辑({{ scope.$index }})</jp-button>
          <jp-button type="danger" size="small">删除</jp-button>
        </template>
      </jp-table-column>
    </jp-render-table>

    <jp-dialog title="收货地址" :visible.sync="dialogTableVisible">
      <jp-render-table
        smallPagination
        ref="table2"
        v-loading="loading"
        :data="tableData"
        :columns="tableColumns"
        @load="doLoad"
        :total="100"
      ></jp-render-table>
    </jp-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dialogTableVisible: false,
      loading: false,
      tableData: [],
      tableColumns: []
    }
  },
  mounted() {
    this.setupColumns()
    this.loadData()
  },
  methods: {
    doAdd() {
      this.dialogTableVisible = true
    },
    doRowClick(data) {
      console.log(data)
    },
    setupColumns() {
      this.tableColumns = [
        { type: 'index', label: '序号', width: 60 },
        { prop: 'code', label: '商品编码' },
        { prop: 'name', label: '商品名称' },
        { prop: 'owner', label: '货主' },
        { prop: 'barcode', label: '商品条码' },
        { prop: 'money', label: '价格type=money', type: 'money' },
        { slot: 'opration', label: '操作' }
      ]
    },
    loadData() {
      this.$refs.table.reset()
    },
    doLoad(params) {
      console.log(params)
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.tableData = [
          { code: '1', name: '测试名称', owner: '货主名称', barcode: '121212', money: 12 },
          { code: '12', name: '测试名称22222223333333333333333334', owner: '货主名称1', barcode: '22222', money: 1234 },
          { code: '13', name: '测试名称3', owner: '货主名称2', barcode: '333333', money: 123456 },
          { code: '14', name: '测试名称4', owner: '货主名称3', barcode: '444444', money: 12454444444 },
          { code: '15', name: '测试名称5', owner: '货主名称4', barcode: '5555555', money: 1244 },
          { code: '16', name: '测试名称6', owner: '货主名称5', barcode: '66666666666666666', money: 12222222 }
        ]
      }, 1000)
    }
  }
}
</script>
<style scoped>
.action-wrapper {
  margin-bottom: 12px;
}
</style>
显示代码

# 多列效果

数据较多的效果

暂无数据

<template>
  <div>
    <jp-render-table
      ref="table"
      v-loading="loading"
      :data="tableData"
      :columns="tableColumns"
      @load="doLoad"
      :total="100"
      @selection-change="handleSelectionChange"
      :row-key="(row) => row.code"
    >
      <div slot="action">
        <jp-button type="primary" size="mini" @click="doAdd">新增一列</jp-button>
        <jp-button type="danger" size="mini" @click="doReduce">减少一列</jp-button>
      </div>
    </jp-render-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      tableColumns: []
    }
  },
  mounted() {
    this.setupColumns()
    this.loadData()
  },
  methods: {
    doAdd() {
      this.tableColumns.push({ prop: 'barcode', label: '商品条码商品条码商品条码商品条码商品条码' })
    },
    doReduce() {
      this.tableColumns.pop()
    },
    handleSelectionChange(val) {
      console.log(val)
    },
    setupColumns() {
      this.tableColumns = [
        { type: 'selection', label: '', width: 60, 'reserve-selection': true },
        { prop: 'code', label: '商品编码' },
        { prop: 'name', label: '商品名称' },
        { prop: 'owner', label: '货主' },
        { prop: 'barcode', label: '商品条码' }
      ]
    },
    loadData() {
      this.$refs.table.reset()
    },
    doLoad(params) {
      console.log(params)
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.tableData = [
          { code: `1${params.pageNum}`, name: '测试名称', owner: '货主名称', barcode: '121212', barcode11: 'text' },
          { code: `2${params.pageNum}`, name: '测试名称22222223333333333333333334', owner: '货主名称1', barcode: '22222', barcode11: 'text2' },
          { code: `3${params.pageNum}`, name: '测试名称3', owner: '货主名称2', barcode: '333333', barcode11: 'text3' },
          { code: `4${params.pageNum}`, name: '测试名称4', owner: '货主名称3', barcode: '444444', barcode11: 'text4' },
          { code: `5${params.pageNum}`, name: '测试名称5', owner: '货主名称4', barcode: '5555555', barcode11: 'text5' },
          { code: `6${params.pageNum}`, name: '测试名称6', owner: '货主名称5', barcode: '66666666666666666', barcode11: 'text6' }
        ]
      }, 1000)
    }
  }
}
</script>
显示代码

# 排序和展开收起

演示下排序和展开收起

暂无数据

<template>
  <div>
    <jp-render-table ref="table" v-loading="loading" :data="tableData" :columns="tableColumns" @load="doLoad" :total="100">
      <template slot="expand">
        <jp-table-column type="expand">
          <template slot-scope="props">
            <jp-form label-position="left" inline class="demo-table-expand">
              <jp-form-item label="商品名称">
                <span>{{ props.row.code }}</span>
              </jp-form-item>
              <jp-form-item label="所属店铺">
                <span>{{ props.row.name }}</span>
              </jp-form-item>
              <jp-form-item label="商品 ID">
                <span>{{ props.row.owner }}</span>
              </jp-form-item>
              <jp-form-item label="店铺 ID">
                <span>{{ props.row.barcode }}</span>
              </jp-form-item>
            </jp-form>
          </template>
        </jp-table-column>
      </template>
    </jp-render-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      tableColumns: []
    }
  },
  mounted() {
    this.setupColumns()
    this.loadData()
  },
  methods: {
    setupColumns() {
      this.tableColumns = [
        { slot: 'expand' },
        { prop: 'code', label: '商品编码', sortable: true },
        { prop: 'name', label: '商品名称', sortable: true },
        { prop: 'owner', label: '货主', sortable: true },
        { prop: 'barcode', label: '商品条码' }
      ]
    },
    loadData() {
      this.$refs.table.reset()
    },
    doLoad(params) {
      console.log(params)
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.tableData = [
          { code: `1${params.pageNum}`, name: '测试名称', owner: '货主名称', barcode: '121212', barcode11: 'text' },
          { code: `2${params.pageNum}`, name: '测试名称22222223333333333333333334', owner: '货主名称1', barcode: '22222', barcode11: 'text2' },
          { code: `3${params.pageNum}`, name: '测试名称3', owner: '货主名称2', barcode: '333333', barcode11: 'text3' },
          { code: `4${params.pageNum}`, name: '测试名称4', owner: '货主名称3', barcode: '444444', barcode11: 'text4' },
          { code: `5${params.pageNum}`, name: '测试名称5', owner: '货主名称4', barcode: '5555555', barcode11: 'text5' },
          { code: `6${params.pageNum}`, name: '测试名称6', owner: '货主名称5', barcode: '66666666666666666', barcode11: 'text6' }
        ]
      }, 1000)
    }
  }
}
</script>
显示代码

# 单选

单选

暂无数据

<template>
  <div>
    <jp-render-table
      ref="table"
      v-loading="loading"
      :data="tableData"
      :columns="tableColumns"
      @load="doLoad"
      :total="100"
      :radioValue="radioValue"
      @current-change="clickChange"
      :row-key="(row) => row.code"
    ></jp-render-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      radioValue: {},
      loading: false,
      tableData: [],
      tableColumns: []
    }
  },
  mounted() {
    this.setupColumns()
    this.loadData()
  },
  methods: {
    clickChange(val) {
      console.log(val)
      this.radioValue = val
    },
    setupColumns() {
      this.tableColumns = [
        { type: 'radio', value: '' },
        { prop: 'code', label: '商品编码' },
        { prop: 'name', label: '商品名称' },
        { prop: 'owner', label: '货主' },
        { prop: 'barcode', label: '商品条码' }
      ]
    },
    loadData() {
      this.$refs.table.reset()
    },
    doLoad(params) {
      console.log(params)
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.tableData = [
          { code: `1${params.pageNum}`, name: '测试名称', owner: '货主名称', barcode: '121212', barcode11: 'text' },
          { code: `2${params.pageNum}`, name: '测试名称22222223333333333333333334', owner: '货主名称1', barcode: '22222', barcode11: 'text2' },
          { code: `3${params.pageNum}`, name: '测试名称3', owner: '货主名称2', barcode: '333333', barcode11: 'text3' },
          { code: `4${params.pageNum}`, name: '测试名称4', owner: '货主名称3', barcode: '444444', barcode11: 'text4' },
          { code: `5${params.pageNum}`, name: '测试名称5', owner: '货主名称4', barcode: '5555555', barcode11: 'text5' },
          { code: `6${params.pageNum}`, name: '测试名称6', owner: '货主名称5', barcode: '66666666666666666', barcode11: 'text6' }
        ]
      }, 1000)
    }
  }
}
</script>
显示代码

# tag 渲染

tag 渲染,支持默认 type-tagType,,字典dicts,使用方法见如下
默认 type defaultType
字典绑定字段 默认dictLabel,可重写
tagOptions:{dictLabel:'重写 || dictLabel'}

暂无数据

<template>
  <div>
    <jp-render-table
      ref="table"
      v-loading="loading"
      :data="tableData"
      :columns="tableColumns"
      @load="doLoad"
      :total="100"
      @current-change="clickChange"
      :row-key="(row) => row.code"
    ></jp-render-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      tableColumns: [],
      dicts3: []
    }
  },
  mounted() {
    this.setupColumns()
    this.loadData()

    setTimeout(() => {
      this.dicts3 = [
        { dictSort: 0, dictLabel: '已预约', dictValue: '00' },
        { dictSort: 1, dictLabel: '已取消', dictValue: '10' }
      ]
      // 暂时不可以使用,只能接口请求成功再渲染tablecloumn
      this.$refs.table.reloadTableCloumn('类型3', this.dicts3)
    }, 1200)
  },
  methods: {
    clickChange(val) {
      console.log(val)
    },
    setupColumns() {
      // eg1
      let dicts = {
        csp_reservation_status: {
          10: '已取消',
          '00': '已预约'
        }
      }
      // eg2
      let dicts2 = {
        csp_reservation_status: {
          10: { dictLabel: '已取消' },
          '00': { dictLabel: '已预约' }
        }
      }
      // eg3 array 限制只能使用,dictLabel,dictValue,字段,如需手写请注意

      this.tableColumns = [
        { prop: 'code', label: '商品编码' },
        { prop: 'name', label: '商品名称' },
        {
          type: 'tag',
          prop: 'owner',
          label: '类型1',
          minWidth: 150,
          tagOptions: { tagTypes: { '00': 'success', 10: 'danger' }, dicts: dicts.csp_reservation_status }
        },
        {
          type: 'tag',
          prop: 'barcode',
          label: '类型2',
          width: 80,
          tagOptions: { tagTypes: { 10: 'success', '00': 'danger' }, dicts: dicts2.csp_reservation_status }
        },
        {
          type: 'tag',
          prop: 'barcode',
          label: '类型3',
          tagOptions: { tagTypes: { 10: 'success', '00': 'danger' }, dicts: this.dicts3 }
        },
        {
          type: 'tag',
          prop: 'barcode11',
          label: '默认tag type', //未匹配则使用默认值
          tagOptions: { defaultType: 'warning', tagTypes: { 1: 'success', 0: 'danger' }, dicts: { 1: '字典1', 0: '字典0', 3: '字典3' } },
          minWidth: 150
        }
      ]
    },
    loadData() {
      this.$refs.table.reset()
    },
    doLoad(params) {
      console.log(params)
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.tableData = [
          { code: `1${params.pageNum}`, name: '测试名称4', owner: 10, barcode: 10, barcode14: 1, barcode11: '1', barcode13: '自动默认 --' },
          { code: `2${params.pageNum}`, name: '测试名称2', owner: '00', barcode: '22222', barcode14: 1, barcode11: '0', barcode13: '可设默认' },
          { code: `3${params.pageNum}`, name: '测试名称3', owner: null, barcode: 1, barcode14: 1, barcode11: '3', barcode13: '' },
          { code: `4${params.pageNum}`, name: '测试名称6', owner: 10, barcode: '00', barcode11: null, barcode14: 1, barcode13: '' }
        ]
      }, 1000)
    }
  }
}
</script>
显示代码

# 空状态

空状态

暂无数据

<template>
  <div>
    <jp-render-table
      ref="table"
      v-loading="loading"
      :data="tableData"
      :columns="tableColumns"
      @load="doLoad"
      :total="100"
      @selection-change="handleSelectionChange"
      :row-key="(row) => row.code"
    >
      <jp-table-column label="操作" slot="opration" fixed="right" width="180">
        <template slot-scope="scope">
          <jp-button type="primary" size="mini">编辑({{ scope.$index }})</jp-button>
          <jp-button type="danger" size="mini">删除</jp-button>
        </template>
      </jp-table-column>
    </jp-render-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      tableColumns: []
    }
  },
  mounted() {
    this.setupColumns()
    this.loadData()
  },
  methods: {
    handleSelectionChange(val) {
      console.log(val)
    },
    setupColumns() {
      this.tableColumns = [
        { type: 'selection', label: '', width: 60, 'reserve-selection': true },
        { prop: 'code', label: '商品编码' },
        { prop: 'name', label: '商品名称' },
        { prop: 'owner', label: '货主' },
        { prop: 'barcode', label: '商品条码' },
        { prop: 'barcode1', label: '商品条码1' },
        { prop: 'barcode2', label: '商品条码2' },
        { prop: 'barcode3', label: '商品条码3' },
        { prop: 'barcode4', label: '商品条码4' },
        { prop: 'barcode5', label: '商品条码5' },
        { prop: 'barcode6', label: '商品条码6' },
        { prop: 'barcode7', label: '商品条码7' },
        { prop: 'barcode8', label: '商品条码8' },
        { prop: 'barcode9', label: '商品条码99' },
        { prop: 'barcode10', label: '商品条码10' },
        { prop: 'barcode11', label: '商品条码11', fixed: 'right' },
        { slot: 'opration', label: '操作' }
      ]
    },
    loadData() {
      this.$refs.table.reset()
    },
    doLoad(params) {
      console.log(params)
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.tableData = []
      }, 3000)
    }
  }
}
</script>
显示代码

# Table Attributes

参数 说明 类型 可选值 默认值
data 显示的数据 array
height Table 的高度,默认为自动高度。如果 height 为 number 类型,单位 px;如果 height 为 string 类型,则这个高度会设置为 Table 的 style.height 的值,Table 的高度会受控于外部样式。 string/number
max-height Table 的最大高度。合法的值为数字或者单位为 px 的高度。 string/number
stripe 是否为斑马纹 table boolean false
border 是否带有纵向边框 boolean false
size Table 的尺寸 string medium / small / mini
fit 列的宽度是否自撑开 boolean true
show-header 是否显示表头 boolean true
highlight-current-row 是否要高亮当前行 boolean false
current-row-key 当前行的 key,只写属性 String,Number
row-class-name 行的 className 的回调方法,也可以使用字符串为所有行设置一个固定的 className。 Function({row, rowIndex})/String
row-style 行的 style 的回调方法,也可以使用一个固定的 Object 为所有行设置一样的 Style。 Function({row, rowIndex})/Object
cell-class-name 单元格的 className 的回调方法,也可以使用字符串为所有单元格设置一个固定的 className。 Function({row, column, rowIndex, columnIndex})/String
cell-style 单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有单元格设置一样的 Style。 Function({row, column, rowIndex, columnIndex})/Object
header-row-class-name 表头行的 className 的回调方法,也可以使用字符串为所有表头行设置一个固定的 className。 Function({row, rowIndex})/String
header-row-style 表头行的 style 的回调方法,也可以使用一个固定的 Object 为所有表头行设置一样的 Style。 Function({row, rowIndex})/Object
header-cell-class-name 表头单元格的 className 的回调方法,也可以使用字符串为所有表头单元格设置一个固定的 className。 Function({row, column, rowIndex, columnIndex})/String
header-cell-style 表头单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有表头单元格设置一样的 Style。 Function({row, column, rowIndex, columnIndex})/Object
row-key 行数据的 Key,用来优化 Table 的渲染;在使用 reserve-selection 功能与显示树形数据时,该属性是必填的。类型为 String 时,支持多层访问:user.info.id,但不支持 user.info[0].id,此种情况请使用 Function Function(row)/String
empty-text 空数据时显示的文本内容,也可以通过 slot="empty" 设置 String 暂无数据
default-expand-all 是否默认展开所有行,当 Table 包含展开行存在或者为树形表格时有效 Boolean false
expand-row-keys 可以通过该属性设置 Table 目前的展开行,需要设置 row-key 属性才能使用,该属性为展开行的 keys 数组。 Array
default-sort 默认的排序列的 prop 和顺序。它的prop属性指定默认的排序的列,order指定默认排序的顺序 Object order: ascending, descending 如果只指定了prop, 没有指定order, 则默认顺序是 ascending
tooltip-effect tooltip effect 属性 String dark/light
show-summary 是否在表尾显示合计行 Boolean false
sum-text 合计行第一列的文本 String 合计
summary-method 自定义的合计计算方法 Function({ columns, data })
span-method 合并行或列的计算方法 Function({ row, column, rowIndex, columnIndex })
select-on-indeterminate 在多选表格中,当仅有部分行被选中时,点击表头的多选框时的行为。若为 true,则选中所有行;若为 false,则取消选择所有行 Boolean true
indent 展示树形数据时,树节点的缩进 Number 16
lazy 是否懒加载子节点数据 Boolean
load 加载子节点数据的函数,lazy 为 true 时生效,函数第二个参数包含了节点的层级信息 Function(row, treeNode, resolve)
tree-props 渲染嵌套数据的配置选项 Object { hasChildren: 'hasChildren', children: 'children' }

# Table Events

事件名 说明 参数
select 当用户手动勾选数据行的 Checkbox 时触发的事件 selection, row
select-all 当用户手动勾选全选 Checkbox 时触发的事件 selection
selection-change 当选择项发生变化时会触发该事件 selection
cell-mouse-enter 当单元格 hover 进入时会触发该事件 row, column, cell, event
cell-mouse-leave 当单元格 hover 退出时会触发该事件 row, column, cell, event
cell-click 当某个单元格被点击时会触发该事件 row, column, cell, event
cell-dblclick 当某个单元格被双击击时会触发该事件 row, column, cell, event
row-click 当某一行被点击时会触发该事件 row, column, event
row-contextmenu 当某一行被鼠标右键点击时会触发该事件 row, column, event
row-dblclick 当某一行被双击时会触发该事件 row, column, event
header-click 当某一列的表头被点击时会触发该事件 column, event
header-contextmenu 当某一列的表头被鼠标右键点击时触发该事件 column, event
sort-change 当表格的排序条件发生变化的时候会触发该事件 { column, prop, order }
filter-change 当表格的筛选条件发生变化的时候会触发该事件,参数的值是一个对象,对象的 key 是 column 的 columnKey,对应的 value 为用户选择的筛选条件的数组。 filters
current-change 当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性 currentRow, oldCurrentRow
header-dragend 当拖动表头改变了列的宽度的时候会触发该事件 newWidth, oldWidth, column, event
expand-change 当用户对某一行展开或者关闭的时候会触发该事件(展开行时,回调的第二个参数为 expandedRows;树形表格时第二参数为 expanded) row, (expandedRows | expanded)

# Table Methods

方法名 说明 参数
clearSelection 用于多选表格,清空用户的选择
toggleRowSelection 用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中) row, selected
toggleAllSelection 用于多选表格,切换所有行的选中状态 -
toggleRowExpansion 用于可展开表格与树形表格,切换某一行的展开状态,如果使用了第二个参数,则是设置这一行展开与否(expanded 为 true 则展开) row, expanded
setCurrentRow 用于单选表格,设定某一行为选中行,如果调用时不加参数,则会取消目前高亮行的选中状态。 row
clearSort 用于清空排序条件,数据会恢复成未排序的状态
clearFilter 不传入参数时用于清空所有过滤条件,数据会恢复成未过滤的状态,也可传入由 columnKey 组成的数组以清除指定列的过滤条件 columnKey
doLayout 对 Table 进行重新布局。当 Table 或其祖先元素由隐藏切换为显示时,可能需要调用此方法
sort 手动对 Table 进行排序。参数prop属性指定排序列,order指定排序顺序。 prop: string, order: string

# Table Slot

name 说明
append 插入至表格最后一行之后的内容,如果需要对表格的内容进行无限滚动操作,可能需要用到这个 slot。若表格有合计行,该 slot 会位于合计行之上。

# Table-column Attributes

参数 说明 类型 可选值 默认值
type 对应列的类型。如果设置了 selection 则显示多选框;如果设置了 index 则显示该行的索引(从 1 开始计算);如果设置了 expand 则显示为一个可展开的按钮 string selection/index/expand
index 如果设置了 type=index,可以通过传递 index 属性来自定义索引 number, Function(index) - -
column-key column 的 key,如果需要使用 filter-change 事件,则需要此属性标识是哪个 column 的筛选条件 string
label 显示的标题 string
prop 对应列内容的字段名,也可以使用 property 属性 string
width 对应列的宽度 string
min-width 对应列的最小宽度,与 width 的区别是 width 是固定的,min-width 会把剩余宽度按比例分配给设置了 min-width 的列 string
fixed 列是否固定在左侧或者右侧,true 表示固定在左侧 string, boolean true, left, right
render-header 列标题 Label 区域渲染使用的 Function Function(h, { column, $index })
sortable 对应列是否可以排序,如果设置为 'custom',则代表用户希望远程排序,需要监听 Table 的 sort-change 事件 boolean, string true, false, 'custom' false
sort-method 对数据进行排序的时候使用的方法,仅当 sortable 设置为 true 的时候有效,需返回一个数字,和 Array.sort 表现一致 Function(a, b)
sort-by 指定数据按照哪个属性进行排序,仅当 sortable 设置为 true 且没有设置 sort-method 的时候有效。如果 sort-by 为数组,则先按照第 1 个属性排序,如果第 1 个相等,再按照第 2 个排序,以此类推 String/Array/Function(row, index)
sort-orders 数据在排序时所使用排序策略的轮转顺序,仅当 sortable 为 true 时有效。需传入一个数组,随着用户点击表头,该列依次按照数组中元素的顺序进行排序 array 数组中的元素需为以下三者之一:ascending 表示升序,descending 表示降序,null 表示还原为原始顺序 ['ascending', 'descending', null]
resizable 对应列是否可以通过拖动改变宽度(需要在 jp-table 上设置 border 属性为真) boolean true
formatter 用来格式化内容 Function(row, column, cellValue, index)
show-overflow-tooltip 当内容过长被隐藏时显示 tooltip Boolean false
align 对齐方式 String left/center/right left
header-align 表头对齐方式,若不设置该项,则使用表格的对齐方式 String left/center/right
class-name 列的 className string
label-class-name 当前列标题的自定义类名 string
selectable 仅对 type=selection 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选 Function(row, index)
reserve-selection 仅对 type=selection 的列有效,类型为 Boolean,为 true 则会在数据更新之后保留之前选中的数据(需指定 row-key Boolean false
filters 数据过滤的选项,数组格式,数组中的元素需要有 text 和 value 属性。 Array[{ text, value }]
filter-placement 过滤弹出框的定位 String 与 Tooltip 的 placement 属性相同
filter-multiple 数据过滤的选项是否多选 Boolean true
filter-method 数据过滤使用的方法,如果是多选的筛选项,对每一条数据会执行多次,任意一次返回 true 就会显示。 Function(value, row, column)
filtered-value 选中的数据过滤项,如果需要自定义表头过滤的渲染方式,可能会需要此属性。 Array

# Table-column Scoped Slot

name 说明
自定义列的内容,参数为 { row, column, $index }
header 自定义表头的内容. 参数为 { column, $index }

# 组件属性 (Props) 文档

以下是组件支持的所有属性(props),用于控制表格、分页、工具栏等功能的显示和行为。
建议谨慎使用,不然后续不好维护,一般使用 props 控制是否使用控件

属性名 类型 默认值 描述
list Array [] 表格数据列表,默认空数组,用于传入表格的行数据。
refName String 'renderTable' 表格的引用名称,用于在组件内部通过 ref 获取表格实例。
columns Array [] 表格列配置,默认空数组,用于定义表格的列结构和显示内容。
layout String 'total,sizes,prev,pager,next,jumper' 分页布局配置,控制分页组件的显示元素(如总数、每页大小、上一页、分页器等)。
pageSize Number 10 每页显示的条目数,默认 10 条。
pageNum Number 1 当前页码,默认第 1 页。
pageSizes Array [10, 50, 100, 200, 1000] 可选的每页条目数,默认提供 10、50、100、200、1000 的选项。
visibleCloumns Array [] 接口保存的可见列,默认空数组,用于控制显示的列(拼写可能应为 visibleColumns)。
total Number 0 数据总数,默认 0,用于分页计算总页数。
pageable Boolean true 是否显示分页信息,默认显示。设置为 false 时隐藏分页组件。
smallPagination Boolean false 是否使用小型分页样式,默认否。小型分页适用于空间有限的场景。
background Boolean true 分页是否显示背景,默认显示。设置为 false 时移除背景样式。
showSelect Boolean false 是否显示选中条数,
prevText String '' 分页“上一页”按钮的自定义文本,默认空,使用图标或默认文本。
id String '' 组件的唯一标识符,默认空,用于区分多个表格实例。
nextText String '' 分页“下一页”按钮的自定义文本,默认空,使用图标或默认文本。
autoEmpty Boolean true 是否自动显示空状态,默认显示。当 list 为空时显示空视图,设置为 false 则隐藏。
imageSize Number 100 空状态或图片显示的尺寸(单位像素),默认 100。
showToolbar Boolean true 是否显示工具栏,默认显示。设置为 false 时隐藏工具栏。
calcHeight Boolean false 是否自动计算表格高度,默认否。启用后,表格高度为窗口高度减,需要指定id='mytable'去顶部和分页高度。
radioValue Object {} 单选值,默认空对象,用于存储单选行的数据。
sortColumn Boolean false 是否启用列排序,默认禁用。启用后支持列头点击排序。