primevue-mirror/doc/tree/LazyDoc.vue

420 lines
12 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
2023-11-28 09:24:01 +00:00
<p>
Lazy loading is useful when dealing with huge datasets, in this example nodes are dynamically loaded on demand using <i>loading</i> property and <i>node-expand</i> method. Default value of <i>loadingMode</i> is <i>mask</i> and also
<i>icon</i> is available.
</p>
2023-02-28 08:29:30 +00:00
</DocSectionText>
2024-05-20 12:14:38 +00:00
<div class="card flex flex-wrap p-fluid gap-4">
<div class="flex-auto md:flex md:justify-start md:items-center flex-col">
2024-04-30 17:45:38 +00:00
<label class="font-bold block mb-2">Mask Mode</label>
2024-05-20 12:14:38 +00:00
<Tree :value="nodes" @node-expand="onNodeExpand" :loading="loading" class="w-full md:w-[30rem]"></Tree>
2023-11-28 09:24:01 +00:00
</div>
2024-05-20 12:14:38 +00:00
<div class="flex-auto md:flex md:justify-start md:items-center flex-col">
2024-04-30 17:45:38 +00:00
<label class="font-bold block mb-2">Icon Mode</label>
2024-05-20 12:14:38 +00:00
<Tree :value="nodes2" @node-expand="onNodeExpand2" loadingMode="icon" class="w-full md:w-[30rem]"></Tree>
2023-11-28 09:24:01 +00:00
</div>
2023-02-28 08:29:30 +00:00
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
nodes: null,
2023-11-28 09:24:01 +00:00
nodes2: null,
2023-02-28 08:29:30 +00:00
loading: false,
code: {
2023-09-22 12:54:14 +00:00
basic: `
2024-05-20 12:14:38 +00:00
<Tree :value="nodes" @node-expand="onNodeExpand" :loading="loading" class="w-full md:w-[30rem]"></Tree>
<Tree :value="nodes2" @node-expand="onNodeExpand2" loadingMode="icon" class="w-full md:w-[30rem]"></Tree>
2023-10-15 09:38:39 +00:00
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2024-05-20 12:14:38 +00:00
<div class="card flex flex-wrap p-fluid gap-4">
<div class="flex-auto md:flex md:justify-start md:items-center flex-col">
2024-04-30 17:45:38 +00:00
<label class="font-bold block mb-2">Mask Mode</label>
2024-05-20 12:14:38 +00:00
<Tree :value="nodes" @node-expand="onNodeExpand" :loading="loading" class="w-full md:w-[30rem]"></Tree>
2023-11-28 09:24:01 +00:00
</div>
2024-05-20 12:14:38 +00:00
<div class="flex-auto md:flex md:justify-start md:items-center flex-col">
2024-04-30 17:45:38 +00:00
<label class="font-bold block mb-2">Icon Mode</label>
2024-05-20 12:14:38 +00:00
<Tree :value="nodes2" @node-expand="onNodeExpand2" loadingMode="icon" class="w-full md:w-[30rem]"></Tree>
2023-11-28 09:24:01 +00:00
</div>
2023-02-28 08:29:30 +00:00
</div>
</template>
<script>
export default {
data() {
return {
nodes: null,
2023-11-28 09:24:01 +00:00
nodes2: null,
2023-02-28 08:29:30 +00:00
loading: false
};
},
mounted() {
this.loading = true;
2024-04-30 17:45:38 +00:00
this.nodes2 = this.initiateNodes2();
2023-02-28 08:29:30 +00:00
setTimeout(() => {
2024-04-30 17:45:38 +00:00
this.nodes = this.initiateNodes();
2023-02-28 08:29:30 +00:00
this.loading = false;
2023-11-28 09:24:01 +00:00
this.nodes2.map((node) => (node.loading = false));
2023-02-28 08:29:30 +00:00
}, 2000);
},
methods: {
onNodeExpand(node) {
if (!node.children) {
this.loading = true;
setTimeout(() => {
let _node = { ...node };
_node.children = [];
for (let i = 0; i < 3; i++) {
_node.children.push({
key: node.key + '-' + i,
label: 'Lazy ' + node.label + '-' + i
});
}
let _nodes = { ...this.nodes };
_nodes[parseInt(node.key, 10)] = _node;
this.nodes = _nodes;
this.loading = false;
}, 500);
}
},
2023-11-28 09:24:01 +00:00
onNodeExpand2(node) {
if (!node.children) {
node.loading = true;
setTimeout(() => {
let _node = { ...node };
_node.children = [];
for (let i = 0; i < 3; i++) {
_node.children.push({
key: node.key + '-' + i,
label: 'Lazy ' + node.label + '-' + i
});
}
let _nodes = { ...this.nodes2 };
_nodes[parseInt(node.key, 10)] = { ..._node, loading: false };
this.nodes2 = _nodes;
}, 500);
}
},
2024-04-30 17:45:38 +00:00
initiateNodes() {
2023-02-28 08:29:30 +00:00
return [
{
key: '0',
label: 'Node 0',
leaf: false
},
{
key: '1',
label: 'Node 1',
leaf: false
},
{
key: '2',
label: 'Node 2',
leaf: false
}
];
2023-11-28 09:24:01 +00:00
},
2024-04-30 17:45:38 +00:00
initiateNodes2() {
2023-11-28 09:24:01 +00:00
return [
{
key: '0',
label: 'Node 0',
leaf: false,
loading: true
},
{
key: '1',
label: 'Node 1',
leaf: false,
loading: true
},
{
key: '2',
label: 'Node 2',
leaf: false,
loading: true
}
];
2023-02-28 08:29:30 +00:00
}
}
}
2023-10-15 09:38:39 +00:00
<\/script>
`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2024-05-20 12:14:38 +00:00
<div class="card flex flex-wrap p-fluid gap-4">
<div class="flex-auto md:flex md:justify-start md:items-center flex-col">
2024-04-30 17:45:38 +00:00
<label class="font-bold block mb-2">Mask Mode</label>
2024-05-20 12:14:38 +00:00
<Tree :value="nodes" @node-expand="onNodeExpand" :loading="loading" class="w-full md:w-[30rem]"></Tree>
2023-11-28 09:24:01 +00:00
</div>
2024-05-20 12:14:38 +00:00
<div class="flex-auto md:flex md:justify-start md:items-center flex-col">
2024-04-30 17:45:38 +00:00
<label class="font-bold block mb-2">Icon Mode</label>
2024-05-20 12:14:38 +00:00
<Tree :value="nodes2" @node-expand="onNodeExpand2" loadingMode="icon" class="w-full md:w-[30rem]"></Tree>
2023-11-28 09:24:01 +00:00
</div>
2023-02-28 08:29:30 +00:00
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const nodes = ref(null);
2023-11-28 09:24:01 +00:00
const nodes2 = ref(null);
2023-02-28 08:29:30 +00:00
const loading = ref(false);
onMounted(() => {
loading.value = true;
2023-11-28 09:24:01 +00:00
nodes2.value = initiateNodes2();
2023-02-28 08:29:30 +00:00
setTimeout(() => {
2024-04-30 17:45:38 +00:00
nodes.value = initiateNodes();
2023-02-28 08:29:30 +00:00
loading.value = false;
2023-11-28 09:24:01 +00:00
nodes2.value.map((node) => (node.loading = false));
2023-02-28 08:29:30 +00:00
}, 2000);
});
const onNodeExpand = (node) => {
if (!node.children) {
loading.value = true;
setTimeout(() => {
let _node = { ...node };
_node.children = [];
for (let i = 0; i < 3; i++) {
_node.children.push({
key: node.key + '-' + i,
label: 'Lazy ' + node.label + '-' + i
});
}
let _nodes = { ...nodes.value };
_nodes[parseInt(node.key, 10)] = _node;
nodes.value = _nodes;
loading.value = false;
}, 500);
}
};
2023-11-28 09:24:01 +00:00
const onNodeExpand2 = (node) => {
if (!node.children) {
node.loading = true;
setTimeout(() => {
let _node = { ...node };
_node.children = [];
for (let i = 0; i < 3; i++) {
_node.children.push({
key: node.key + '-' + i,
label: 'Lazy ' + node.label + '-' + i
});
}
let _nodes = { ...nodes2.value };
_nodes[parseInt(node.key, 10)] = { ..._node, loading: false };
nodes2.value = _nodes;
}, 500);
}
};
2024-04-30 17:45:38 +00:00
const initiateNodes = () => {
2023-02-28 08:29:30 +00:00
return [
{
key: '0',
label: 'Node 0',
leaf: false
},
{
key: '1',
label: 'Node 1',
leaf: false
},
{
key: '2',
label: 'Node 2',
leaf: false
}
];
};
2023-11-28 09:24:01 +00:00
2024-04-30 17:45:38 +00:00
const initiateNodes2 = () => {
2023-11-28 09:24:01 +00:00
return [
{
key: '0',
label: 'Node 0',
leaf: false,
loading: true
},
{
key: '1',
label: 'Node 1',
leaf: false,
loading: true
},
{
key: '2',
label: 'Node 2',
leaf: false,
loading: true
}
];
};
2023-10-15 09:38:39 +00:00
<\/script>
`,
2023-03-13 10:57:47 +00:00
data: `
{
key: '0',
label: 'Documents',
data: 'Documents Folder',
icon: 'pi pi-fw pi-inbox',
children: [
{
key: '0-0',
label: 'Work',
data: 'Work Folder',
icon: 'pi pi-fw pi-cog',
children: [
{ key: '0-0-0', label: 'Expenses.doc', icon: 'pi pi-fw pi-file', data: 'Expenses Document' },
{ key: '0-0-1', label: 'Resume.doc', icon: 'pi pi-fw pi-file', data: 'Resume Document' }
]
},
{
key: '0-1',
label: 'Home',
data: 'Home Folder',
icon: 'pi pi-fw pi-home',
children: [{ key: '0-1-0', label: 'Invoices.txt', icon: 'pi pi-fw pi-file', data: 'Invoices for this month' }]
}
]
},
...`
2023-02-28 08:29:30 +00:00
}
};
},
mounted() {
this.loading = true;
2024-04-30 17:45:38 +00:00
this.nodes2 = this.initiateNodes2();
2023-02-28 08:29:30 +00:00
setTimeout(() => {
2024-04-30 17:45:38 +00:00
this.nodes = this.initiateNodes();
2023-02-28 08:29:30 +00:00
this.loading = false;
2023-11-28 09:24:01 +00:00
this.nodes2.map((node) => (node.loading = false));
2023-02-28 08:29:30 +00:00
}, 2000);
},
methods: {
onNodeExpand(node) {
if (!node.children) {
this.loading = true;
setTimeout(() => {
let _node = { ...node };
_node.children = [];
for (let i = 0; i < 3; i++) {
_node.children.push({
key: node.key + '-' + i,
label: 'Lazy ' + node.label + '-' + i
});
}
let _nodes = { ...this.nodes };
_nodes[parseInt(node.key, 10)] = _node;
this.nodes = _nodes;
this.loading = false;
}, 500);
}
},
2023-11-28 09:24:01 +00:00
onNodeExpand2(node) {
if (!node.children) {
node.loading = true;
setTimeout(() => {
let _node = { ...node };
_node.children = [];
for (let i = 0; i < 3; i++) {
_node.children.push({
key: node.key + '-' + i,
label: 'Lazy ' + node.label + '-' + i
});
}
let _nodes = { ...this.nodes2 };
_nodes[parseInt(node.key, 10)] = { ..._node, loading: false };
this.nodes2 = _nodes;
}, 500);
}
},
2024-04-30 17:45:38 +00:00
initiateNodes() {
2023-02-28 08:29:30 +00:00
return [
{
key: '0',
label: 'Node 0',
leaf: false
},
{
key: '1',
label: 'Node 1',
leaf: false
},
{
key: '2',
label: 'Node 2',
leaf: false
}
];
2023-11-28 09:24:01 +00:00
},
2024-04-30 17:45:38 +00:00
initiateNodes2() {
2023-11-28 09:24:01 +00:00
return [
{
key: '0',
label: 'Node 0',
leaf: false,
loading: true
},
{
key: '1',
label: 'Node 1',
leaf: false,
loading: true
},
{
key: '2',
label: 'Node 2',
leaf: false,
loading: true
}
];
2023-02-28 08:29:30 +00:00
}
}
};
</script>