elementui 表格默认勾选

效果图如下:

 表格显示如下:

<el-table ref="deliverDataTable" :data="deliverDialogTableData" tooltip-effect="dark" >
    <el-table-column type="selection" @selection-change="handleSelectionChange" width="55" >
    </el-table-column>
    <el-table-column prop="goods_name" label="商品" align="left" >
        <template slot-scope="scope" class="tableStyle">
            <span style="float: left">
                <img :src="deliverDialogTableData[scope.$index].source" class="head_pic"/>
            </span>
            <span style="float: left;margin-top:20px;">&nbsp;&nbsp;&nbsp;{{ scope.row.goods_name}}</span>
        </template>
    </el-table-column>
    <el-table-column  prop="good_number" label="数量" align="center" > </el-table-column>
    <el-table-column prop="courier_number" label="物流单号" align="center" > </el-table-column>
    <el-table-column prop="state" label="状态" align="center"> </el-table-column>
</el-table>

注: ref="deliverDataTable"                                         与 this.$refs.deliverDataTable.toggleRowSelection(row);一样

        :data="deliverDialogTableData"                           动态数据(由后台传过来的)

        type="selection"                                                   实现多选

        @selection-change="handleSelectionChange"   事件监听

         toggleRowSelection                                            用于多选表格
    

表格显示如下:vue js代码如下

加载数据记录状态

return {
    deliverDialogTableData:[],
},
created () {
    // 初始化获取列表数据
    this.initData()
},
methods: {
    initData(){
        let _this = this
        ordersApi.getById(this.id)
            .then(response => {
            const data = response.data
            this.deliverDialogTableData = data.obj
             // 记录表格选中状态
            _this.$nextTick(() => {
                    _this.toggleSelection(_this.deliverDialogTableData)
            })
        })
    },
    // 选中数据的集合通过this.multipleSelection.prop字段 取得每一个选项的值
    handleSelectionChange (val) {
      this.multipleSelection = val
      console.log(this.multipleSelection)
    },
}

设置选中状态(重点

this.$refs.deliverDataTable.toggleRowSelection(item)        与上面的必须一样,不能重复

    // 设置选中
    toggleSelection (_this) {
      if (_this) {
        _this.forEach((item) => {
          // 设置该表格选框选中
          this.$refs.deliverDataTable.toggleRowSelection(item)
        })
      } else {
        this.$refs.deliverDataTable.clearSelection()
      }
    },

 

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值