美文网首页
element-ui 中 的 el-table 添加递增序号

element-ui 中 的 el-table 添加递增序号

作者: CMaggie | 来源:发表于2020-08-28 13:15 被阅读0次
(%B1XF6IHJ_YC~1O{YOL9TN.png

效果如上所示,

不论在表格中如何新增删除表格数据,序号总是从1开始递增排序,原理是根据表格分页中当前页数与当前页条数来计算的。
方法一:
 <el-table-column label="序号" type="index"  width="100" :index='indexMethod'> </el-table-column> 
或者
 <el-table-column label="序号"  width="100" type="index" :index='(index)=>{return (index+1) + (this.currentPage-1)*this.PageSize}'> </el-table-column>
methods: {
 indexMethod(index) {
      let curpage = this.currentPage; //单前页码,具体看组件取值
      let limitpage = this.PageSize; //每页条数,具体是组件取值
      return index + 1 + (curpage - 1) * limitpage;
    }
}
方法二:

根据后端传递数据的id

   <el-table
       :data="tableData"
       @selection-change="handleSelectionChange"
       :default-sort="{prop: 'outlay', order: 'ascending'}"
       @sort-change="sortChange">
                    <el-table-column label="序号" prop="Id"></el-table-column>
  </el-table>
  methods: {
sortChange(column, prop, order) {
      console.log(column.prop); //prop标签 => nickname
      console.log(column.order); //descending降序、ascending升序
    },
}

亲,可以点个赞吗?

相关文章

网友评论

      本文标题:element-ui 中 的 el-table 添加递增序号

      本文链接:https://www.haomeiwen.com/subject/knxlsktx.html