Break down the table output based on column values with Vue

At the moment, my data is being displayed in one table.

https://i.sstatic.net/C1mmY.png

What I am looking to achieve is having a separate table for each code. For example, all instances of Code 1 should be in one table, Code 2 in another table, and so on. This is the current code I am using to display the table:

<template>
<div class="panel-con">
        <ui-basic-table
            ref="table"
            :store="table.store"
            :apiUrl="table.apiUrl"
            :dataKey="table.dataKey"
            :columns="table.columns"
            :loadOnMount="true"
            >
        </ui-basic-table>
</template>


export default {
name: 'area-cost',
data() {
    return {
    }
},
computed:{
    table(){

        var table = {                
            apiUrl: this.$api.areacost.resource,
            dataKey: this.$api.areacost.plural_key,
            store:{
                namespace:'AreaCost',
                mutation:'set',
            },
            columns: [
                { name: 'area_id', label:'Code',width:40},
                { name: 'expected_cost', label: 'Target', width: 40 , format:'number' },
                { name: 'created_date',label:'Date',width:40, type:'text',format:'date'},
            ],
            actions: [
                {name: 'viewitem', label: '', icon: 'search', icon_color:
                    'primary',routelink:{}}
            ],    
        }
        return table;
    },
},
}

Is it possible to achieve this in any way?

UPDATE

<div class="panel-con">
            <div v-for="(value, index) in areas" :key="index" >
                {{ value.label }} 
                <ui-basic-table
                    ref="table"                        
                    :store="table.store" //tried :store="table.store[value.label]" or :store="table.store[index]"
                    :apiUrl="table.apiUrl"
                    :dataKey="table.dataKey"
                    :columns="table.columns"
                    :loadOnMount="true"
                    :searchparam="value.key"
                    >
                </ui-basic-table> 
                <br/>
            </div>
        </div> 

Answer №1

Sure. Create a function that generates a list of distinct codes. Establish individual stores for each code. Then proceed with the following iteration:

<template>
  <div v-for="code in uniqueCodes" :key="code">
    <div class="panel-con">
        <ui-basic-table
            ref="table"
            :store="table.store[code]"
            :apiUrl="table.apiUrl"
            :dataKey="table.dataKey"
            :columns="table.columns"
            :loadOnMount="true"
            >
        </ui-basic-table>
    </div>
  </div
<template>

My assumptions about your data and table functionality may not be exact, but I trust the concept is comprehensible.

Answer №2

Organize your data by their codes into separate arrays, like this:

new Vue({
  el: "#app",
  data: {
    someData: [
        {
        code: 1,
        name: 'test1'
      },
      {
        code: 2,
        name: 'test2'
      },
      {
        code: 2,
        name: 'test3'
      },
      {
        code: 1,
        name: 'test4'
      },
      {
        code: 1,
        name: 'test5'
      },
      {
        code: 3,
        name: 'test6'
      }
    ]
  },
  computed: {
    tables() {
      let tabs = {};
      this.someData.forEach((el, i) => (i = parseInt(el.code), tabs[i] ? tabs[i].push(el) : (tabs[i] = [el])));
      return tabs;
    }
  }
})

https://jsfiddle.net/eywraw8t/24880/

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

Function Errors, How to Fix Them?

I've recently developed a tool for character creation within a new video game. However, I'm currently facing an issue: When it comes to assigning points in Magic Power or Weapon Power for the Warrior and Wizard characters, there seems to be a p ...

A guide on developing a React component using dot notation and efficiently sharing state with its child components

In my development project, I am creating a component named NavigationBar and I want to have both mobile and desktop versions of it. My plan is to achieve this by creating separate components using the dot notation. class NavigationBar extends React.PureCo ...

Getting console data in AngularJS can be achieved by using the console.log()

This log in the console is functioning correctly. Is there a way to retrieve this information for the HTML? ProductController.js $scope.selectedProduct = function(product) { console.log(product.post_title); console.log(product.ID); console.l ...

Issue with primeng dropdown not displaying the selected label

When using the editable dropdown with filter feature from PrimeFaces, I've noticed that selecting an option displays the value instead of the label. https://i.sstatic.net/8YFRa.png Here is the code snippet: <div class="col-md-5 col-xs-1 ...

Edit data within an Angular table on-the-fly

Currently, I am in the process of developing a dynamic table that may have an unknown number of columns and rows. My goal is to incorporate inline editing with inline templates using ng-include. The first issue at hand: I am faced with the challenge of u ...

What is the process for obtaining multiple arrays from a webassembly function invocation?

I'm searching for a solution to retrieve multiple arrays of varying sizes from a webAssembly function call. Initially, I considered using a struct with multiple arrays and returning it, but I couldn't find any information on how to receive that s ...

Having trouble implementing the FCKeditor in a Zend form

I am trying to integrate FCKeditor with my form by downloading the CKeditor library from Although everything seems to be working fine, I keep encountering the following error: ReferenceError: ReferenceError: CKeditor is not defined Here is the JavaScri ...

Enabling Context Isolation in Electron.js and Next.js with Nextron: A Step-by-Step Guide

I've been working on a desktop application using Nextron (Electron.js + Next.js). Attempting to activate context isolation from BrowserWindow parameters, I have utilized the following code: contextIsolation: true However, it seems that this doesn&ap ...

How does the use of let versus const differ when iterating through a collection?

Utilizing Node.js (ES6) to iterate through each item in a collection like the one provided below: var statuses = [{ statusId: 1, description: 'New' }, { statusId: 2, description: 'Pending' }, { ...

Encountering a problem when attempting to execute Selenium

Currently, I am utilizing Ubuntu 12.04 and attempting to execute Selenium by running the command webdriver-manager start However, every time I try to run it, I encounter the following error message: webdriver-manager start seleniumProcess.pid: 3522 Exce ...

Exploring the world of Bootstrap modals through the lens of

I have integrated AngularStrap into my application in order to utilize the modal feature of Bootstrap. However, I am facing an issue with displaying my template modal. I have followed the documentation and referenced my template with template='#test&a ...

The Custom Layout Component in Form.io

I am currently working with Form.io v3.27.1 and I'm in the process of developing a custom layout component, specifically an accordion. I have been referring to the concepts outlined in the CheckMatrix component example as my guide. Successfully, I ha ...

Using Formik with Material UI's TextField component and passing a 'label' prop to the Field component

Currently, I am in the process of creating a form with Formik and Material UI. I have implemented the Formik component as follows: Within my Input component, the following code is used: const Input = ({ field, form: { errors } }) => { const errorMes ...

What is the best way to manage and add dates in my database using Node.JS and MongoDB?

I am currently developing a Calendar application using Node.JS and MongoDB. However, I am encountering difficulties when trying to integrate data from the database into the existing calendar system. Whenever I attempt to load LocalHost:3000/init, I am pre ...

Upload an array of choices to the server by utilizing ng-model

I have almost resolved my issue, but now I need help with sending the data to the server. In my current situation, there is a form that includes employee details and projects for that employee (which can be multiple). When the user wants to add projects, ...

What could be causing the property of the object to be inaccessible in a ternary equation, yet functional in JSX in React?

I have an object that resembles the structure below: campground { "uri": "/campgrounds/long-island-bridge-campground-llc/", "acfDetails": { "picture": { "mediaItemUrl": "/uploads/2021/04/ ...

Error message: "Unable to access D3 data when trying to select nested

Working with JSON data in D3 is proving to be a challenge for me. The file seems to be properly read, as indicated by its appearance when I use console.log, and it appears to be correctly formatted based on the examples I have come across. However, when I ...

What is the best way to display all the videos that have been uploaded to YouTube?

I've been working with the Youtube API and PHP library, using this link: http://code.google.com/apis/youtube/2.0/developers_guide_php.html Currently, I'm making modifications to an existing app found at: The same functionality is also available ...

I continuously encounter an issue in Vite version 3.2.4 where an error pops up stating `[vite:esbuild] The service has stopped running: write EPIPE`

When I finished creating a Vite app, I ran the command npm run dev and encountered the following error: [vite:esbuild] The service is no longer running: write EPIPE https://i.stack.imgur.com/MZuyK.png I need help solving this error. Can anyone provide gu ...

The click() function in jQuery executing only once inside a "for" loop

This is an example of my HTML code: <!DOCTYPE html> <head> <title>Chemist</title> <link href="stylesheet.css" rel="stylesheet"> </head> <body> <h2 id="money"></h2> <table border="1px ...