Pagination
parent
0621cd0f04
commit
e9bfcecf73
|
@ -2,7 +2,7 @@
|
||||||
<div>
|
<div>
|
||||||
<div class="content-section introduction">
|
<div class="content-section introduction">
|
||||||
<div class="feature-intro">
|
<div class="feature-intro">
|
||||||
<h1>DataTable - Lazy</h1>
|
<h1>DataTable <span>Lazy</span></h1>
|
||||||
<p>Lazy mode is handy to deal with large datasets, instead of loading the entire data, small chunks of data is loaded by invoking corresponding callbacks everytime paging, sorting and filtering happens.
|
<p>Lazy mode is handy to deal with large datasets, instead of loading the entire data, small chunks of data is loaded by invoking corresponding callbacks everytime paging, sorting and filtering happens.
|
||||||
Sample belows imitates lazy paging by using an in memory list. It is also important to assign the logical number of rows to totalRecords by doing a projection query for paginator configuration
|
Sample belows imitates lazy paging by using an in memory list. It is also important to assign the logical number of rows to totalRecords by doing a projection query for paginator configuration
|
||||||
so that paginator displays the UI assuming there are actually records of totalRecords size although in reality they aren't as in lazy mode, only the records that are displayed on the current page exist.
|
so that paginator displays the UI assuming there are actually records of totalRecords size although in reality they aren't as in lazy mode, only the records that are displayed on the current page exist.
|
||||||
|
@ -12,12 +12,12 @@
|
||||||
|
|
||||||
<div class="content-section implementation">
|
<div class="content-section implementation">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<DataTable :value="cars" :lazy="true" :paginator="true" :rows="10"
|
<DataTable :value="customers" :lazy="true" :paginator="true" :rows="10"
|
||||||
:totalRecords="totalRecords" :loading="loading" @page="onPage($event)">
|
:totalRecords="totalRecords" :loading="loading" @page="onPage($event)">
|
||||||
<Column field="vin" header="Vin"></Column>
|
<Column field="name" header="Name"></Column>
|
||||||
<Column field="year" header="Year"></Column>
|
<Column field="country.name" header="Country"></Column>
|
||||||
<Column field="brand" header="Brand"></Column>
|
<Column field="company" header="Company"></Column>
|
||||||
<Column field="color" header="Color"></Column>
|
<Column field="representative.name" header="Representative"></Column>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,52 +27,52 @@
|
||||||
<TabPanel header="Source">
|
<TabPanel header="Source">
|
||||||
<CodeHighlight>
|
<CodeHighlight>
|
||||||
<template v-pre>
|
<template v-pre>
|
||||||
<DataTable :value="cars" :lazy="true" :paginator="true" :rows="10"
|
<DataTable :value="customers" :lazy="true" :paginator="true" :rows="10"
|
||||||
:totalRecords="totalRecords" :loading="loading" @page="onPage($event)">
|
:totalRecords="totalRecords" :loading="loading" @page="onPage($event)">
|
||||||
<Column field="vin" header="Vin"></Column>
|
<Column field="name" header="Name"></Column>
|
||||||
<Column field="year" header="Year"></Column>
|
<Column field="country.name" header="Country"></Column>
|
||||||
<Column field="brand" header="Brand"></Column>
|
<Column field="company" header="Company"></Column>
|
||||||
<Column field="color" header="Color"></Column>
|
<Column field="representative.name" header="Representative"></Column>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
</template>
|
</template>
|
||||||
</CodeHighlight>
|
</CodeHighlight>
|
||||||
|
|
||||||
<CodeHighlight lang="javascript">
|
<CodeHighlight lang="javascript">
|
||||||
import CarService from '../../service/CarService';
|
import CustomerService from '../../service/CustomerService';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
totalRecords: 0,
|
totalRecords: 0,
|
||||||
cars: null
|
customers: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
datasource: null,
|
datasource: null,
|
||||||
carService: null,
|
customerService: null,
|
||||||
created() {
|
created() {
|
||||||
this.carService = new CarService();
|
this.customerService = new CustomerService();
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.carService.getCarsLarge().then(data => {
|
this.customerService.getCustomersLarge().then(data => {
|
||||||
this.datasource = data;
|
this.datasource = data;
|
||||||
this.totalRecords = data.length,
|
this.totalRecords = data.length,
|
||||||
this.cars = this.datasource.slice(0, 10);
|
this.customers = this.datasource.slice(0, 10);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 500);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onPage(event) {
|
onPage(event) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.cars = this.datasource.slice(event.first, event.first + event.rows);
|
this.customers = this.datasource.slice(event.first, event.first + event.rows);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}, 1000);
|
}, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,41 +84,41 @@ export default {
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import CarService from '../../service/CarService';
|
import CustomerService from '../../service/CustomerService';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
totalRecords: 0,
|
totalRecords: 0,
|
||||||
cars: null
|
customers: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
datasource: null,
|
datasource: null,
|
||||||
carService: null,
|
customerService: null,
|
||||||
created() {
|
created() {
|
||||||
this.carService = new CarService();
|
this.customerService = new CustomerService();
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.carService.getCarsLarge().then(data => {
|
this.customerService.getCustomersLarge().then(data => {
|
||||||
this.datasource = data;
|
this.datasource = data;
|
||||||
this.totalRecords = data.length,
|
this.totalRecords = data.length,
|
||||||
this.cars = this.datasource.slice(0, 10);
|
this.customers = this.datasource.slice(0, 10);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 500);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onPage(event) {
|
onPage(event) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.cars = this.datasource.slice(event.first, event.first + event.rows);
|
this.customers = this.datasource.slice(event.first, event.first + event.rows);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}, 1000);
|
}, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue