primevue-mirror/doc/deferredcontent/DataTableDoc.vue

109 lines
3.8 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>A practical example that loads only when table becomes visible in viewport.</p>
</DocSectionText>
<div class="card">
<div style="height: 800px">Scroll down to lazy load a DataTable.</div>
<DeferredContent @load="onDataLoad" role="region" aria-live="polite" aria-label="Content loaded after page scrolled down">
<DataTable :value="products">
<Column field="code" header="Code"></Column>
<Column field="name" header="Name"></Column>
<Column field="category" header="Category"></Column>
<Column field="quantity" header="Quantity"></Column>
</DataTable>
</DeferredContent>
</div>
<DocSectionCode :code="code" :service="['ProductService']" v-bind="$attrs" />
</template>
<script>
import { ProductService } from '/service/ProductService';
export default {
data() {
return {
code: {
2023-09-22 12:54:14 +00:00
basic: `
<DeferredContent @load="onDataLoad" role="region" aria-live="polite" aria-label="Content loaded after page scrolled down">
2023-02-28 08:29:30 +00:00
<DataTable :value="products">
<Column field="code" header="Code"></Column>
<Column field="name" header="Name"></Column>
<Column field="category" header="Category"></Column>
<Column field="quantity" header="Quantity"></Column>
</DataTable>
</DeferredContent>`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2023-02-28 08:29:30 +00:00
<div class="card">
<Toast />
<div style="height: 800px">Scroll down to lazy load a DataTable.</div>
<DeferredContent @load="onDataLoad" role="region" aria-live="polite" aria-label="Content loaded after page scrolled down">
<DataTable :value="products">
<Column field="code" header="Code"></Column>
<Column field="name" header="Name"></Column>
<Column field="category" header="Category"></Column>
<Column field="quantity" header="Quantity"></Column>
</DataTable>
</DeferredContent>
</div>
</template>
<script>
import { ProductService } from '@/service/ProductService';
export default {
data() {
return {
products: null
};
},
methods: {
onDataLoad() {
ProductService.getProductsSmall().then((data) => (this.products = data));
this.$toast.add({ severity: 'success', summary: 'Data Initialized', detail: 'Render Completed', life: 2000 });
}
}
};
<\/script>`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2023-02-28 08:29:30 +00:00
<div class="card">
<Toast />
<div style="height: 800px">Scroll down to lazy load a DataTable.</div>
<DeferredContent @load="onDataLoad" role="region" aria-live="polite" aria-label="Content loaded after page scrolled down">
<DataTable :value="products">
<Column field="code" header="Code"></Column>
<Column field="name" header="Name"></Column>
<Column field="category" header="Category"></Column>
<Column field="quantity" header="Quantity"></Column>
</DataTable>
</DeferredContent>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { ProductService } from '@/service/ProductService';
const products = ref(null);
const onDataLoad = () => {
ProductService.getProductsSmall().then((data) => (products.value = data));
toast.add({ severity: 'success', summary: 'Data Initialized', detail: 'Render Completed', life: 2000 });
};
<\/script>`
},
products: null
};
},
methods: {
onDataLoad() {
ProductService.getProductsSmall().then((data) => (this.products = data));
this.$toast.add({ severity: 'success', summary: 'Data Initialized', detail: 'Render Completed', life: 2000 });
}
}
};
</script>