[vuejs] ํน์ ์กฐ๊ฑด์์ ๋์ rowspan์ ํตํ ํ ์ด๋ธ ๋ณํฉ
ํ๋์ ๊ฑฐ์ง๊ฐ๋ wijmo ๊ทธ๋ฆฌ๋๋ฅผ ์ฐ๋๋ ๊ฑท์ด๋ด๊ณ DevExtreme์ผ๋ก ๋ฐ๊พผ๋จ๋ค. -_-
ํ์ฌ๊ฐ, ๋น๋ถ๊ฐ์ ๊ทธ๋ฆฌ๋ ์๋ฃจ์ ์ ์ฐ์ง ๋ง๊ณ ๊ธฐ๋ณธ ํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ผ๊ธธ๋ ๊ทธ๋ ๊ฒ ํ๋ค.
์๊ตฌ์ฌํญ์ ์ด๋ ๋ค. ์๋์ ๊ฐ์ ํ๋ฒํ ๊ทธ๋ฆฌ๋๋ฅผ
COL1 | COL2 | COL3 | COL4 | COL5 | COL6 | COL7 | COL8 |
A category | 100 | 2023-01-09 | ์ํ1 | 30000 | 1 | 30000 | ์๋ฃ |
A category | 100 | 2023-01-09 | ์ํ2 | 10000 | 3 | 30000 | ์๋ฃ |
B category | 200 | 2023-01-09 | ์ํ3 | 15000 | 2 | 30000 | ์๋ฃ |
A category | 300 | 2023-01-09 | ์ํ4 | 10000 | 1 | 10000 | ์๋ฃ |
B category | 400 | 2023-01-09 | ์ํ5 | 2000 | 5 | 10000 | ๋ฏธ์๋ฃ |
↓
ํ๋จ๊ณผ ๊ฐ์ด ๋ณํฉํ๋ ๊ฒ์ด๋ค.
COL1 | COL2 | COL3 | COL4 | COL5 | COL6 | COL7 | COL8 |
A category | 100 | 2023-01-09 | ์ํ1 | 30000 | 1 | 30000 | ์๋ฃ |
์ํ2 | 10000 | 3 | 30000 | ์๋ฃ | |||
B category | 200 | 2023-01-09 | ์ํ3 | 15000 | 2 | 30000 | ์๋ฃ |
A category | 300 | 2023-01-09 | ์ํ4 | 10000 | 1 | 10000 | ์๋ฃ |
B category | 400 | 2023-01-09 | ์ํ5 | 2000 | 5 | 10000 | ๋ฏธ์๋ฃ |
COL1๊ณผ COL2 ๊ทธ๋ฆฌ๊ณ COL3์ด ๋์ผํ ๋, ํด๋น ์ปฌ๋ผ๋ง ๋ณํฉ์ ํ๋ ๋ชจ์์ด๋ค.
๋ฐ์ดํฐ ํ์ผ๋ถํฐ ๋ง๋ค์ด๋ณด์. COL4~COL8๊น์ง์ ์ปฌ๋ผ์ 2 depth๋ก ๋ง๋ค์ด์ฃผ์ด์ผํ๋ค.
export const dataInfo = [
{
COL1 : 'A category',
COL2 : '100',
COL3 : '2023-01-09'
subInfo : [
{
COL4 : '์ํ1',
COL5 : 30000,
COL6 : 1,
COL7 : 30000,
COL8 : '์๋ฃ'
},
{
COL4 : '์ํ2',
COL5 : 10000,
COL6 : 3,
COL7 : 30000,
COL8 : '์๋ฃ'
}
],
},
{
COL1 : 'B category',
COL2 : '200',
COL3 : '2023-01-09'
subInfo : [
{
COL4 : '์ํ3',
COL5 : 15000,
COL6 : 2,
COL7 : 30000,
COL8 : '์๋ฃ'
},
],
},
{
COL1 : 'A category',
COL2 : '300',
COL3 : '2023-01-09'
subInfo : [
{
COL4 : '์ํ4',
COL5 : 10000,
COL6 : 1,
COL7 : 10000,
COL8 : '์๋ฃ'
},
],
},
{
COL1 : 'B category',
COL2 : '400',
COL3 : '2023-01-09'
subInfo : [
{
COL4 : '์ํ5',
COL5 : 2000,
COL6 : 5,
COL7 : 10000,
COL8 : '์๋ฃ'
},
],
}
];
๊ทธ๋ฆฌ๊ณ <tbody> ์ชฝ์ ์ด๋ ๊ฒ ๋ง์ถฐ์ฃผ๋ฉด ๋๋ค.
์ฐ์ v-if๋ฅผ ๊ฑธ์ด, 2 depth์ ๋ฐฐ์ด์ด ํ๋ ์ด์์ธ ๊ฒฝ์ฐ(์ฆ, ๋ณํฉ์ ํด์ผํ๋ ๊ฒฝ์ฐ)
:rowspan์ผ๋ก ์ปฌ๋ผ ๋ณํฉ์ ํด์ฃผ์๋๋ฐ, ํ๋จ์ ๋ธ๋ฆฐ 2 depth์ ๋ฐฐ์ด์ ๊ธธ์ด๋งํผ rowspan ๊ฐ์ ๊ฑธ์ด์ฃผ์๋ค. :rowspan="item.subInfo.length"
๊ทธ๋ฆฌ๊ณ , ๋ณํฉํ์ง ์์ COL4~COL8 ์ปฌ๋ผ ๋ฐ์ดํฐ๋ฅผ slice๋ก ์ชผ๊ฐ์ด ๋ฟ๋ ค์ฃผ์๋ค.
๋ณํฉํ์ง ์๋ ๊ฒฝ์ฐ์๋ ๊ทธ๋ฅ ๊ทธ๋๋ก ๋ฟ๋ ค์ฃผ๋ฉด ๋๋ค.
<tbody>
<template v-for="(item, index) in table.data" :key="index">
<template v-if="item.subInfo.length > 1"> <!--๋ณํฉํ๋ ๊ฒฝ์ฐ-->
<tr @click="selectRow('table', index)">
<td class="ta-c" :rowspan="item.subInfo.length">{{ item.COL1 }}</td>
<td class="ta-c" :rowspan="item.subInfo.length">
<button type="button" @click="openPopup(item)" style="text-decoration: underline">{{ item.COL2 }}</button>
</td>
<td class="ta-c" :rowspan="item.subInfo.length">{{ item.COL3 }}</td>
<td class="ta-l">{{ item.subInfo[0].COL4 }}</td>
<td class="ta-r">{{ item.subInfo[0].COL5 }}</td>
<td class="ta-c">{{ item.subInfo[0].COL6 }}</td>
<td class="ta-r">{{ item.subInfo[0].COL7 }}</td>
<td class="ta-c">{{ item.subInfo[0].COL8 }}</td>
</tr>
<template v-for="(itm, idx) in item.subInfo.slice(1, item.subInfo.length)" :key="idx">
<tr>
<td class="ta-l">{{ itm.COL4 }}</td>
<td class="ta-r">{{ itm.COL5 }}</td>
<td class="ta-c">{{ itm.COL6 }}</td>
<td class="ta-r">{{ itm.COL7 }}</td>
<td class="ta-c">{{ itm.COL8 }}</td>
</tr>
</template>
</template>
<template v-if="item.subInfo.length == 1"> <!--๋ณํฉํ์ง ์๋ ๊ฒฝ์ฐ-->
<tr @click="selectRow('table', index)">
<td class="ta-c">{{ item.COL1 }}</td>
<td class="ta-c">
<button>{{ item.COL2 }}</button>
</td>
<td class="ta-c">{{ item.COL3 }}</td>
<td class="ta-l">{{ item.subInfo[0].COL4 }}</td>
<td class="ta-r">{{ item.subInfo[0].COL5 }}</td>
<td class="ta-c">{{ item.subInfo[0].COL6 }}</td>
<td class="ta-r">{{ item.subInfo[0].COL7 }}</td>
<td class="ta-c">{{ item.subInfo[0].COL8 }}</td>
</tr>
</template>
</template>
</tbody>