2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-06-08 11:26:48 +00:00
|
|
|
<thead :class="cx('thead')" :style="sx('thead')" role="rowgroup" v-bind="columnGroup ? { ...ptm('thead'), ...getColumnGroupPT('root') } : ptm('thead')" data-pc-section="thead">
|
2022-09-06 12:03:37 +00:00
|
|
|
<template v-if="!columnGroup">
|
2023-05-08 14:08:06 +00:00
|
|
|
<tr role="row" v-bind="ptm('headerRow')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-for="(col, i) of columns" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || i">
|
|
|
|
<DTHeaderCell
|
|
|
|
v-if="!columnProp(col, 'hidden') && (rowGroupMode !== 'subheader' || groupRowsBy !== columnProp(col, 'field'))"
|
|
|
|
:column="col"
|
2023-06-02 11:10:18 +00:00
|
|
|
:index="i"
|
2022-09-14 11:26:01 +00:00
|
|
|
@column-click="$emit('column-click', $event)"
|
|
|
|
@column-mousedown="$emit('column-mousedown', $event)"
|
|
|
|
@column-dragstart="$emit('column-dragstart', $event)"
|
|
|
|
@column-dragover="$emit('column-dragover', $event)"
|
|
|
|
@column-dragleave="$emit('column-dragleave', $event)"
|
|
|
|
@column-drop="$emit('column-drop', $event)"
|
|
|
|
:groupRowsBy="groupRowsBy"
|
|
|
|
:groupRowSortField="groupRowSortField"
|
|
|
|
:reorderableColumns="reorderableColumns"
|
|
|
|
:resizableColumns="resizableColumns"
|
|
|
|
@column-resizestart="$emit('column-resizestart', $event)"
|
|
|
|
:sortMode="sortMode"
|
|
|
|
:sortField="sortField"
|
|
|
|
:sortOrder="sortOrder"
|
|
|
|
:multiSortMeta="multiSortMeta"
|
|
|
|
:allRowsSelected="allRowsSelected"
|
|
|
|
:empty="empty"
|
|
|
|
@checkbox-change="$emit('checkbox-change', $event)"
|
|
|
|
:filters="filters"
|
|
|
|
:filterDisplay="filterDisplay"
|
|
|
|
:filtersStore="filtersStore"
|
2022-12-08 11:04:25 +00:00
|
|
|
:filterInputProps="filterInputProps"
|
2022-09-14 11:26:01 +00:00
|
|
|
@filter-change="$emit('filter-change', $event)"
|
|
|
|
@filter-apply="$emit('filter-apply')"
|
|
|
|
@operator-change="$emit('operator-change', $event)"
|
|
|
|
@matchmode-change="$emit('matchmode-change', $event)"
|
|
|
|
@constraint-add="$emit('constraint-add', $event)"
|
|
|
|
@constraint-remove="$emit('constraint-remove', $event)"
|
|
|
|
@apply-click="$emit('apply-click', $event)"
|
2023-04-13 14:42:33 +00:00
|
|
|
:headerCheckboxIconTemplate="headerCheckboxIconTemplate"
|
2023-05-08 14:08:06 +00:00
|
|
|
:pt="pt"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</tr>
|
2023-05-08 14:08:06 +00:00
|
|
|
<tr v-if="filterDisplay === 'row'" role="row" v-bind="ptm('headerRow')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-for="(col, i) of columns" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || i">
|
2023-05-09 14:57:31 +00:00
|
|
|
<th
|
|
|
|
v-if="!columnProp(col, 'hidden') && (rowGroupMode !== 'subheader' || groupRowsBy !== columnProp(col, 'field'))"
|
|
|
|
:style="getFilterColumnHeaderStyle(col)"
|
|
|
|
:class="getFilterColumnHeaderClass(col)"
|
2023-06-02 11:10:18 +00:00
|
|
|
v-bind="{ ...getColumnPT(col, 'root', i), ...getColumnPT(col, 'headerCell', i) }"
|
2023-05-09 14:57:31 +00:00
|
|
|
>
|
|
|
|
<DTHeaderCheckbox v-if="columnProp(col, 'selectionMode') === 'multiple'" :checked="allRowsSelected" :disabled="empty" @change="$emit('checkbox-change', $event)" :column="col" :pt="pt" />
|
2022-09-14 11:26:01 +00:00
|
|
|
<DTColumnFilter
|
|
|
|
v-if="col.children && col.children.filter"
|
|
|
|
:field="columnProp(col, 'filterField') || columnProp(col, 'field')"
|
|
|
|
:type="columnProp(col, 'dataType')"
|
|
|
|
display="row"
|
|
|
|
:showMenu="columnProp(col, 'showFilterMenu')"
|
|
|
|
:filterElement="col.children && col.children.filter"
|
|
|
|
:filterHeaderTemplate="col.children && col.children.filterheader"
|
|
|
|
:filterFooterTemplate="col.children && col.children.filterfooter"
|
|
|
|
:filterClearTemplate="col.children && col.children.filterclear"
|
|
|
|
:filterApplyTemplate="col.children && col.children.filterapply"
|
2023-04-14 06:58:37 +00:00
|
|
|
:filterIconTemplate="col.children && col.children.filtericon"
|
|
|
|
:filterAddIconTemplate="col.children && col.children.filteraddicon"
|
|
|
|
:filterRemoveIconTemplate="col.children && col.children.filterremoveicon"
|
|
|
|
:filterClearIconTemplate="col.children && col.children.filterclearicon"
|
2022-09-14 11:26:01 +00:00
|
|
|
:filters="filters"
|
|
|
|
:filtersStore="filtersStore"
|
2022-12-08 11:04:25 +00:00
|
|
|
:filterInputProps="filterInputProps"
|
2022-09-14 11:26:01 +00:00
|
|
|
@filter-change="$emit('filter-change', $event)"
|
|
|
|
@filter-apply="$emit('filter-apply')"
|
|
|
|
:filterMenuStyle="columnProp(col, 'filterMenuStyle')"
|
|
|
|
:filterMenuClass="columnProp(col, 'filterMenuClass')"
|
|
|
|
:showOperator="columnProp(col, 'showFilterOperator')"
|
|
|
|
:showClearButton="columnProp(col, 'showClearButton')"
|
|
|
|
:showApplyButton="columnProp(col, 'showApplyButton')"
|
|
|
|
:showMatchModes="columnProp(col, 'showFilterMatchModes')"
|
|
|
|
:showAddButton="columnProp(col, 'showAddButton')"
|
|
|
|
:matchModeOptions="columnProp(col, 'filterMatchModeOptions')"
|
|
|
|
:maxConstraints="columnProp(col, 'maxConstraints')"
|
|
|
|
@operator-change="$emit('operator-change', $event)"
|
|
|
|
@matchmode-change="$emit('matchmode-change', $event)"
|
|
|
|
@constraint-add="$emit('constraint-add', $event)"
|
|
|
|
@constraint-remove="$emit('constraint-remove', $event)"
|
|
|
|
@apply-click="$emit('apply-click', $event)"
|
2023-05-09 14:57:31 +00:00
|
|
|
:column="col"
|
2023-06-05 08:55:38 +00:00
|
|
|
:unstyled="unstyled"
|
|
|
|
:pt="pt"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</th>
|
|
|
|
</template>
|
|
|
|
</tr>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
2023-06-02 11:10:18 +00:00
|
|
|
<tr v-for="(row, i) of getHeaderRows()" :key="i" role="row" v-bind="{ ...ptm('headerRow'), ...getRowPT(row, 'root', i) }">
|
2022-09-14 11:26:01 +00:00
|
|
|
<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"
|
|
|
|
:allRowsSelected="allRowsSelected"
|
|
|
|
:empty="empty"
|
|
|
|
@checkbox-change="$emit('checkbox-change', $event)"
|
|
|
|
:filters="filters"
|
|
|
|
:filterDisplay="filterDisplay"
|
|
|
|
:filtersStore="filtersStore"
|
|
|
|
@filter-change="$emit('filter-change', $event)"
|
|
|
|
@filter-apply="$emit('filter-apply')"
|
|
|
|
@operator-change="$emit('operator-change', $event)"
|
|
|
|
@matchmode-change="$emit('matchmode-change', $event)"
|
|
|
|
@constraint-add="$emit('constraint-add', $event)"
|
|
|
|
@constraint-remove="$emit('constraint-remove', $event)"
|
|
|
|
@apply-click="$emit('apply-click', $event)"
|
2023-04-13 14:42:33 +00:00
|
|
|
:headerCheckboxIconTemplate="headerCheckboxIconTemplate"
|
2023-05-08 14:08:06 +00:00
|
|
|
:pt="pt"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</tr>
|
|
|
|
</template>
|
|
|
|
</thead>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-08 14:08:06 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
2023-07-13 11:12:07 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2022-12-08 11:04:25 +00:00
|
|
|
import ColumnFilter from './ColumnFilter.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
import HeaderCell from './HeaderCell.vue';
|
|
|
|
import HeaderCheckbox from './HeaderCheckbox.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'TableHeader',
|
2023-06-08 11:16:48 +00:00
|
|
|
hostName: 'DataTable',
|
2023-05-08 14:08:06 +00:00
|
|
|
extends: BaseComponent,
|
2022-09-14 11:26:01 +00:00
|
|
|
emits: [
|
|
|
|
'column-click',
|
|
|
|
'column-mousedown',
|
|
|
|
'column-dragstart',
|
|
|
|
'column-dragover',
|
|
|
|
'column-dragleave',
|
|
|
|
'column-drop',
|
|
|
|
'column-resizestart',
|
|
|
|
'checkbox-change',
|
|
|
|
'filter-change',
|
|
|
|
'filter-apply',
|
|
|
|
'operator-change',
|
|
|
|
'matchmode-change',
|
|
|
|
'constraint-add',
|
|
|
|
'constraint-remove',
|
|
|
|
'filter-clear',
|
|
|
|
'apply-click'
|
|
|
|
],
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
2022-09-14 11:26:01 +00:00
|
|
|
columnGroup: {
|
2022-09-06 12:03:37 +00:00
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
columns: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
rowGroupMode: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
groupRowsBy: {
|
2022-12-08 11:04:25 +00:00
|
|
|
type: [Array, String, Function],
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
resizableColumns: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
allRowsSelected: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
empty: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
sortMode: {
|
|
|
|
type: String,
|
|
|
|
default: 'single'
|
|
|
|
},
|
|
|
|
groupRowSortField: {
|
|
|
|
type: [String, Function],
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
sortField: {
|
|
|
|
type: [String, Function],
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
sortOrder: {
|
|
|
|
type: Number,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
multiSortMeta: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
filterDisplay: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
filtersStore: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
reorderableColumns: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
filterInputProps: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
2023-04-13 14:42:33 +00:00
|
|
|
},
|
|
|
|
headerCheckboxIconTemplate: {
|
2023-04-13 18:05:42 +00:00
|
|
|
type: Function,
|
2023-04-13 14:42:33 +00:00
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
columnProp(col, prop) {
|
|
|
|
return ObjectUtils.getVNodeProp(col, prop);
|
|
|
|
},
|
2023-06-02 11:10:18 +00:00
|
|
|
getColumnGroupPT(key) {
|
|
|
|
const columnGroupMetaData = {
|
2023-05-10 11:39:25 +00:00
|
|
|
props: this.getColumnGroupProps(),
|
|
|
|
parent: {
|
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
2023-06-02 11:10:18 +00:00
|
|
|
},
|
|
|
|
context: {
|
|
|
|
type: 'header'
|
2023-05-10 11:39:25 +00:00
|
|
|
}
|
2023-06-02 11:10:18 +00:00
|
|
|
};
|
|
|
|
|
2023-07-13 11:12:07 +00:00
|
|
|
return mergeProps(this.ptm(`columnGroup.${key}`, { columnGroup: columnGroupMetaData }), this.ptm(`columnGroup.${key}`, columnGroupMetaData), this.ptmo(this.getColumnGroupProps(), key, columnGroupMetaData));
|
2023-05-10 11:39:25 +00:00
|
|
|
},
|
|
|
|
getColumnGroupProps() {
|
|
|
|
return this.columnGroup && this.columnGroup.props && this.columnGroup.props.pt ? this.columnGroup.props.pt : undefined; //@todo
|
|
|
|
},
|
2023-06-02 11:10:18 +00:00
|
|
|
getRowPT(row, key, index) {
|
|
|
|
const rowMetaData = {
|
2023-05-10 11:39:25 +00:00
|
|
|
props: row.props,
|
|
|
|
parent: {
|
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
2023-06-02 11:10:18 +00:00
|
|
|
},
|
|
|
|
context: {
|
|
|
|
index
|
2023-05-10 11:39:25 +00:00
|
|
|
}
|
2023-06-02 11:10:18 +00:00
|
|
|
};
|
|
|
|
|
2023-07-13 11:12:07 +00:00
|
|
|
return mergeProps(this.ptm(`row.${key}`, { row: rowMetaData }), this.ptm(`row.${key}`, rowMetaData), this.ptmo(this.getRowProp(row), key, rowMetaData));
|
2023-05-10 11:39:25 +00:00
|
|
|
},
|
|
|
|
getRowProp(row) {
|
|
|
|
return row.props && row.props.pt ? row.props.pt : undefined; //@todo
|
|
|
|
},
|
2023-06-02 11:10:18 +00:00
|
|
|
getColumnPT(column, key, index) {
|
|
|
|
const columnMetaData = {
|
2023-05-09 14:57:31 +00:00
|
|
|
props: column.props,
|
|
|
|
parent: {
|
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
2023-06-02 11:10:18 +00:00
|
|
|
},
|
|
|
|
context: {
|
|
|
|
index
|
2023-05-09 14:57:31 +00:00
|
|
|
}
|
2023-06-02 11:10:18 +00:00
|
|
|
};
|
|
|
|
|
2023-07-13 11:12:07 +00:00
|
|
|
return mergeProps(this.ptm(`column.${key}`, { column: columnMetaData }), this.ptm(`column.${key}`, columnMetaData), this.ptmo(this.getColumnProp(column), key, columnMetaData));
|
2023-05-09 14:57:31 +00:00
|
|
|
},
|
|
|
|
getColumnProp(column) {
|
|
|
|
return column.props && column.props.pt ? column.props.pt : undefined; //@todo
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
getFilterColumnHeaderClass(column) {
|
2023-06-02 06:52:13 +00:00
|
|
|
return [this.cx('headerCell', { column }), this.columnProp(column, 'filterHeaderClass'), this.columnProp(column, 'class')];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
getFilterColumnHeaderStyle(column) {
|
|
|
|
return [this.columnProp(column, 'filterHeaderStyle'), this.columnProp(column, 'style')];
|
|
|
|
},
|
|
|
|
getHeaderRows() {
|
|
|
|
let rows = [];
|
|
|
|
|
|
|
|
let columnGroup = this.columnGroup;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (columnGroup.children && columnGroup.children.default) {
|
|
|
|
for (let child of columnGroup.children.default()) {
|
|
|
|
if (child.type.name === 'Row') {
|
|
|
|
rows.push(child);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (child.children && child.children instanceof Array) {
|
2022-09-06 12:03:37 +00:00
|
|
|
rows = child.children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
getHeaderColumns(row) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let cols = [];
|
|
|
|
|
|
|
|
if (row.children && row.children.default) {
|
2022-09-14 11:26:01 +00:00
|
|
|
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);
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return cols;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2022-09-14 11:26:01 +00:00
|
|
|
DTHeaderCell: HeaderCell,
|
|
|
|
DTHeaderCheckbox: HeaderCheckbox,
|
|
|
|
DTColumnFilter: ColumnFilter
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|