Implementing server-side range filter in vue-tables-2: A step-by-step guide

I am currently using a server-side VueTables-2 component to display data from the database. The table includes columns with numeric, textual, and date values.

My issue lies with filtering the numeric columns. I am trying to incorporate options for range filtering (such as >, >=, <, <=, =, between, etc).

The only available documentation that I could find is located here:

https://www.npmjs.com/package/vue-tables-2#server-side-filters

Server Side Filters

A. utilize the customFilters option to define your filters, following this syntax:

customFilters: ['alphabet','age-range']

B. similar to the client-side component.

However, there are a few aspects that I don't quite grasp:

  1. How is 'age-range' actually implemented?
  2. Where do I specify the filter settings for each column?
  3. Do I need to involve Vuex or the bus in this process?

If anyone can assist me with the implementation, I would greatly appreciate it.

Thank you

Answer №1

Consumer-created Custom Filters are a unique feature of this package. These filters, which are implemented externally by the user, have the ability to be integrated directly into the table using slots instead of relying on the standard text filter (Refer to the 'Slots' documentation).

As these filters operate independently from the package itself, it is necessary for you to inform the package whenever changes occur, either through the event bus or Vuex.

In essence, the only communication channel between the package and the custom filter is via events. The package does not possess any information regarding when these events will be emitted or the circumstances under which they will take place. It simply waits passively for changes and combines the incoming query with its native one.

For example, suppose you create an age-range-filter component that triggers a changed event, and you wish for it to replace the default text filter for the age column:

<v-server-table ... :columns="['name','age']" :options="tableOptions">
<div slot="filter__age">
    <age-range-filter @changed="filter"></age-range-filter>
</div>
</v-server-table>

Within your Vue instance:

data:{
tableOptions:{
   filterable:['name'] // exclude 'age' as it will be substituted by your component
   customFilters:['age-range']
  }
},
methods:{
   filter(query) {
     VueEvent.$emit('age-range', query);
   }
}

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

Sometimes the Navbar options fail to show up consistently on the Navbar bar

I recently launched my website at campusconnect.cc Unfortunately, I've noticed that when resizing the window, the navbar options are shifting up and down. Can anyone help me identify the issue and provide guidance on how to resolve it? ...

Combining multiple arrays of arrays in JavaScript

I am dealing with an array that contains nested arrays. This particular array is called template https://i.sstatic.net/QIs0Q.png template consists of 2 arrays, but the number can vary and there can be multiple levels of arrays within each one. Here' ...

Exploring the power of Chained Promise.allSettled

Currently, I am working on a project that involves using a basic for loop to create an array of IPs for fetching. My goal is to verify that the response.status is 200 (though I have not yet implemented this), and then filter out only those IPs that return ...

Modify the name of the selected option value

I am working on an html code where I need to replace the values 0, 1, and 2 with USA, Australia, and Canada respectively. I also need to know the name of these values in my MySQL database. Thanks! HTML <form method="post" id="countriesForm" name="cou ...

What is preventing me from accessing React state within Tracker.Autorun?

I'm feeling lost on this one. I have implemented a Tracker.autorun function to monitor when my Mongo subscription is ready for querying (following the advice given in this previous Meteor subscribe callback). It seems to be working fine as it triggers ...

Deselect the DOM element

Here is a jQuery code snippet: $(document).ready(function () { $(".story-area > h1, .story-area > p, .story-area > div > p").text(function () { return convertString($(this).text()); }); }); Additionally, there is a function de ...

Tallying discarded objects post removal from drop zone

Is there a way to accurately count dropped items within a dropped area? I have created an example that seems to be working fine but with one minor issue. When I begin removing items, the count does not include the first item and only starts decreasing afte ...

What is the reason for the new page rendering from the bottom of the screen in React?

Whenever I navigate between pages in my React project, the page always starts at the bottom instead of staying at the top after rendering. I am using router v5 and have been unable to find a solution specifically for this version. I have attempted differe ...

Suggestions for rectifying the calculation script to include the price, a phone number, 2 digits, and integrating a textfield for cost

I have developed a script that calculates prices, phone numbers, and extracts the last 2 digits from the phone number. In my website, the price is displayed through a select option. However, I am facing an issue where the cost does not automatically updat ...

Tables inserted via ckeditor do not preserve the style attribute

After incorporating ckeditor into my web page along with the table plugin, I noticed that sometimes the width of tables created in the editor window extends beyond the boundaries of the webpage when displayed. To address this issue, I made some adjustments ...

Why does my VueJS method only execute after I save changes in VS Code instead of reloading the page? Can someone provide assistance?

Whenever I refresh the page, the console.log inside the method does not get executed until I make a change in VSC and save it. Is the show/hide modal for the form causing this issue? I tested removing the toggle but the problem persisted. Please refer to ...

Activate a click event on an element using Simple HTML DOM

I need assistance in triggering a click on the element below and then retrieving its innertext. <a class="btn btn-sm btn-default" href="javascript:;" onClick="score(238953,this)">Show result</a> Once the "onClick" event is triggered, the elem ...

Discover the latest data in the Laravel and Vue.js integration

My edit page is located at: http://localhost/smp/post/12 https://i.stack.imgur.com/5KAbo.png API ROUTE: Route::get('package', [ProductController::class, 'update']); In ProductController.php public function update(Request $request) { ...

What is the best method for scrolling down a JavaScript table using Selenium in Python?

My dynamic table is created using JavaScript. When the page loads, only the first elements are visible in the source code. This means that when I try to scrape values from the table, only the initial parts are retrieved. Before scraping, I need to scroll ...

ESLint error caught off guard by function expression in customized MUI Snackbar Component with Alert

Struggling to create a personalized MUI Snackbar using the MUI Alert example from the official Documentation, but facing ESlint errors: error Unexpected function expression prefer-arrow-callback error Prop spreading is forbidden react/jsx-props-no-s ...

Issues with Ajax calls not functioning properly within CakePHP

I'm attempting to make an AJAX request in CakePHP. The submit button is marked as #enviar and the action as pages/contato. This is the code for my AJAX request: $(document).ready(function() { $('#enviar').click(function(){ $. ...

AngularJS $scope changes not reflecting in the view

Struggling with a persistent issue in my angularJS $scope. I've been working on updating an array within a controller function, and even though the values are changing based on console logs, the view isn't reflecting those changes. Here's wh ...

Error message "Vue CLI project setup encountering ENOENT error: file or directory does not exist"

I'm currently in the process of creating a new Vue.js app, and I've executed the following command: vue create client After that, I opted for the default template: default (babel, eslint) However, during the setup process, it abruptly stops w ...

Exported data in Vue3 components cannot be accessed inside the component itself

Essentially, I'm working on creating a dynamic array in Vue3. Each time a button is clicked, the length of the array should increase. Below is the code snippet. <div class="package-item" v-for="n in arraySize"></div> e ...

What is the best way to utilize images stored in the public directory rather than the assets folder within my Vue application?

When including images from the assets folder (located in src besides App.vue), it builds and runs successfully. However, when attempting to change the image using JavaScript, it doesn't work as expected. For instance: background-image: url('../as ...