table.vue 3.4 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1
// table 纯前端示例
Mr.奇淼('s avatar
Mr.奇淼( 已提交
2
<template>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  <div>
    <el-table
      :data="tableData"
      @selection-change="handleSelectionChange"
      border
      ref="multipleTable"
      stripe
      style="width: 100%"
      tooltip-effect="dark"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="日期" width="120">
        <template slot-scope="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column label="姓名" prop="name" width="120"></el-table-column>
      <el-table-column label="年龄" prop="age" width="120"></el-table-column>
J
jinlan.du 已提交
19 20
      <el-table-column label="住址" prop="address" min-width="200" show-overflow-tooltip></el-table-column>
      <el-table-column label="是否禁用" prop="switch" min-width="180">
21
        <template slot-scope="scope">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
22 23 24
          <el-switch active-text="开启" inactive-text="禁用" v-model="scope.row.switch"></el-switch>
        </template>
      </el-table-column>
J
jinlan.du 已提交
25 26
      <el-table-column label="按钮组" min-width="180">
        <template slot-scope="scope" >
Mr.奇淼('s avatar
Mr.奇淼( 已提交
27 28 29 30 31 32 33 34 35
            <el-button type="text" size="small" @click="toggleSelection([scope.row])">按钮1</el-button>
            <el-button type="text" size="small" @click="toggleSelection([scope.row])">按钮2</el-button>
            <el-button type="text" size="small" @click="toggleSelection([scope.row])">按钮3</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 20px">
      <el-button @click="toggleSelection([tableData[1], tableData[2]])">切换第二、第三行的选中状态</el-button>
      <el-button @click="toggleSelection()">取消选择</el-button>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
36
    </div>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
37
  </div>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
38
</template>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
39

Mr.奇淼('s avatar
Mr.奇淼( 已提交
40 41
<script>
export default {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
  name: 'Table',
  data() {
    return {
      tableData: [
        {
          date: '2016-05-03',
          name: '王小虎',
          age: 12,
          address: '上海市普陀区金沙江路 1518 弄',
          switch:true
        },
        {
          date: '2016-05-02',
          name: '王小虎',
          age: 12,
          address: '上海市普陀区金沙江路 1518 弄',
          switch:true
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          age: 12,
          address: '上海市普陀区金沙江路 1518 弄',
          switch:true
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          age: 12,
          address: '上海市普陀区金沙江路 1518 弄',
          switch:false
        },
        {
          date: '2016-05-08',
          name: '王小虎',
          age: 12,
          address: '上海市普陀区金沙江路 1518 弄',
          switch:true
        },
        {
          date: '2016-05-06',
          name: '王小虎',
          age: 12,
          address: '上海市普陀区金沙江路 1518 弄',
          switch:true
        },
        {
          date: '2016-05-07',
          name: '王小虎',
          age: 12,
          address: '上海市普陀区金沙江路 1518 弄',
          switch:false
        }
      ],
      multipleSelection: []
    }
  },

  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
114 115
}
</script>