Skip to content

Commit

Permalink
Fixed #1630 - Cannot create dynamic ColumnGroup columns in DataTable
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Nov 10, 2021
1 parent 4709ce7 commit a51f26c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/components/datatable/TableFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</tr>
<template v-else>
<tr v-for="(row,i) of columnGroup.children.default()" :key="i" role="row">
<template v-for="(col,j) of row.children.default()" :key="columnProp(col,'columnKey')||columnProp(col,'field')||j">
<template v-for="(col,j) of getFooterColumns(row)" :key="columnProp(col,'columnKey')||columnProp(col,'field')||j">
<DTFooterCell :column="col" v-if="!columnProp(col,'hidden')"/>
</template>
</tr>
Expand All @@ -34,6 +34,20 @@ export default {
methods: {
columnProp(col, prop) {
return ObjectUtils.getVNodeProp(col, prop);
},
getFooterColumns(row){
let cols = [];
if (row.children && row.children.default) {
row.children.default().forEach(child => {
if (child.children && child.children instanceof Array)
cols = [...cols, ...child.children];
else if (child.type.name === 'Column')
cols.push(child);
});
return cols;
}
}
},
computed: {
Expand Down
16 changes: 15 additions & 1 deletion src/components/datatable/TableHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</template>
<template v-else>
<tr v-for="(row,i) of columnGroup.children.default()" :key="i" role="row">
<template v-for="(col,j) of row.children.default()" :key="columnProp(col, 'columnKey')||columnProp(col, 'field')||j">
<template v-for="(col,j) of getHeaderColumns(row)" :key="columnProp(col, 'columnKey')||columnProp(col, 'field')||j">
<DTHeaderCell v-if="!columnProp(col, 'hidden') && (rowGroupMode !== 'subheader' || (groupRowsBy !== columnProp(col, 'field'))) && (typeof col.children !== 'string')" :column="col"
@column-click="$emit('column-click', $event)" @column-mousedown="$emit('column-mousedown', $event)"
:groupRowsBy="groupRowsBy" :groupRowSortField="groupRowSortField" :sortMode="sortMode" :sortField="sortField" :sortOrder="sortOrder" :multiSortMeta="multiSortMeta"
Expand Down Expand Up @@ -131,6 +131,20 @@ export default {
},
getFilterColumnHeaderStyle(column) {
return [this.columnProp(column, 'filterHeaderStyle'), this.columnProp(column, 'style')];
},
getHeaderColumns(row){
let cols = [];
if (row.children && row.children.default) {
row.children.default().forEach(child => {
if (child.children && child.children instanceof Array)
cols = [...cols, ...child.children];
else if (child.type.name === 'Column')
cols.push(child);
});
return cols;
}
}
},
components: {
Expand Down

0 comments on commit a51f26c

Please sign in to comment.