NPM address

# vue-element-easy-table

vue-element-easy-table

  • A simple table based on the re-encapsulation of Element-UI table

  • Fully supports all attributes of the Element UI Table component

The installation

npm i vue-element-easy-table
Copy the code

The sample

// in main.js
import EasyTable from "vue-element-easy-table";
Vue.use(
  EasyTable,
  /* Global configuration, element-UI table attributes are available */ {
    // Table properties
    tableAttrs: {
      border: true.size: "small"."header-row-class-name": "className",},// Cell attributes
    tableColumnAttrs: {
      align: "center".emptyPlaceholder: "--".omit: {
        rows: 2.direction: "top",}},// Paging properties
    paginationAttrs: {
      align: "right",}});Copy the code
<EasyTable
  row-id="id"
  :data="tableData"
  :tableOptions="tableOptions"
  :page.sync="page"
  :page-size.sync="size"
  :total="total"
  :checkbox-config="{fetchVal: true, rowClick: true}"
  :radio-config="{selectedVal: selectedVal, fetchVal: true, rowClick: true}"
  @selected-change="select"
  @checked-change="handleChecked"
  @pagination="handleChangePage"
/>
Copy the code
export default {
  name: "App".components: {},
  data() {
    return {
      page: 1.size: 10.total: 1000.selectedVal: -1.tableData: [{id: 10.date: "2016-05-02".name: "Wang Xiaohu".address: Lane 1518, Jinshajiang Road, Putuo District, Shanghai.type: "1".img: require("@/assets/images/avatar.jpg"),
          status: 1}, {id: 21.date: "2016-05-04".name: "Wang Xiaohu".address:
            "Lane 1517, Jinshajiang Road, Putuo District, Shanghai".type: 0.img: require("@/assets/images/avatar.jpg"),
          status: 1}, {id: 33.date: "2016-05-01".name: "Wang Xiaohu".address: Lane 1519, Jinshajiang Road, Putuo District, Shanghai.type: false.img: require("@/assets/images/avatar.jpg"),
          status: 2}, {id: 4.date: "2016-05-03".name: "Wang Xiaohu".address: Lane 1516, Jinshajiang Road, Putuo District, Shanghai.type: 1516 Jinshajiang Road, Putuo District, Shanghai.img: require("@/assets/images/avatar.jpg"),
          status: 0,}]}; },computed: {
    tableOptions() {
      return[{title: "Radio".type: "radio"}, {title: "Date".prop: "date".merge: [{title: "Name".prop: "name".merge: [{title: The name of the "1".prop: "name"}, {title: "Address".prop: "address".returnVal: (value) = > {
                    return 'Detailed Address:${value}`; },},],}, {title: "Address".prop: "address",},],}, {title: "The name of the 111".prop: "type".renderHeader: () = > {
            return (
              <span>
                <span>Custom table headers</span>
                <sup>*</sup>
              </span>
            );
          },
          returnVal: (value, row) = > {
            return ` name:${value}`; }, {},title: "Image".render: (h, data) = > {
            return (
              <div>
                <img style="width: 50px; height: 50px" src={data.img} />
              </div>); }, {},title: "Address".prop: "address".omit: {
            effect: "light".rows: 2.direction: "top",}}, {title: "Address".prop: "address".omit: 1}, {title: "State".prop: "status".enumType: [{value: 0.label: "Not started"}, {value: 1.label: "Already started"}, {value: 2.label: "In progress",},],}, {title: "State 2".prop: "status".enumType: {
            // Customize enumeration parameters
            params: {
              value: "status".label: "text",},data: [{status: 0.text: "Not started"}, {status: 1.text: "Already started"}, {status: 2.text: "In progress",},],},},]; }},methods: {
    handleChangePage({ page, size }) {
      console.log(page, size);
      console.log(this.page);
      console.log(this.size);
    },
    handleChecked(data) {
      console.log("radio");
      console.log(data);
    },
    select(data) {
      console.log("selected");
      console.log(data); ,}}};Copy the code

Table Global Attribute


parameter instructions type
tableAttrs Table properties object
tableColumnAttrs Cell attribute object
paginationAttrs Paging properties object








Table Attribute


parameter instructions type optional
loading loading boolean
page The current page number
pageSize Number each page number
total Total number of data items number
row-id The value parameter of row data string
tableOptions Form parameter array
checkbox-config Type =selection configuration parameter: “fetchVal specifies the value, row-id specifies the value attribute, and rowClick on the row.” object {fetchVal: boolean, rowClick: boolean}
radio-config Select selectedVal by default, fetchVal by default, row-id by default, rowClick by row object {selectedVal: selectedVal, fetchVal: boolean, rowClick: boolean}
paginationAttrs Bind to the Pagination property, see the Element-UI Pagination property object








Table Options


parameter instructions type optional The default value
title Display title string
prop The name of the field corresponding to the column content string
width Cell width number
show Whether or not shown boolean true
align Text alignment string left/right/center
type Radio displays a single box, and other parameters correspond to the Type attribute of the Element-UI table string selection/index/expand/radio
attrs To bind Attributes, see the elder-UI table table-column Attributes attribute object
merge Table header merge, recursive merge table header, can be multi-level merge array
render Equivalent to element-UI table “slot-scope”, “H: generate virtual DOM component, data: current row data” Function(h, data)
check If check is false and render is used, the prop field data value is not verified to be null boolean true
omit {rows: 1, direction: {rows: 1, direction: ‘top’}, the default display direction is’ TOP ‘. If you need to change the direction, modify the direction parameter (refer to the placement parameter value of el-Tooltip) and other attributes according to the element-UI el-tooltip attribute number/object
sortable Column sorting boolean
returnVal The data can be processed accordingly and returned. “Val: prop value, rows: current row data” Function(val, rows)
enumType {params: {label: ‘corresponding label’, value:’ corresponding value’}, data: enumData} array[{lable: string, value: any}]/object
renderHeader Custom table headers Function
emptyPlaceholder Empty placeholder. When the data value is: undefined/null/empty, it will be displayed as a placeholder string








Table Events


The event name instructions type
checked-change Check the callback box. If the row-id attribute is specified and “fetchVal: true” is entered, the value is returned, otherwise the current row data is returned Function(data)
selected-change Check the callback box. If the row-id attribute is specified and “fetchVal: true”, the value is returned; otherwise, the current row data is returned Function(data)
pagination Switch paging or size change triggered Function(page, size)