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