takarajapaneseramen.com

Vue 3 and PrimeVue: Implementing Org Chart and Paginator

Written on

Introduction to PrimeVue Framework

PrimeVue is a user interface framework designed to work seamlessly with Vue 3. In this guide, we will explore how to start developing applications using Vue 3 and the PrimeVue framework, specifically focusing on adding an Org Chart component.

Vue 3 application with PrimeVue Org Chart example

Implementing the Org Chart Component

PrimeVue includes an Org Chart component that simplifies the process of creating organizational charts. To implement this feature, we begin with the following code in main.js:

import { createApp } from "vue";

import App from "./App.vue";

import PrimeVue from "primevue/config";

import OrganizationChart from 'primevue/organizationchart';

import 'primevue/resources/primevue.min.css';

import 'primevue/resources/themes/saga-blue/theme.css';

import 'primeicons/primeicons.css';

import 'primeflex/primeflex.css';

const app = createApp(App);

app.use(PrimeVue);

app.component("OrganizationChart", OrganizationChart);

app.mount("#app");

In App.vue, we define the structure of our organization chart using the following template:

<template>

<div>

<OrganizationChart :value="data">

<template #default="slotProps">

<span>{{ slotProps.node.data.label }}</span>

</template>

</OrganizationChart>

</div>

</template>

<script>

export default {

name: "App",

data() {

return {

data: {

key: "0",

data: { label: "F.C. Barcelona" },

children: [

{

key: "0_0",

data: { label: "Barcelona" },

children: [

{

key: "0_0_0",

data: { label: "Chelsea" },

},

{

key: "0_0_1",

data: { label: "Barcelona" },

},

],

},

{

key: "0_1",

data: { label: "Real Madrid" },

children: [

{

key: "0_1_0",

data: { label: "Bayern Munich" },

},

{

key: "0_1_1",

data: { label: "Real Madrid" },

},

],

},

],

},

};

},

methods: {},

};

</script>

Here, we register the OrganizationChart component within main.js and include it in the App.vue component. The value prop is linked to the data object, which includes properties for key, data, and children. The key serves as a unique identifier, while the data object contains the label that we display.

Introducing the Paginator Component

To enhance our Vue 3 application further, we can integrate a Paginator component, enabling page navigation. The code snippet below adds the paginator functionality.

import { createApp } from "vue";

import App from "./App.vue";

import PrimeVue from "primevue/config";

import Paginator from 'primevue/paginator';

import 'primevue/resources/primevue.min.css';

import 'primevue/resources/themes/saga-blue/theme.css';

import 'primeicons/primeicons.css';

import 'primeflex/primeflex.css';

const app = createApp(App);

app.use(PrimeVue);

app.component("Paginator", Paginator);

app.mount("#app");

In App.vue, we can utilize the Paginator as shown below:

<template>

<div>

<Paginator :rows="10" :totalRecords="200"></Paginator>

</div>

</template>

<script>

export default {

name: "App",

data() {

return {};

},

methods: {},

};

</script>

We register the Paginator component and add it to the App. The rows attribute specifies how many entries will appear per page, while totalRecords indicates the total number of records available.

To set the initial page to a specific value, we can modify the component like this:

<template>

<div>

<Paginator :rows="10" :totalRecords="200" :first="20"></Paginator>

</div>

</template>

<script>

export default {

name: "App",

data() {

return {};

},

methods: {},

};

</script>

Alternatively, we can manage the initial page using a data property:

<template>

<div>

<Paginator

:rows="10" :totalRecords="200"

v-model:first="offset"

></Paginator>

</div>

</template>

<script>

export default {

name: "App",

data() {

return {

offset: 20,

};

},

methods: {},

};

</script>

Now the application will start on page 3. Additionally, we can implement a dropdown for selecting rows per page with the rowsPerPageOptions property:

<template>

<div>

<Paginator

:rows="10" :totalRecords="200"

v-model:first="offset" :rowsPerPageOptions="[10, 20, 30]"

>

</Paginator>

</div>

</template>

<script>

export default {

name: "App",

data() {

return {

offset: 20,

};

},

methods: {},

};

</script>

Conclusion

In summary, we have successfully integrated both an Org Chart and a Paginator component into our Vue 3 application using the PrimeVue framework.

Explore the next-generation UI component library in Vue.js with this live session.

Learn how to implement pagination using Vue 3, Laravel, and the Laravel Vue Pagination Package in this tutorial.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Rethinking IT Band Pain: Why Foam Rolling Isn't the Solution

Discover why foam rolling may not be effective for IT band pain and explore better alternatives for runners.

Understanding Russia's Strategic Insights Amidst U.S. Diplomacy

Analyzing the intelligence acquired by Russia during U.S. diplomatic efforts and implications for global security.

Embracing the Freedom of Letting Go: A Healing Journey

Discover the transformative power of letting go of toxic relationships and reclaiming your joy and peace.

A Journey from Pain to Forgiveness: An Old Man's Wisdom

An old man's encounter with a troubled soul leads to profound insights on forgiveness and life choices.

The Tranquility of Embracing Singlehood as a Man

Discover how choosing to remain single can lead to peace and happiness for men, away from the stresses of relationships.

Ultimate Guide to Your Affordable Glow Up Journey

Discover how to enhance your life on a budget through personal growth and practical strategies.

Innovative Solutions to Address Maternal Mortality in Rural Areas

Explore effective strategies and technologies to combat maternal mortality in rural areas, focusing on accessibility and education.

Navigating the Waters of Life: Michael Meade's Insights on Masculinity

Explore Michael Meade's perspective on masculinity, initiation, and the balance between aggression and community.