Refactor #3924 - For ColumnGroup & Row

pull/3949/head
Tuğçe Küçükoğlu 2023-05-10 14:39:25 +03:00
parent 05cb0588da
commit a52acf2a32
9 changed files with 159 additions and 6 deletions

View File

@ -1,7 +1,23 @@
const ColumnGroupProps = [
{
name: 'type',
type: 'string',
default: 'null',
description: 'Defines the type of the group.'
},
{
name: 'pt',
type: 'any',
default: 'null',
description: 'Uses to pass attributes to DOM elements inside the component.'
}
];
module.exports = { module.exports = {
columngroup: { columngroup: {
name: 'ColumnGroup', name: 'ColumnGroup',
description: 'Columns can be grouped at header and footer sections by defining a ColumnGroup with nested rows and columns', description: 'Columns can be grouped at header and footer sections by defining a ColumnGroup with nested rows and columns',
'doc-url': 'datatable' 'doc-url': 'datatable',
props: ColumnGroupProps
} }
}; };

View File

@ -1,7 +1,23 @@
const RowProps = [
{
name: 'type',
type: 'string',
default: 'null',
description: 'Defines the type of the group.'
},
{
name: 'pt',
type: 'any',
default: 'null',
description: 'Uses to pass attributes to DOM elements inside the component.'
}
];
module.exports = { module.exports = {
row: { row: {
name: 'Row', name: 'Row',
description: 'DataTable can be grouped by defining a Row component with nested columns', description: 'DataTable can be grouped by defining a Row component with nested columns',
'doc-url': 'datatable' 'doc-url': 'datatable',
props: RowProps
} }
}; };

View File

@ -5,8 +5,37 @@
* [Live Demo](https://www.primevue.org/datatable/) * [Live Demo](https://www.primevue.org/datatable/)
* @module columngroup * @module columngroup
*/ */
import { DataTablePassThroughOptions } from '../datatable';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type ColumnGroupPassThroughOptionType = ColumnGroupPassThroughAttributes | ((options: ColumnGroupPassThroughMethodOptions) => ColumnGroupPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface ColumnGroupPassThroughMethodOptions {
props: ColumnGroupProps;
parent: DataTablePassThroughOptions;
}
/**
* Custom passthrough(pt) options.
* @see {@link ColumnGroupProps.pt}
*/
export interface ColumnGroupPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: ColumnGroupPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface ColumnGroupPassThroughAttributes {
[key: string]: any;
}
/** /**
* Defines valid properties in ColumnGroup component. * Defines valid properties in ColumnGroup component.
*/ */
@ -15,6 +44,11 @@ export interface ColumnGroupProps {
* Type of column group * Type of column group
*/ */
type?: 'header' | 'footer' | undefined; type?: 'header' | 'footer' | undefined;
/**
* Uses to pass attributes to DOM elements inside the component.
* @type {ColumnGroupPassThroughOptions}
*/
pt?: ColumnGroupPassThroughOptions;
} }
/** /**

View File

@ -1,6 +1,9 @@
<script> <script>
import BaseComponent from 'primevue/basecomponent';
export default { export default {
name: 'ColumnGroup', name: 'ColumnGroup',
extends: BaseComponent,
props: { props: {
type: { type: {
type: String, type: String,

View File

@ -16,6 +16,7 @@ import { CheckboxPassThroughOptions } from '../checkbox';
import { ChipPassThroughOptions } from '../chip'; import { ChipPassThroughOptions } from '../chip';
import { ChipsPassThroughOptions } from '../chips'; import { ChipsPassThroughOptions } from '../chips';
import { ColorPickerPassThroughOptions } from '../colorpicker'; import { ColorPickerPassThroughOptions } from '../colorpicker';
import { ColumnGroupPassThroughOptions } from '../columngroup';
import { ConfirmDialogPassThroughOptions } from '../confirmdialog'; import { ConfirmDialogPassThroughOptions } from '../confirmdialog';
import { ConfirmPopupPassThroughOptions } from '../confirmpopup'; import { ConfirmPopupPassThroughOptions } from '../confirmpopup';
import { ContextMenuPassThroughOptions } from '../contextmenu'; import { ContextMenuPassThroughOptions } from '../contextmenu';
@ -56,6 +57,7 @@ import { PickListPassThroughOptions } from '../picklist';
import { ProgressBarPassThroughOptions } from '../progressbar'; import { ProgressBarPassThroughOptions } from '../progressbar';
import { ProgressSpinnerPassThroughOptions } from '../progressspinner'; import { ProgressSpinnerPassThroughOptions } from '../progressspinner';
import { RadioButtonPassThroughOptions } from '../radiobutton'; import { RadioButtonPassThroughOptions } from '../radiobutton';
import { RowPassThroughOptions } from '../row';
import { ScrollPanelPassThroughOptions } from '../scrollpanel'; import { ScrollPanelPassThroughOptions } from '../scrollpanel';
import { ScrollTopPassThroughOptions } from '../scrolltop'; import { ScrollTopPassThroughOptions } from '../scrolltop';
import { SelectButtonPassThroughOptions } from '../selectbutton'; import { SelectButtonPassThroughOptions } from '../selectbutton';
@ -112,6 +114,7 @@ interface PrimeVuePTOptions {
chip?: ChipPassThroughOptions; chip?: ChipPassThroughOptions;
chips?: ChipsPassThroughOptions; chips?: ChipsPassThroughOptions;
colorpicker?: ColorPickerPassThroughOptions; colorpicker?: ColorPickerPassThroughOptions;
columngroup?: ColumnGroupPassThroughOptions;
confirmdialog?: ConfirmDialogPassThroughOptions; confirmdialog?: ConfirmDialogPassThroughOptions;
confirmpopup?: ConfirmPopupPassThroughOptions; confirmpopup?: ConfirmPopupPassThroughOptions;
contextmenu?: ContextMenuPassThroughOptions; contextmenu?: ContextMenuPassThroughOptions;
@ -153,6 +156,7 @@ interface PrimeVuePTOptions {
progressbar?: ProgressBarPassThroughOptions; progressbar?: ProgressBarPassThroughOptions;
progressspinner?: ProgressSpinnerPassThroughOptions; progressspinner?: ProgressSpinnerPassThroughOptions;
radiobutton?: RadioButtonPassThroughOptions; radiobutton?: RadioButtonPassThroughOptions;
row?: RowPassThroughOptions;
scrollpanel?: ScrollPanelPassThroughOptions; scrollpanel?: ScrollPanelPassThroughOptions;
scrolltop?: ScrollTopPassThroughOptions; scrolltop?: ScrollTopPassThroughOptions;
sidebar?: SidebarPassThroughOptions; sidebar?: SidebarPassThroughOptions;

View File

@ -1,12 +1,12 @@
<template> <template>
<tfoot v-if="hasFooter" class="p-datatable-tfoot" role="rowgroup" v-bind="ptm('tfoot')"> <tfoot v-if="hasFooter" class="p-datatable-tfoot" role="rowgroup" v-bind="{ ...ptm('tfoot'), ...getColumnGroupPTOptions('root') }">
<tr v-if="!columnGroup" role="row" v-bind="ptm('footerRow')"> <tr v-if="!columnGroup" role="row" v-bind="ptm('footerRow')">
<template v-for="(col, i) of columns" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || i"> <template v-for="(col, i) of columns" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || i">
<DTFooterCell v-if="!columnProp(col, 'hidden')" :column="col" :pt="pt" /> <DTFooterCell v-if="!columnProp(col, 'hidden')" :column="col" :pt="pt" />
</template> </template>
</tr> </tr>
<template v-else> <template v-else>
<tr v-for="(row, i) of getFooterRows()" :key="i" role="row" v-bind="ptm('footerRow')"> <tr v-for="(row, i) of getFooterRows()" :key="i" role="row" v-bind="getRowPTOptions(row, 'root')">
<template v-for="(col, j) of getFooterColumns(row)" :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 v-if="!columnProp(col, 'hidden')" :column="col" :pt="pt" /> <DTFooterCell v-if="!columnProp(col, 'hidden')" :column="col" :pt="pt" />
</template> </template>
@ -37,6 +37,30 @@ export default {
columnProp(col, prop) { columnProp(col, prop) {
return ObjectUtils.getVNodeProp(col, prop); return ObjectUtils.getVNodeProp(col, prop);
}, },
getColumnGroupPTOptions(key) {
return this.ptmo(this.getColumnGroupProps(), key, {
props: this.getColumnGroupProps(),
parent: {
props: this.$props,
state: this.$data
}
});
},
getColumnGroupProps() {
return this.columnGroup && this.columnGroup.props && this.columnGroup.props.pt ? this.columnGroup.props.pt : undefined; //@todo
},
getRowPTOptions(row, key) {
return this.ptmo(this.getRowProp(row), key, {
props: row.props,
parent: {
props: this.$props,
state: this.$data
}
});
},
getRowProp(row) {
return row.props && row.props.pt ? row.props.pt : undefined; //@todo
},
getFooterRows() { getFooterRows() {
let rows = []; let rows = [];

View File

@ -1,5 +1,5 @@
<template> <template>
<thead class="p-datatable-thead" role="rowgroup" v-bind="ptm('thead')"> <thead class="p-datatable-thead" role="rowgroup" v-bind="{ ...ptm('thead'), ...getColumnGroupPTOptions('root') }">
<template v-if="!columnGroup"> <template v-if="!columnGroup">
<tr role="row" v-bind="ptm('headerRow')"> <tr role="row" v-bind="ptm('headerRow')">
<template v-for="(col, i) of columns" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || i"> <template v-for="(col, i) of columns" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || i">
@ -91,7 +91,7 @@
</tr> </tr>
</template> </template>
<template v-else> <template v-else>
<tr v-for="(row, i) of getHeaderRows()" :key="i" role="row" v-bind="ptm('headerRow')"> <tr v-for="(row, i) of getHeaderRows()" :key="i" role="row" v-bind="getRowPTOptions(row, 'root')">
<template v-for="(col, j) of getHeaderColumns(row)" :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 <DTHeaderCell
v-if="!columnProp(col, 'hidden') && (rowGroupMode !== 'subheader' || groupRowsBy !== columnProp(col, 'field')) && typeof col.children !== 'string'" v-if="!columnProp(col, 'hidden') && (rowGroupMode !== 'subheader' || groupRowsBy !== columnProp(col, 'field')) && typeof col.children !== 'string'"
@ -232,6 +232,30 @@ export default {
columnProp(col, prop) { columnProp(col, prop) {
return ObjectUtils.getVNodeProp(col, prop); return ObjectUtils.getVNodeProp(col, prop);
}, },
getColumnGroupPTOptions(key) {
return this.ptmo(this.getColumnGroupProps(), key, {
props: this.getColumnGroupProps(),
parent: {
props: this.$props,
state: this.$data
}
});
},
getColumnGroupProps() {
return this.columnGroup && this.columnGroup.props && this.columnGroup.props.pt ? this.columnGroup.props.pt : undefined; //@todo
},
getRowPTOptions(row, key) {
return this.ptmo(this.getRowProp(row), key, {
props: row.props,
parent: {
props: this.$props,
state: this.$data
}
});
},
getRowProp(row) {
return row.props && row.props.pt ? row.props.pt : undefined; //@todo
},
getColumnPTOptions(column, key) { getColumnPTOptions(column, key) {
return this.ptmo(this.getColumnProp(column), key, { return this.ptmo(this.getColumnProp(column), key, {
props: column.props, props: column.props,

View File

@ -5,8 +5,37 @@
* *
* @module row * @module row
*/ */
import { ColumnGroupPassThroughOptions } from '../columngroup';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type RowPassThroughOptionType = RowPassThroughAttributes | ((options: RowPassThroughMethodOptions) => RowPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface RowPassThroughMethodOptions {
props: RowProps;
parent: ColumnGroupPassThroughOptions;
}
/**
* Custom passthrough(pt) options.
* @see {@link RowProps.pt}
*/
export interface RowPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: RowPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface RowPassThroughAttributes {
[key: string]: any;
}
/** /**
* Defines valid properties in Row component. * Defines valid properties in Row component.
*/ */

View File

@ -1,6 +1,9 @@
<script> <script>
import BaseComponent from 'primevue/basecomponent';
export default { export default {
name: 'Row', name: 'Row',
extends: BaseComponent,
render() { render() {
return null; return null;
} }