VueTablePlus dropdown filter options for Vue.js version 2

I am facing an issue with populating dropdown options on vue good table. My approach involves making an API call to fetch the possible values for the dropdown and then assigning them to the column filter. However, I am struggling to make it work.

  <vue-good-table
    :paginationOptions="paginationOptions"
    :sort-options="sortOptions"
    :isLoading.sync="isTableLoading"
    :rows="rows"
    :columns="columns"
    :lineNumbers="true"
    mode="remote"
    :totalRows="totalRecords"
    @on-row-click="onRowClick"
    @on-page-change="onPageChange"
    @on-sort-change="onSortChange"
    @on-column-filter="onColumnFilter"
    @on-per-page-change="onPerPageChange"
    @on-search="onSearch"
    :search-options="{
        enabled: true
      }"
    styleClass="vgt-table striped bordered"
    ref="table"
  >

This is a basic vgt setup.

  columns: [
    {
      label: 'some column',
      field: 'column1'
    },
    {
      label: 'Customer',
      field: 'customerName',
      filterOptions: {
        enabled: true,
        placeholder: 'All',
        filterDropdownItems: Object.values(this.customers)
      }
    },
    {
      label: 'other columns',
      field: 'column234'
    }
]

The function responsible for fetching data from the API:

methods: {
   async load () {
      await this.getTableOptions()
    },

  async getTableOptions () {
  try {
    var response = await axios.get(APICallUrl)

    this.customers= []
    for (var i = 0; i < response.data.customers.length; i++) {
      this.customers.push({ value: response.data.customers[i].customerId, text: response.data.customers[i].customerName})
    }
  } catch (e) {
    console.log('e', e)
  }
}

I suspect that the table finishes rendering before the load method completes. Even using a static object did not improve the results. Whenever I try to set it as an object, the filter box becomes a type-in box instead of a dropdown.

Answer №1

To ensure the table updates post-render, consider transforming columns into a computed property. Another issue you may encounter is that this.customers is an Array while Object.values() expects an Object. In this case, utilizing the Array.map function could be a suitable alternative.

this.customers.map(c => c.value)

Although as per the VueGoodTable documentation, using an array of objects like your current setup should function correctly.

computed: {
  columns() {
    return [
      {
        label: 'some column',
        field: 'column1'
      },
      {
        label: 'Customer',
        field: 'customerName',
        filterOptions: {
          enabled: true,
          placeholder: 'All',
          filterDropdownItems: this.customers
        }
      },
      {
        label: 'other columns',
        field: 'column234'
      }
    ];
  }
}

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

What is the reasoning behind having two separate permission dialog boxes for accessing the webcam and microphone in flash?

I am currently using a JavaScript plugin known as cameratag () in order to record videos through the web browser. This plugin utilizes a flash-based solution. When the flash application requests permission to access the webcam, it presents a security dialo ...

Creating functionality in Ionic to allow for the dynamic addition of buttons to the navigation bar

I have a navigation bar and I would like to include a save button on it for just one screen. After going through various blogs, I found that the general advice is to declare buttons in the view rather than accessing them in a controller. But still, isn&apo ...

Guide to creating a nested table with JavaScript

Currently, I am utilizing JavaScript to dynamically generate a table. To better explain my inquiry, here is an example of the HTML: <table id='mainTable'> <tr> <td> Row 1 Cell 1 </td> ...

Is iterating over an array of objects the same as avoiding repetitive code?

Update: Incorporating JavaScript with the three.js library. To streamline our code and prevent repetition, we utilize loops. However, in this specific scenario, the for loop is not functioning as expected compared to six similar lines that should achieve ...

Purge stored events from BehaviorSubject in Angular2 using Observables as they are consumed

I'm encountering an issue that I believe stems from my limited understanding of Observables. This project is built on Angular2 (v4.0.3) and employs rx/js along with Observables. Within a state service, there exists a store for events: // Observab ...

Pace.js doesn't bother waiting for iframes to completely load before moving on

On my website, I am using pace.js but encountering issues with pages containing iframes. Is there a method to ensure that pace.js considers the content loading within those iframes? I attempted to configure paceOptions to wait for the iframe selector to l ...

Obtaining the jqXHR object from a script request loaded within the <head> tag using the <script> tag

Is it possible to retrieve the jqXHR object when a script loaded from a script tag within the head tag? function loadScript(url){ const script = document.createElement("script"); script.src = url; // This line will load the script in the ...

Issue with Click event not working on dynamically added button in Angular 8

My goal is to dynamically add and remove product images when a user clicks the add or delete button on the screen. However, I am encountering an issue where the function is not being called when dynamically injecting HTML and binding the click event. Below ...

AngularJS 2: Updating variable in parent component using Router

My current app.component looks like the following: import { Component, Input } from '@angular/core'; import {AuthTokenService} from './auth-token.service'; @Component({ selector: 'app-root', templateUrl: './app ...

Transmitting Various Static Files via Express Router

I am currently utilizing the Express router to serve static .html files based on the URL specified in router.get. For example, this code snippet sends the homepage: router.get('/', function(req, res, next) { res.sendFile('index.html&ap ...

Activate a jQuery plugin on elements that are dynamically generated

Here is the code snippet I am using: $(".address-geocomplete").geocomplete({ country: "US", details: ".details", detailsAttribute: "data-geo" }); When these elements are loaded with the document, everything works smoothly. However, there seem ...

Convert the user input into a div by clicking a button

Here is the code snippet I am currently using: $(document).on('click', '#editDetailBtn', function () { var input = $('<input id="#detailprimaryDescription" type="text" />'); input.val($('#detailprimaryDes ...

A new marker has been created on the Ajax Google Map, however, the old marker is still displaying as

Hey, I'm currently working on retrieving marker latitudes and longitudes using Ajax. I am receiving Ajax data every second and successfully creating markers within a specific radius. However, I'm running into an issue with updating marker positio ...

Discovering the highest value within an array of objects

I have a collection of peaks in the following format: peaks = 0: {intervalId: 7, time: 1520290800000, value: 54.95125000000001} 1: {intervalId: 7, time: 1520377200000, value: 49.01083333333333} and so on. I am looking to determine the peak with the hig ...

I am interested in incorporating various forms within this code

I followed an online tutorial to create this code, and I've made some edits myself, mainly related to the buttons that display information. However, I'm still learning and struggling with adding different forms to each section. I would really app ...

Tips for creating a countdown timer from scratch without relying on a plugin

Looking at this image, it is clear that jQuery can be used. However, I am wondering if there is a way to create a countdown timer without relying on plugins. Can anyone offer some guidance? ...

Utilizing AJAX and PHP POST to dynamically refresh innerHTML content with MySQL data updates

I've been trying to solve this problem for a long time now, and I've reached a point where I can't seem to figure it out. On a page, there are several forms where users input different information that gets submitted to a mySQL database usin ...

Tips for updating JS and CSS links for static site deployment

As I develop my static site using HTML files served from a simple web server, I want to use local, non-minified versions of Javascript code and CSS files. However, when it comes time to deploy the site, I would like to refer to minified versions of these s ...

Load elements in Vue dynamically when a drop-down selection is made

I am looking to implement a functionality where on initial page load, there is a single drop-down field displayed. When an item is selected from this drop-down, I want another drop-down to appear with the same items: After repeating this procedure: I don ...

Retrieving information from an external API in response to an express GET request

After reviewing the sample code in the gtfs-realtime-bindings library's documentation, I attempted to implement a similar logic within my router. However, I encountered issues with extracting the result from the request() route.get('/', (req ...