element 中el-table 获取当前选中行的index


1. 获取当前行选中的index

<el-table ref="tableF" :row-class-name="tableRowClassName" @row-click="onRowClick" highlight-current-row :data="tableData" style="width: 100%" v-loading="tableLoading">
        <el-table-column prop="name" show-overflow-tooltip label="策略名称"></el-table-column>
        <el-table-column prop="issue_time" show-overflow-tooltip label="下发时间">
          <template slot-scope="scope">{{scope.row.issue_time && scope.row.issue_time!=0 ? $moment.unix(scope.row.issue_time).format("YYYY-MM-DD HH:mm:ss") : '--'}}</template>
        </el-table-column>
        <el-table-column label="操作" width="80">
          <template slot-scope="scope">
            <el-button type="text" @click.stop="detailsDialog(scope.row)">详情</el-button>
          </template>
        </el-table-column>
</el-table>

 

首先,给table加一个属性::row-class-name="tableRowClassName"

tableRowClassName({row, rowIndex}) {
    row.row_index = rowIndex;
}

 

然后给表格添加: @row-click = "onRowClick"

onRowClick (row, event, column) {
    this.currentRowIndex = row.row_index;
}

这时属性: currentRowIndex 存的就是当前选中行的index。

 

2. table默认选中行

 this.tableData = res.Data.list;           
 this.$refs.tableF.setCurrentRow(this.tableData[this.currentRowIndex]

 


免责声明!

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



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