I'm trying to figure out the best way to render sub rows in a table.
I'm developing what's essentially a table+accordion. That is, the table adds more rows when you click on it to show more details for that entry.
My table is located in the Researcher Groups component, which has a sub-component: "app-researcher-group-entry (ResearcherGroupEntry).
I'm using Vue-Material, but the problem would be the same if I was using a plain .
Anyway, my structure is kind of like:
// ResearcherGroups.vue
<template>
<md-table>
<md-table-row>
<md-table-head></md-table-head>
<md-table-head>Researcher</md-table-head>
<md-table-head>Type</md-table-head>
<md-table-head></md-table-head>
<md-table-head></md-table-head>
</md-table-row>
<app-researcher-group-entry v-for="(group, index) in researcherGroups" :key="group.label" :groupData="group" :indexValue="index"></app-researcher-group-entry>
</md-table>
</template>
And in ResearcherGroupEntry.vue:
<template>
<md-table-row>
<md-table-cell>
<md-button class="md-icon-button md-primary" @click="toggleExpansion">
<md-icon v-if="expanded">keyboard_arrow_down</md-icon>
<md-icon v-else>keyboard_arrow_right</md-icon>
</md-button>
<md-button @click="toggleExpansion" class="index-icon md-icon-button md-raised md-primary">{{indexValue + 1}}</md-button>
</md-table-cell>
<md-table-cell>{{groupData.label}}</md-table-cell>
<md-table-cell>Group</md-table-cell>
<md-table-cell>
<md-button @click="openTab" class="md-primary">
<md-icon>add_box</md-icon>
Add Client / Client Type
</md-button>
</md-table-cell>
<md-table-cell>
<md-button class="md-primary">
<md-icon>settings</md-icon>
Settings
</md-button>
</md-table-cell>
<app-add-client-to-group-tab :indexValue="indexValue" :groupData="groupData" :closeTab="closeTab" :addClientToGroupTab="addClientToGroupTab"></app-add-client-to-group-tab>
</md-table-row>
</template>
Here's where the problem comes in. I want to be able to expand the clients like this from our mockup:
This would be trivially easy if I could just add another into the ResearcherGroupEntry component. Unfortunately, wrapping with a div or span tag won't work here (it messes up the table).
If I wasnt using Vue Material, I might have considered using JSX for this component, because then I could simply use .map in the parent to create an array of components based on the two variables. I might still be able to do that with v-for directives, but I'm not sure. What I may have to do is create, from props, a crazy pseudo array merging in parents and children, but that's UUUUUGLY code.