antd中table 动态改变disabled


目的:点击某个按钮之后使得table中行动态改变disabled值

去看table组件中rowSelection的配置,getCheckboxProps可以用来设置选择框的默认属性,那么如果想要动态改变,怎么解决?

后来发现实现方法还是要依赖getCheckboxProps

 

 

 

<template>
  <div>
    <a-table :columns="columns" :dataSource="data" :rowSelection="rowSelection">
      <a
        slot="operation"
        slot-scope="text,record,index"
        @click="handleDisabled()"
      >activate/disabled</a>
    </a-table>
    <a-button @click="handleDisabled(3)">activate/disabled</a-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      columns: [
        {
          title: "Operation",
          scopedSlots: { customRender: "operation" }
        },
        {
          title: "Name",
          dataIndex: "name"
        },
        {
          title: "Age",
          dataIndex: "age"
        },
        {
          title: "Address",
          dataIndex: "address"
        }
      ],
      data: [
        {
          key: "1",
          name: "John Brown",
          age: 32,
          address: "New York No. 1 Lake Park",
          disabled: false
        },
        {
          key: "2",
          name: "Jim Green",
          age: 42,
          address: "London No. 1 Lake Park",
          disabled: false
        },
      ],
      selectedRowKeys: []
    };
  },
  computed: {
    rowSelection() {
      return {
        getCheckboxProps: record => ({
          props: {
            disabled: record.disabled
          }
        })
      };
    }
  },
  methods: {
    handleDisabled() {
      this.data.map(item=>item.disabled=!item.disabled) ;
      // 这一步重新赋值才能实现动态改变disabled
      this.data = [...this.data];
    }
  }
};
</script>

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM