admin管理员组

文章数量:1362177

Im just wondering that there is no built-in functionality in the el-table ponent for pagination.

There is a seperate pagination ponent, but no explanation on how to use it bined with a el-table. I can't figure it out and im confused.

Could someone give a short and clear example how to bine them?

Im just wondering that there is no built-in functionality in the el-table ponent for pagination.

There is a seperate pagination ponent, but no explanation on how to use it bined with a el-table. I can't figure it out and im confused.

Could someone give a short and clear example how to bine them?

Share Improve this question asked Mar 28, 2020 at 14:49 configconfig 1461 gold badge1 silver badge10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

I created a small example, in this case all data is already in the front-end, but in a real case scenario you probably doing a call to some back-end service, so if you want to apply stuff like sorting you have to do this yourself in the back-end service

Good luck with it.

HTML:

<script src="//unpkg./vue/dist/vue.js"></script>
<script src="//unpkg./[email protected]/lib/index.js"></script>
<div id="app">
<template>
    <el-table :data="pagedTableData" style="width: 100%">
      <el-table-column prop="date" label="Date" width="180"></el-table-column>
      <el-table-column prop="name" label="Name" width="180"></el-table-column>
      <el-table-column prop="address" label="Address"></el-table-column>
    </el-table>
    <el-pagination layout="prev, pager, next" :total="this.tableData.length" @current-change="setPage">
  </el-pagination>
  </template>
</div>

JS:

var Main = {
    created() {
      for (let i = 0; i < 100; i++) {
        this.tableData.push({ date: '2016-05-03', name: 'Tom', address: `No. ${i}, Grove St, Los Angeles`
         })
      }
    },
    data() {
      return {
        tableData: [],
        page: 1,
        pageSize: 10
      }
    },
   puted: {
     pagedTableData() {
       return this.tableData.slice(this.pageSize * this.page - this.pageSize, this.pageSize * this.page)
     }
   },
    methods : {
      setPage (val) {
        this.page = val
      }
    }
  }
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')

It is also available on Codepen

本文标签: javascriptHow to use pagination in a datatable in Element UIStack Overflow