Exploring various ways to implement HTTP GET requests within the PrimeVue DatatableUsing a mix

I am facing a challenge where I need to use different GET requests to populate my Datatable with data from separate tables in the Database. Despite trying different approaches, I am unable to figure out how to make this work successfully. I have realized that I am using distinct values in the :value attribute of the Datatable component. The crucial information that I aim to display includes the Package and Page details.

<DataTable :value="gridData" :paginator="true" :rows="50" :rowHover="true" :loading="loading" @page="scrollUp()"
               paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
               :rowsPerPageOptions="[15,25,50]" :autoLayout="true"
               selectionMode="single" dataKey="id"
               currentPageReportTemplate="Mostrando {first} até {last} de {totalRecords} Registros"
               :filters="filters"
               class="p-datatable-customers p-datatable p-component p-datatable-hoverable-rows"
               @row-select="onRowSelect">
        <div class="p-datatable-header">
            <div class="table-header">
                Orgs
                <span class="p-input-icon-left">
                <i class="pi pi-search"></i>
                <InputText v-model="filters['global']" placeholder="Global Search"/>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <Button label="Novo" icon="pi pi-plus" iconPos="right" @click="goToNew"/>
                </span>
            </div>
        </div>
        <template #empty>
            Empty
        </template>
        <template #loading>
            load
        </template>
        <Column field="name" header="Name" headerClass="headerClass" bodyClass="bodyClass" :sortable="true"
                filterMatchMode="contains">
            <template #body="slotProps">
                {{slotProps.data.name}}
            </template>
        </Column>
        <Column field="trade_name" header="Trade" headerClass="headerClass" bodyClass="bodyClass" :sortable="true"
                filterMatchMode="contains">
            <template #body="slotProps">
                {{ slotProps.data.trade_name }}
            </template>
        </Column>
        <Column field="created_date" header="Date" headerClass="headerClass" bodyClass="bodyClass" :sortable="true"
                filterMatchMode="contains">
            <template #body="slotProps">
                {{ dateHourFormat(slotProps.data.created_date) }}
            </template>
        </Column>
        <Column field="name" header="Package" headerClass="headerClass" bodyClass="bodyClass" :sortable="true"
                filterMatchMode="contains">
            <template #body="slotProps">
                {{ slotProps.data.name }}
            </template>
        </Column>
        <Column field="file_name" header="Page" headerClass="headerClass" bodyClass="bodyClass" :sortable="true"
                filterMatchMode="contains">
            <template #body="slotProps">
                {{ slotProps.data.file_name }}
            </template>
        </Column>
    </DataTable>
 getAll() {
                this.customerService.getAll()
                    .then((response) => {
                        this.gridData = response;
                    }).catch((error) => {
                    console.log(error);
                })
            },
            getPackage() {
                this.operationPackage = []
                this.operationPackageService.getAllOperationPackages()
                    .then((response) => {
                        this.operationPackage = response;
                    }).catch((error) => {
                    if (error.response && error.response.data && error.response.data.details) {
                        this.$toast.add({
                            severity: 'error',
                            summary: error.response.data.details,
                            life: 5000
                        });
                    } else {
                        this.$toast.add({
                            severity: 'error',
                            summary: 'N',
                            life: 5000
                        });
                    }
                });
            },
            getPage() {
                this.operationPage = []
                this.operationPackageService.getAllHtmlFiles()
                    .then((response) => {
                        this.operationPage = response;
                    }).catch((error) => {
                    if (error.response && error.response.data && error.response.data.details) {
                        this.$toast.add({
                            severity: 'error',
                            summary: error.response.data.details,
                            life: 5000
                        });
                    } else {
                        this.$toast.add({
                            severity: 'error',
                            summary: 'N',
                            life: 5000
                        });
                    }
                });
            },

My attempts to use the same value for multiple GET requests have been unsuccessful as it only displays the first loaded value when mounted. If the getAll request loads first, it shows those values but changes when the getPackage request is loaded.

Answer №1

After some problem-solving, I successfully found a solution to display the desired data.

 <Column field="name" header="Package" headerClass="headerClass" bodyClass="bodyClass" :sortable="true"
            filterMatchMode="contains">
        <template #body="slotProps">
            <div v-for="item in operationPackage">
                <div v-if="slotProps.data.name === item.id">
                    {{ item.name }}
                </div>
            </div>
        </template>
    </Column>
    <Column field="file_name" header="Page" headerClass="headerClass" bodyClass="bodyClass" :sortable="true"
            filterMatchMode="contains">
        <template #body="slotProps">
            <div v-for="item in operationPage">
                <div v-if="slotProps.data.file_name === item.id">
                    {{ item.file_name }}
                </div>
            </div>
        </template>
    </Column>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Showcasing events in a horizontal line using Vue-echarts

Seeking guidance on creating a chart using vue-echarts. How can I display events over 24 hours? The data, fetched from an API, consists of objects like: [ { start: "2023-11-01T01:47:09.930Z" end: "2023-11-01T02:47:09.930Z" ...

How can I avoid C3.js legends from overlapping when hiding or showing a div?

Every time I visit a specific page, a simple chart is automatically generated: function displayOptions() { $("#div1").show(); chartRef.flush(); } function displayChoices() { $("#div1").show(); } $("#div1").hid ...

Detecting the scroll events of elements with the overflow:hidden property

Looking to synchronize scrolling between two different panels or divs? In one element, there's an overflow: auto while the other has overflow: hidden (trying to mimic a grid with frozen columns). I've managed to sync the scroll when it occurs w ...

Having trouble persisting images in Laravel and Vue Js?

Custom Template <form @submit.prevent=" addUser()"> <div class="form-group"> <label for="addUser">Password</label> <input type="tex" class="form-control" id="name" placeholder="Name" name="name" v-model="form.n ...

Seeking a more deliberate option instead of using $(window).load, one that is not as quick as $(document)

Currently, my goal is to utilize JavaScript to conceal my preloader once the DOM and key elements have been loaded. The issue lies in the fact that various iframes on my page can significantly slow down this process. It seems that using jQuery's $(do ...

What strategies can be employed to address the limitations of a single page application?

Looking to create a dynamic single page application using Vue? Consider checking out either Vuetify or CoreUI for Vue. However, some sources claim that single page applications may not be ideal for SEO. In light of this, I'm considering the use of a m ...

Troubleshooting the issue: Difficulty in activating Navbar dropdown using Angular and ui-router

I've been struggling with this issue for some time now - trying to make a simple bootstrap navbar dropdown function properly with angular ui-router and ui-bootstrap (1.3.3, the latest version). Below is my current code: <div class="container"> ...

There is no way to convert a strongly typed object into an observable object using MobX

I have been utilizing the MobX library in conjunction with ReactJS, and it has integrated quite smoothly. Currently, I am working with an observable array structured as follows: @observable items = []; When I add an object in the following manner, everyt ...

When the page is refreshed, the ContextProvider fails to mount

For the complete code, you can view it on codesandbox. Within my countries API application, I have implemented two Route components - <> <Header/> <Router> <Switch> <CountriesDataProvider> ...

Can components be designed in a way that includes elements such as buttons or text areas in the code, but allows for them to be excluded when the component is used?

I have a custom form component that I designed. Depending on certain cases, I want the form to display either a button or a text field instead of the input field as currently coded. function FormTypeOne(props) { return ( <form className={classes.f ...

Does using the useState() hook in React automatically empty out the input fields?

Every time I update a state in my React application, it mysteriously erases the content of my inputs like checkboxes and numbers. Let me share a simple example to demonstrate this issue. import React, { useState } from "react"; export default fun ...

Empty array returned when using fetch in a for loop

Currently, I am developing a server route to execute API calls. I have encountered the need to make two separate fetch requests as I require additional information that is not available in the first fetch. The issue lies in declaring a variable outside o ...

How should the directory be organized for the param with a prefix in Nuxt.js?

My route is set up as /en/rent-:productSlug How should I organize the directory for this route, considering that the parameter productSlug includes the prefix rent? ...

Tips on retrieving and showcasing information from various endpoints in React?

I am working with two different endpoints and I need to fetch data from both simultaneously in order to display it in one single element. For example, I want to show data from one table along with the corresponding name from another table if the product id ...

Having trouble with SVG Circles - Attempting to create a Speedometer design

Trying to implement a speedometer in one of the components of my Vue project, but encountering an issue. When I input 0 into my progress calculation for determining the stroke fill, it overlaps with the background circle instead of staying within its bound ...

Disabling the authentication prompt in the browser

Apologies for the repetition, but I would like to pose a more general question. Is there any method on the client side of a web application to predict if requesting a resource will result in a 401 status code and trigger an unattractive authentication pro ...

The issue of CSS not being applied to HTML content after being inserted via AJAX has been encountered

I've successfully implemented AJAX to retrieve specific page content from a database, but now I'm facing an issue: When it comes to the 'Contact' page, the form retrieved from the database (as HTML) is not applying the CSS styles I hav ...

Vue-cli project encounters an issue where the "Require" function is not recognized when attempting to render using the

Hello everyone, I am currently exploring Vue js (specifically using vue3) and have come across a strange issue regarding image rendering in my Component Within my project, I have two main endpoints titled Home.vue and InitializationModal.vue The problem ...

Sharing data between view and controller in Laravel: a guide

Currently, I am developing a product cart feature that includes subtotal and grand total values displayed within <span> tags. My goal is to pass the grand total value to the controller for further processing. However, I encountered an issue where the ...

Encountering a hindrance with NPM proxy while attempting to globally install Vue CLI

I have encountered an issue while trying to install Vue Cli globally. The installation process is not completing and I am receiving errors related to proxy settings. I tried to manually add values to the .npmrc file as shown below, but it did not resolve t ...