【el-table 表头自定义全选列】

具体效果

javascript 复制代码
<el-table-column
            align="center"
            width="100px"
            :render-header="(h) =>renderHeader(h,'列名')"
          >
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row['列名']"
                @change="(value) =>updatePlanStatus(scope.row,'列名',scope.$index,value)"
              />
            </template>
          </el-table-column>
javascript 复制代码
renderHeader(h, name) {
      return h("div", [
        h("el-checkbox", {
          style: "margin-right:5px",
          // 普通的 HTML 属性
          attrs: {
            id: "check1"
          },
          on: {
            change: value => {
              if (this.selectPoints.length > 0) {
                this.$nextTick(() => {
                // selectPoints 是选中的列
                  this.selectPoints.forEach((item, key) => {
                    item[name] = value;
                    // 判断数组下标
                    const index = this.pointsList.findIndex(
                      point => item.cabinNo == point.cabinNo
                    );
                    // 更新表格数据
                    this.$set(this.pointsList, index, { ...item });
                    // 上一句执行后所有选中的列都会被清除,需要重新选中
                    this.$refs.pointTable.toggleRowSelection(
                      this.pointsList[index],
                      true
                    );
                  });
                });
              }
            }
          }
        }),
        h("span", name)
      ]);
    },
javascript 复制代码
在这里插入代码片
相关推荐
颜酱3 分钟前
回溯算法专项突破练习(1)
javascript·后端·算法
早點睡39018 分钟前
ReactNative项目OpenHarmony三方库集成实战:react-native-contacts
javascript·react native·react.js
☞无能盖世♛逞何英雄☜21 分钟前
Echarts数据可视化应用
前端·信息可视化·echarts
2501_9436103623 分钟前
我爱导航系统美化版源码网址导航系统带后台-【全开源】
前端·后端·html·php
__Yvan26 分钟前
Kotlin 的 ?.let{} ?: run{} 真的等价于 if-else 吗?
android·开发语言·前端·kotlin
英俊潇洒美少年1 小时前
JS 事件循环(宏/微任务) ↔ Vue ↔ React** 三者的关系
javascript·vue.js·react.js
Greg_Zhong1 小时前
Js中异步编程的知识扩展【异步有哪些、如何执行、宏任务和微任务等】
开发语言·javascript
陈随易1 小时前
我也曾离猝死很近
前端·后端·程序员
喵个咪1 小时前
GoWind Content Hub|风行,开箱即用的企业级前后端一体内容中台
前端·后端·cms
我命由我123451 小时前
React - 路由样式丢失问题、路由观察记录、路由传递参数
开发语言·前端·javascript·react.js·前端框架·html·ecmascript