Displaying a quasar table with rows sourced from an object of objects stored in the

Encountering an issue with displaying data in my q-table. The problem stems from storing data in the store as an object of objects, whereas q-table requires data to be in the form of an array of objects. Below is the code snippet:

store.js

import Vue from 'vue'

    const state = {
        tasks: {
            'ID1': {
                name: 'Go to shop',
                completed: false,
                dueDate: '2019/05/12',
                dueTime: '18:30'
            },
            'ID2': {
                name: 'Get bananas',
                completed: false,
                dueDate: '2019/05/13',
                dueTime: '14:00'
            },
            'ID3': {
                name: 'Get apples',
                completed: false,
                dueDate: '2019/05/14',
                dueTime: '16:00'
            }   
        }
    }

    export default {
        namespaced: true,
        state,
        mutations,
        actions,
        getters
    }

Component

<template>
    <q-page padding>
        <q-table
                padding
                title="Tasks"
                :data="tasks"
                :columns="columns"
                row-key="name"
                hide-bottom
        >
            <template v-slot:body="props">
                <q-tr :props="props">
                    <q-td key="name" :props="props">
                        {{ props.name }}
                    </q-td>
                    <q-td key="created" :props="props">
                        {{ props.created }}
                    </q-td>
                </q-tr>
            </template>
        </q-table>

    </q-page>
</template>

<script>
    import {mapState} from 'vuex'

    export default {
        data () {
            return {
                columns: [
                    { name: 'name', required: true, label: 'Name', align: 'left', field: row => row.name, sortable: true },
                    { name: 'created', required: true, label: 'Created', align: 'left', field: row => row.created, sortable: false },
                ],
            }
        },
        computed: {
            ...mapState('tasks')
        }
    }
</script>

Facing the issue

Invalid prop: type check failed for prop "data". Expected Array, got Object
. How can I format my code to properly display table rows when the store object "tasks" is structured as an object of objects and can't be reformatted as an array of objects?

If further details are needed, please let me know. Thank you!

Answer №1

To simplify the process, consider creating another computed arrayTasks (local) based on the tasks array and utilize it for the q-table component.

computed: {
    ...mapState('tasks'),
    arrayTasks() {
        return Object.values(this.tasks);
    }
}

Next, adjust the template accordingly.

<q-table
    padding
    title="Tasks"
    :data="arrayTasks"
    :columns="columns"
    row-key="name"
    hide-bottom
>

If you no longer require the original tasks in the form of an Object within an Object, you can opt for this alternative approach.

computed: {
    ...mapState({
        tasks: state => Object.values(state.tasks) // Transform Object values into an Array
    })
}

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 best way to identify duplicate data being returned from a server within a for loop?

When receiving sorted data from the server through an infinite scroll, my goal is to filter out duplicate entries and add new unique data to a client-side array. If duplicates are found, I want to stop the infinite scrolling process. $scope.collections = ...

Modify content or display picture within accordion panel based on its identifier

In my view, I have a model representing a list of items. Each item has a unique ID, which is included in the H2 header tag. The details of each item are displayed in a div below the header. Initially, there is an image within the header that is set to disp ...

When users install my npm module, they are not seeing text prediction (intellisense) in their editors

I'm currently focused on developing my package @xatsuuc/startonomy. I'm encountering an issue where Intellisense is not working properly when the package is installed on the user's side. Even though the .d.ts files are visible in node_modul ...

Vuetify Autocomplete feature in PhpStorm

Having difficulty implementing autocomplete on Vuetify components, such as v-card. Currently using PhpStorm 2018.2.4 on a Windows 10 system with the Vue.js plugin installed. ...

Create a hierarchical tree structure using a string separated by dots

I am struggling with organizing a tree structure. :( My goal is to create a tree structure based on the interface below. export type Tree = Array<TreeNode>; export interface TreeNode { label: string; type: 'folder' | 'file'; ...

Is chaining .all() a feasible alternative to utilizing Promise.all()?

I am currently working with bluebird promises in Node.js. I recently attempted to incorporate Promise.all into my promise chain, resulting in the following code: request-promise(some_API_call) .then( (responseBody) => { // using response ...

Techniques within the identical module, constantly refreshing

In the realm of HTML, I am well-versed in accomplishing this task. However, I am reluctant to conceal it using a div tag and class. Here is my current setup: <template> <div id="navJade" class="inactive"> <h1>Jade Skill Calculations ...

Getting the time difference relative to the current time using date-fns from a MySQL datetime - a step

I am trying to implement a relative time feature like ... ago in my react blog posts without relying on moment.js. The date of the post is stored in mysql using the datatime data type, for example 2023-02-01 21:25:33 This is what I have attempted in the c ...

Starting an AngularJS module without an HTML page may seem like a daunting task,

I am currently developing a browser extension project using AngularJS. Within the background.js file (which contains the code that runs in the background), I have created a module with a run block. var myExtensionModule = angular.module('myExtension ...

Adjust the width of the element to match the size of the image within

My webpage features an image along with some accompanying metadata that I want to be centered on the page. I want the div holding the metadata to be the same width as the image. Here's an example: Unfortunately, I am unable to determine the image&apo ...

I am encountering a 302 error when attempting to sideload images on Imgur using the API

I've been experimenting with sideloading using imgur's API. $.get("http://api.imgur.com/2/upload.json?", { url: www.example.com/blah.jpg },function(response){ var url = response.upload.links.original; var thumb_url = response ...

Can you guide me on setting a background image URL for rails using javascript?

Within my Rails application, I have a collection of content paired with image buttons (each piece of content has an associated image). When a user clicks on one of these buttons, my goal is to display the corresponding image. All of my images are stored u ...

The GitHub Pages website is not displaying exactly like it does when running locally with a live server

Currently in the process of creating a compact website where users can input an anagram and receive all potential words that can be formed from it. Additionally, upon receiving these words, there is an option to click on one for its definitions. The site ...

Spacing the keyboard and input field in React Native

Is there a way to add margin between the input and keyboard so that the bottom border is visible? Also, how can I change the color of the blinking cursor in the input field? This is incorrect https://i.sstatic.net/Jsbqi.jpg The keyboard is hidden https: ...

What is the best method for accessing a value in IndexedDB while utilizing service workers?

I am feeling overwhelmed by the concepts of IndexedDB and serviceworkers as I try to transform them into a functional application. Despite my extensive research, including studying various examples, I am struggling to integrate the two technologies effecti ...

Tips for efficiently exporting and handling data from a customizable table

I recently discovered an editable table feature on https://codepen.io/ashblue/pen/mCtuA While the editable table works perfectly for me, I have encountered a challenge when cloning the table and exporting its data. Below is the code snippet: // JavaScr ...

When integrating AngularJS $http with WordPress, the desired response may not always be achieved

I recently implemented a wp_localize_script for ajax in my WordPress project: wp_localize_script('cb_admin_js', 'cbAjax', array('ajax_url' => admin_url( 'admin-ajax.php' ))); As part of testing, I used an $http. ...

Exploring the Observable object within Angular

As I delve into learning Angular through various tutorials, I encountered a perplexing issue regarding my console displaying an error message: ERROR in src/app/employee/employee.component.ts:17:24 - error TS2322: Type 'IEmployee' is not assignab ...

NextAuth - simulating the login process of OneLogin

I've been working on setting up a local OneLogin mocked service using WireMock. Everything has been going smoothly so far, as I was able to mock most of the OAuth OneLogin flow. However, I'm facing an issue with the last part that is preventing i ...

A guide on understanding tab-formatted text in a textarea using JavaScript (Vuejs)

Trying to decipher a text that has been copied into a Word table, the formatting is very confusing. I am looking to extract the rows as objects in an array, with the columns serving as properties of each object. I would like to accomplish this using Vuejs ...