简体   繁体   中英

Split table result by column value vue

Right now I can display data but they're all in one table.

在此处输入图片说明

What I want somehow is that, every Code, there should be one table. like All code 1 should have in separate table, all code 2 in separate table and so on.. This is my code in displaying 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 this possible 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> 

Sure. Make a computed that returns a list of unique codes. Make a separate store for each code. Then iterate like:

<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>

I made some assumptions about how your data and table work. Even if this isn't quite right, I hope the idea is clear.

Split your data by their codes into separate arrays, example:

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM