Is there a way to access the filtered or organized rows in the Quasar Q-Table?

I have encountered a roadblock in my project. Despite installing Quasar version 2.0.0, I realized that it lacks a property to access the filtered or sorted rows. Previous versions of q-table had a computedRows property which was missing in the latest version. I am working on enhancing the functionality of the q-table by implementing features such as highlighting focused rows and enabling keyboard shortcuts for in-line editing. To achieve this, I require access to the row data (model) and its corresponding HTML row.

  • Quasar ver:2.0.0
  • Vuejs 3
  • Typescript

Answer №1

After an extensive search on Google, I stumbled upon a hidden method to access the computedRows and computedRowsNumber properties...

  1. To unlock these properties, assign a ref to your table:
    <q-table ref="table" />
  2. You can then access these properties using the ref:
    • this.$refs.table.computedRows
    • this.$refs.table.computedRowsNumber

This discovery was made with the release of v2.0.0-beta.9 (March 8, 2021)

Insight

computedRows -- provides the rows currently displayed on the page

  • For instance, if there are 30 total results but only 10 are visible on the current page, this property will return those 10 rows. If you need all rows, consider checking out filteredSortedRows

filteredSortedRows -- offers all the displayed rows across all pages

  • For example, if there are 50 rows in total, with 30 matching the filter criteria and displaying, this property will give you those filtered 30 rows. In case there is no filtering, it will return all 50 original rows

computedRowsNumber -- indicates the total count of displayed rows across all pages

  • equivalent to filteredSortedRows.length

Note that these properties may behave differently when server-side data fetching is enabled. While I haven't tested this myself, I had to peek at the source code for insights.

Source | Original Discovery

Answer №2

I came up with a temporary fix for my issue: here is the code snippet of my q-table :

 <template v-slot:body="props">
     <q-tr
         class="row-data"
          :props="props"
          :rowID="props.row.id"
        >
 <q-td
            @click="onTdClick($event, props.row, 
                   props.rowIndex, index)"
            v-for="(col, index) in props.cols"
            :key="col.name"
            :props="props"
            :column="col.name"
          >
            <slot :name="'column-' + col.name" :props="props" :row="props.row">
              {{ col.value }}
            </slot>

            <slot
              :name="'column-edit-' + col.name"
              :props="props"
              :row="props.row"
            >
            </slot>
          </q-td>
        </q-tr>
</template>

//To retrieve filtered rows, I extract the displayed tr elements (each tr element has rowID attribute):
  getHtmlRows(): HTMLTableRowElement[] {
      let htmlTable = this.getHtmlTable();
      let htmlRows: HTMLTableRowElement[] = Array.from(
        htmlTable.querySelectorAll("tr.row-data")
      );

      return htmlRows;
    }, 
//If I need to fetch the data corresponding to an html row (tr), I use :
   getRowData(id: number): any {
      let table = this.$refs.qtableRef as QTable;
      let rowData = table.rows?.find((rw) => rw.id == id);
      return rowData;
    },

    getRowDataByHtmlRow(htmlRow: HTMLTableRowElement): any {
      let rowID = htmlRow.getAttribute("rowID");
      return this.getRowData(Number(rowID));
    },

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

Display all data using JSONP

I've encountered an issue with JSONP. Although I was able to successfully load my JSONP data into my html file, I am struggling to display all the information. I have attempted using both a for loop and $.each method without any luck. Here is the JSO ...

The NestJS error code 413 indicates that the payload size is too large for

I am currently utilizing nestjs and have encountered an issue where an endpoint only accepts files via multipart. When attempting to upload files that are less than 10MB, everything works perfectly fine. However, when trying to upload files larger than 10M ...

I am having trouble reaching the _groups attribute in angular/d3js

I am encountering an issue when trying to access the "_groups" property in my code: function getMouseDate(scale){ var groupElement = d3.select("#group")._groups[0][0] var xCoordinate = scale.invert(d3.mouse(groupElement)[0]); co ...

Limit the option to check or uncheck all on the current page only

I am facing an issue with a select all checkbox that interacts with checkboxes in a paginated table. The problem arises when I check the select all box, as it selects all records instead of just those on the current page. For example, if there are 200 reco ...

Using jQuery to dynamically include option groups and options in a select box

Generate option groups and options dynamically using data retrieved via AJAX. <select name="catsndogs"> <optgroup label="Cats"> <option>Tiger</option> <option>Leopard</option> <option>Ly ...

Tips on utilizing browser.getCurrentUrl() within a Protractor examination

I’ve been wrestling with these lines of Protractor code today: element(by.linkText("People")).click(); browser.waitForAngular(); var url = browser.getCurrentUrl(); ... It seems that getCurrentUrl always throws an error when placed after a waitF ...

Why does jQuery val() function fail to clear readonly input date in Firefox but succeed in Chrome?

When using JQuery.val(''), I noticed a difference in behavior between Firefox and Chrome. You can see the issue demonstrated in this jsfiddle: https://jsfiddle.net/mdqfbj/d4eovkg8/3/ A JS function triggered by a radio button is supposed to clea ...

"Troubleshooting: Fixing the 'Firebase Cloud Function admin reference is not a function'

I recently attempted to transform the .WriteOn cloud function in my Firebase app into a scheduled cloud function. The goal was to create a function that would run every 4 days to delete messages older than 2 days. While this worked well for the .WriteOn fu ...

The output from the second request using RxJS

I am facing an issue with returning an Observable from the second request. Here is the scenario I am encountering: commandRequest(action:string, commandData:any):Observable<CashDesckResponse> { let command:CashDeskRequest; //ask my backend f ...

Failed submission: XMLHttpRequest and FormData not processing data correctly

I'm attempting to use AJAX to submit a form using the post method along with a FormData object. Here's a simplified version of the JavaScript code: var form=…; // form element var url=…; // action form['update'].onclick=function ...

Exporting enums within types in React Typescript

Here are the files I have: VehicleBrands.ts: export enum VehicleBrands { FORD = "ford", HONDA = "honda" } VehicleBrand.ts: import {VehicleBrands} from "./VehicleBrands"; export type VehicleBrand = VehicleBrands.FORD | V ...

I am experiencing issues with the functionality of the navigation drawer on my page (using Vuetify)

One challenge I'm facing is with a vuetify navigation drawer within the navbar of my vuejs app. While it opens and closes properly, none of the items inside are clickable as they should be acting as links to other pages. Currently, only the logout but ...

Mapping through multiple items in a loop using Javascript

Typescript also functions Consider an array structured like this const elementList = ['one', 'two', 'three', 'four', 'five'] Now, suppose I want to generate components that appear as follows <div&g ...

In Internet Explorer 11, the Content-Type setting is not functional and may cause issues with certain functionalities

My initial attempt to solve the issue involved using the method beginQuoteFileUnquoteUpload1, which created a proper boundary and Content-Type. However, upon receiving the file, I discovered that it was corrupted :( var formData = new FormData(); formD ...

How can I create a v-slot template with dynamic content in Vue.js?

Hello there! I appreciate you taking the time to read my inquiry. Currently, I am delving into Vue.js, Vuetify, and v-data-table for a project. I am faced with a challenge of getting my v-slot to function with two different strings as the header name. < ...

Save user input data into an Excel file using PHPExcel

Could someone assist me with storing values from my form inputs to Excel using PHPExcel? I have successfully stored data from my table to Excel, but now I want to store the values from my inputs. Can anyone help me, please? Example of the form inputs: ent ...

The issue with CSS filter invert not functioning properly in Mozilla Firefox is causing complications

I am currently developing a small Firefox add-on designed to make reading pages at night more comfortable. The goal is to invert page colors without affecting images. Here is the code snippet I am using: document.body.style.filter = "invert(100%)"; var i ...

"Troubleshooting: Why isn't my MVC5 Controller able to receive

I am facing an issue with a controller method that I have defined: public JsonResult Save(List<BlogInfo> list) { return Json(new { Data = "" }, JsonRequestBehavior.AllowGet); } In addition, there is an ajax post request from the client side lik ...

Images are not being shown by Glide JS

I have implemented the Glide JS carousel within a VueJS project to showcase multiple images, however, I am encountering an issue where only the first image is being displayed. The <img/> tag has the correct src URL for all three images, but only th ...

Enhancing a Stripe customer object with additional metadata

While setting up a payment system using Stripe, I encountered an issue when trying to add metadata to the customer object. Specifically, I wanted to include my workspace id in the metadata property of the customer. However, upon executing the code below, I ...