1、官网提供的方法

在这里插入图片描述

2、a-table中设置rowSelection属性与customRow点击事件方法(如标题3)

在这里插入图片描述

3、单选与多选的方法

    // Table行点击事件,单选onClickRow(),多选onClickRowMulti()
    onClickRow(record) {
      return {
        on: {
          click: () => {
            let keys = [];
            let rows = [];
            // 无选中或者选中的不是同一条数据则push选中数据
            if(this.selectedRowKeys.length == 0 || (this.selectedRowKeys.length > 0 &&this.selectedRowKeys[0] != record.id)){
              keys.push(record.id);
              rows.push(record);
            }
            this.selectedRowKeys = keys;
            this.selectionRows = rows;
          }
        }
      }
    },
    onClickRowMultiple(record) {
      return {
        on: {
          click: () => {
            let keys = this.selectedRowKeys;
            let rows = this.selectionRows;
            // 若点击选中的行则取消选中该行,否则添加行
            if(keys.length>0 && keys.includes(record.id)){
              keys.splice(keys.indexOf(record.id),1)
              rows.splice(rows.indexOf(record),1)
            }else{
              keys.push(record.id)
              rows.push(record)
            }
            this.selectedRowKeys = keys;
            this.selectionRows = rows;
          }
        }
      }
    },
Logo

前往低代码交流专区

更多推荐