elementUI table组件

<template>
  <div class="w-data-table" v-loading="tableLoading">
    <div class="dt-search" v-if="$slots.search">
      <el-form
        ref="searchform"
        size="mini"
        class="dt-search-form-inline"
        :inline="true"
        :model="searchParams"
        @submit.native.prevent="search({ _fromBar: true, _begin: 0 })"
      >
        <slot name="search" />
        <button type="submit" style="display: none;"></button>
      </el-form>
    </div>
    <div
      class="dt-toolbar"
      v-if="$slots.toolbar || $slots.search || $slots['toolbar-right']"
    >
      <slot name="toolbar" />
      <el-button
        v-if="exportable"
        size="mini"
        type="primary"
        icon="el-icon-download"
        plain
        @click="doExport()"
      >
        导出
      </el-button>
      <template v-if="$slots.search">
        <el-divider
          v-if="($slots.toolbar || exportable) && (showSearch || showReset)"
          direction="vertical"
        ></el-divider>
        <el-button
          type="primary"
          size="mini"
          icon="el-icon-search"
          plain
          v-if="showSearch"
          class="search"
          @click="search({ _fromBar: true, _begin: 0 })"
        >
          查询
        </el-button>
        <el-button
          type="default"
          size="mini"
          icon="el-icon-refresh-left"
          plain
          v-if="showReset"
          class="reset"
          @click="clearSearch()"
        >
          重置
        </el-button>
      </template>
      <template v-if="$slots['toolbar-right']">
        <div class="dt-toolbar_right">
          <slot name="toolbar-right" />
        </div>
      </template>
    </div>
    <el-table
      ref="table"
      size="medium"
      style="width: 100%"
      class="dt-table"
      header-cell-class-name="header-compact-cell"
      cell-class-name="compact-cell"
      :highlight-current-row="highlightCurrentRow"
      :border="showBorder"
      :data="data"
      :height="returnHeight || tableHeight"
      :row-key="rowKey"
      :default-expand-all="defaultExpandAll"
      :tree-props="treeProps"
      @row-click="clickRow"
      @select="onTabelSelect"
      @select-all="onTabelSelectAll"
      :load="load"
      lazy
    >
      <el-table-column v-if="showSelect" type="selection" width="55">
      </el-table-column>
      <el-table-column
        v-if="showIndex"
        type="index"
        width="50"
      ></el-table-column>
      <template
        v-for="({
    hide, render, tag, dict, comp, cols, ...attrs },
        index) in column"
      >
        <template v-if="!hide">
          <el-table-column
            v-if="attrs.type"
            v-bind="{ ...columnAttrs, ...attrs }"
            :key="index"
            :selectable="checkboxT"
          ></el-table-column>
          <el-table-column
            v-else-if="render"
            v-bind="{ ...columnAttrs, ...attrs }"
            :key="index"
          >
            <template slot-scope="scope">
              <w-render :render="render" :params="scope" :data="data" />
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="cols"
            v-bind="{ ...columnAttrs, ...attrs }"
            :key="index"
          >
            <template v-for="(cattrs, index) in cols">
              <el-table-column
                v-bind="{ ...columnAttrs, ...cattrs }"
                :key="index"
              ></el-table-column>
            </template>
          </el-table-column>
          <el-table-column
            v-else
            v-bind="{ ...columnAttrs, ...attrs }"
            :key="index"
          >
            <template slot-scope="scope">
              <template v-if="tag">
                <template v-if="tag.dict">
                  <el-tag size="mini" :type="tag.type(scope)">
                    <!-- {
   {
   scope.row[attrs.prop]}} -->
                    {
   {
   
                      scope.row[attrs.prop]
                        | fmtDict(dicts[tag.dict.code || attrs.prop])
                    }}
                  </el-tag>
                </template>
                <template v-else>
                  <el-tag size="mini" :type="tag.type(scope)">
                    {
   {
    tag.text(scope) }}
                  </el-tag>
                </template>
              </template>
              <template v-else-if="comp">
                <component
                  :is="comp.name"
                  v-bind="{ ...comp.attr }"
                  v-on="{ ...comp.on(scope) }"
                >
                  <template v-if="comp.text">{
   {
    comp.text }}</template>
                </component>
              </template>
              <template v-else-if="dict">
                {
   {
   
                  scope.row[dict.prop || attrs.prop]
                    | fmtDict(dicts[dict.code || dict.prop])
                }}
              </template>
              <template v-else>
                {
   {
    scope.row[attrs.prop] }}
              </template>
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可以在表格中的列定义中添加一个多选框列,示例代码如下: ```html <template> <el-table :data="tableData" style="width: 100%"> <el-table-column type="selection"></el-table-column> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="age" label="年龄"></el-table-column> <el-table-column prop="address" label="地址"></el-table-column> </el-table> </template> ``` 在这个例子中,我们在列定义中添加了一个 `type="selection"` 的列,这个列会在表格的左侧显示一个多选框,用户可以通过选中多选框来选择表格中的行。注意,这个列的 `prop` 属性没有定义,因为它不会显示任何数据,只是用来实现多选框的功能。 另外,需要注意的是,在使用多选框列的时候,需要在表格组件上添加 `@selection-change` 事件监听器来处理用户的选择操作: ```html <template> <el-table :data="tableData" style="width: 100%" @selection-change="handleSelectionChange"> <!-- 列定义 --> </el-table> </template> <script> export default { data() { return { tableData: [ // 表格数据 ], selectedRows: [] // 保存用户选择的行 }; }, methods: { handleSelectionChange(selection) { // 更新用户选择的行 this.selectedRows = selection; } } }; </script> ``` 在这个例子中,我们定义了一个 `selectedRows` 数组来保存用户选择的行,然后在 `@selection-change` 事件监听器中更新这个数组。你可以在监听器中执行任意的操作,比如更新表格中的数据、发送请求等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

lbchenxy

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

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

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

打赏作者

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

抵扣说明:

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

余额充值