Add lazy loading support to DataView
parent
f66e2b45f4
commit
2e678efce1
|
@ -196,10 +196,14 @@
|
||||||
data = this.sort();
|
data = this.sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.paginator)
|
if (this.paginator) {
|
||||||
return data.slice(this.d_first, this.d_first + this.d_rows);
|
const first = this.lazy ? 0 : this.d_first;
|
||||||
else
|
return data.slice(first, first + this.d_rows);
|
||||||
|
}
|
||||||
|
else {
|
||||||
return data;
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
<div class="content-section implementation dataview-demo">
|
<div class="content-section implementation dataview-demo">
|
||||||
<h3 class="first">Default</h3>
|
<h3 class="first">Default</h3>
|
||||||
<DataView :value="cars" :layout="layout" paginatorPosition='both' :paginator="true" :rows="20" :sortOrder="sortOrder" :sortField="sortField">
|
<DataView :value="cars" :layout="layout" paginatorPosition="both" :paginator="true" :rows="20" :sortOrder="sortOrder" :sortField="sortField">
|
||||||
<template #header>
|
<template #header>
|
||||||
<div class="p-grid p-nogutter">
|
<div class="p-grid p-nogutter">
|
||||||
<div class="p-col-6" style="text-align: left">
|
<div class="p-col-6" style="text-align: left">
|
||||||
|
|
|
@ -100,7 +100,7 @@ export default {
|
||||||
of page links to display. To customize the left and right side of the paginators, use <i>paginatorLeft</i> and <i>paginatorRight</i> templates.</p>
|
of page links to display. To customize the left and right side of the paginators, use <i>paginatorLeft</i> and <i>paginatorRight</i> templates.</p>
|
||||||
<CodeHighlight>
|
<CodeHighlight>
|
||||||
<template v-pre>
|
<template v-pre>
|
||||||
<DataView :value="cars" :layout="layout" paginatorPosition='both' :paginator="true" :rows="20">
|
<DataView :value="cars" :layout="layout" paginatorPosition="both" :paginator="true" :rows="20">
|
||||||
<template #paginatorLeft>
|
<template #paginatorLeft>
|
||||||
<Button type="button" icon="pi pi-refresh"/>
|
<Button type="button" icon="pi pi-refresh"/>
|
||||||
</template>
|
</template>
|
||||||
|
@ -186,6 +186,45 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</template>
|
</template>
|
||||||
|
</CodeHighlight>
|
||||||
|
|
||||||
|
<h3>Lazy Loading</h3>
|
||||||
|
<p>Lazy loading is useful to deal with huge datasets, in order to implement lazy loading use the pagination and utilize the <i>page</i> callback to load your data from the backend.
|
||||||
|
Pagination in this case needs to display the logical number of records bound to the <i>totalRecords</i> property so that paginator can display itself according to the total records although you'd only
|
||||||
|
need to load the data of the current page.</p>
|
||||||
|
<CodeHighlight>
|
||||||
|
<template v-pre>
|
||||||
|
<DataView :value="cars" :layout="layout" :paginator="true" :rows="20" :lazy="true" @page="onPage($event)">
|
||||||
|
<template #list="slotProps" >
|
||||||
|
<div>Vin: <b>{{slotProps.data.vin}}</b></div>
|
||||||
|
</template>
|
||||||
|
<template #grid="slotProps">
|
||||||
|
<div>Vin: <b>{{slotProps.data.vin}}</b></div>
|
||||||
|
</template>
|
||||||
|
</DataView>
|
||||||
|
</template>
|
||||||
|
</CodeHighlight>
|
||||||
|
|
||||||
|
<CodeHighlight lang="js">
|
||||||
|
<template v-pre>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
cars: null,
|
||||||
|
layout: 'list'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
carService: null,
|
||||||
|
mounted() {
|
||||||
|
this.cars = //initialize the first chunk of data between 0 and 20
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onPage(event){
|
||||||
|
this.cars = //load the data between (event.first) and (event.first + event.rows) from a remote datasource
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</template>
|
||||||
</CodeHighlight>
|
</CodeHighlight>
|
||||||
|
|
||||||
<h3>Properties</h3>
|
<h3>Properties</h3>
|
||||||
|
@ -383,7 +422,7 @@ export default {
|
||||||
|
|
||||||
<div class="content-section implementation dataview-demo">
|
<div class="content-section implementation dataview-demo">
|
||||||
<h3 class="first">Default</h3>
|
<h3 class="first">Default</h3>
|
||||||
<DataView :value="cars" :layout="layout" paginatorPosition='both' :paginator="true" :rows="20" :sortOrder="sortOrder" :sortField="sortField">
|
<DataView :value="cars" :layout="layout" paginatorPosition="both" :paginator="true" :rows="20" :sortOrder="sortOrder" :sortField="sortField">
|
||||||
<template #header>
|
<template #header>
|
||||||
<div class="p-grid p-nogutter">
|
<div class="p-grid p-nogutter">
|
||||||
<div class="p-col-6" style="text-align: left">
|
<div class="p-col-6" style="text-align: left">
|
||||||
|
|
Loading…
Reference in New Issue