Refactor #3832 Refactor #3833 - For TreeTable

pull/3861/head
Tuğçe Küçükoğlu 2023-04-13 11:53:28 +03:00
parent f592ab71d8
commit 7ee4c0ac83
6 changed files with 110 additions and 30 deletions

View File

@ -443,23 +443,39 @@ const TreeTableEvents = [
const TreeTableSlots = [ const TreeTableSlots = [
{ {
name: 'header', name: 'header',
description: "Custom content for the component's header" description: "Custom content for the component's header."
}, },
{ {
name: 'paginatorstart', name: 'paginatorstart',
description: "Custom content for the component paginator's left side" description: "Custom content for the component paginator's left side."
}, },
{ {
name: 'paginatorend', name: 'paginatorend',
description: "Custom content for the component paginator's right side" description: "Custom content for the component paginator's right side."
}, },
{ {
name: 'empty', name: 'empty',
description: 'Custom content when there is no data to display' description: 'Custom content when there is no data to display.'
}, },
{ {
name: 'footer', name: 'footer',
description: "Custom content for the component's footer" description: "Custom content for the component's footer."
},
{
name: 'loadingicon',
description: 'Custom loading icon template.'
},
{
name: 'togglericon',
description: 'Custom toggler icon template.'
},
{
name: 'checkboxicon',
description: 'Custom checkbox icon template.'
},
{
name: 'sorticon',
description: 'Custom sort icon template.'
} }
]; ];

View File

@ -1,24 +1,28 @@
<template> <template>
<td :style="containerStyle" :class="containerClass" role="cell"> <td :style="containerStyle" :class="containerClass" role="cell">
<button v-if="columnProp('expander')" v-ripple type="button" class="p-treetable-toggler p-link" @click="toggle" :style="togglerStyle" tabindex="-1"> <button v-if="columnProp('expander')" v-ripple type="button" class="p-treetable-toggler p-link" @click="toggle" :style="togglerStyle" tabindex="-1">
<i :class="togglerIcon"></i> <component :is="templates['togglericon'] ? templates['togglericon'] : expanded ? 'ChevronDownIcon' : 'ChevronRightIcon'" :expanded="expanded" class="p-treetable-toggler-icon" />
</button> </button>
<div v-if="checkboxSelectionMode && columnProp('expander')" :class="['p-checkbox p-treetable-checkbox p-component', { 'p-checkbox-focused': checkboxFocused }]" @click="toggleCheckbox"> <div v-if="checkboxSelectionMode && columnProp('expander')" :class="['p-checkbox p-treetable-checkbox p-component', { 'p-checkbox-focused': checkboxFocused }]" @click="toggleCheckbox">
<div class="p-hidden-accessible"> <div class="p-hidden-accessible">
<input type="checkbox" @focus="onCheckboxFocus" @blur="onCheckboxBlur" tabindex="-1" /> <input type="checkbox" @focus="onCheckboxFocus" @blur="onCheckboxBlur" tabindex="-1" />
</div> </div>
<div ref="checkboxEl" :class="checkboxClass"> <div ref="checkboxEl" :class="checkboxClass">
<span :class="checkboxIcon"></span> <component :is="templates['checkboxicon'] ? templates['checkboxicon'] : checked ? 'CheckIcon' : partialChecked ? 'MinusIcon' : null" :checked="checked" :partialChecked="partialChecked" class="p-checkbox-icon" />
</div> </div>
</div> </div>
<component v-if="column.children && column.children.body" :is="column.children.body" :node="node" :column="column" /> <component v-if="column.children && column.children.body" :is="column.children.body" :node="node" :column="column" />
<template v-else <template v-else>
><span>{{ resolveFieldData(node.data, columnProp('field')) }}</span></template <span>{{ resolveFieldData(node.data, columnProp('field')) }}</span>
> </template>
</td> </td>
</template> </template>
<script> <script>
import CheckIcon from 'primevue/icon/check';
import ChevronDownIcon from 'primevue/icon/chevrondown';
import ChevronRightIcon from 'primevue/icon/chevronright';
import MinusIcon from 'primevue/icon/minus';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
import { DomHandler, ObjectUtils } from 'primevue/utils'; import { DomHandler, ObjectUtils } from 'primevue/utils';
@ -61,6 +65,10 @@ export default {
partialChecked: { partialChecked: {
type: Boolean, type: Boolean,
default: false default: false
},
templates: {
type: null,
default: null
} }
}, },
data() { data() {
@ -146,19 +154,19 @@ export default {
visibility: this.leaf ? 'hidden' : 'visible' visibility: this.leaf ? 'hidden' : 'visible'
}; };
}, },
togglerIcon() {
return ['p-treetable-toggler-icon pi', { 'pi-chevron-right': !this.expanded, 'pi-chevron-down': this.expanded }];
},
checkboxSelectionMode() { checkboxSelectionMode() {
return this.selectionMode === 'checkbox'; return this.selectionMode === 'checkbox';
}, },
checkboxClass() { checkboxClass() {
return ['p-checkbox-box', { 'p-highlight': this.checked, 'p-focus': this.checkboxFocused, 'p-indeterminate': this.partialChecked }]; return ['p-checkbox-box', { 'p-highlight': this.checked, 'p-focus': this.checkboxFocused, 'p-indeterminate': this.partialChecked }];
},
checkboxIcon() {
return ['p-checkbox-icon', { 'pi pi-check': this.checked, 'pi pi-minus': this.partialChecked }];
} }
}, },
components: {
ChevronRightIcon: ChevronRightIcon,
ChevronDownIcon: ChevronDownIcon,
CheckIcon: CheckIcon,
MinusIcon: MinusIcon
},
directives: { directives: {
ripple: Ripple ripple: Ripple
} }

View File

@ -3,12 +3,17 @@
<span v-if="resizableColumns && !columnProp('frozen')" class="p-column-resizer" @mousedown="onResizeStart"></span> <span v-if="resizableColumns && !columnProp('frozen')" class="p-column-resizer" @mousedown="onResizeStart"></span>
<component v-if="column.children && column.children.header" :is="column.children.header" :column="column" /> <component v-if="column.children && column.children.header" :is="column.children.header" :column="column" />
<span v-if="columnProp('header')" class="p-column-title">{{ columnProp('header') }}</span> <span v-if="columnProp('header')" class="p-column-title">{{ columnProp('header') }}</span>
<span v-if="columnProp('sortable')" :class="sortableColumnIcon"></span> <span v-if="columnProp('sortable')">
<component :is="templates ? templates : findSortIcon" :sorted="sortableColumnIcon[1].sorted" :sortOrder="sortableColumnIcon[1].sortOrder" class="p-sortable-column-icon pi-fw" />
</span>
<span v-if="isMultiSorted()" class="p-sortable-column-badge">{{ getMultiSortMetaIndex() + 1 }}</span> <span v-if="isMultiSorted()" class="p-sortable-column-badge">{{ getMultiSortMetaIndex() + 1 }}</span>
</th> </th>
</template> </template>
<script> <script>
import SortAltIcon from 'primevue/icon/sortalt';
import SortAmountDownIcon from 'primevue/icon/sortamountdown';
import SortAmountUpAltIcon from 'primevue/icon/sortamountupalt';
import { DomHandler, ObjectUtils } from 'primevue/utils'; import { DomHandler, ObjectUtils } from 'primevue/utils';
export default { export default {
@ -38,6 +43,10 @@ export default {
sortMode: { sortMode: {
type: String, type: String,
default: 'single' default: 'single'
},
templates: {
type: Function,
default: null
} }
}, },
data() { data() {
@ -163,25 +172,38 @@ export default {
} }
return [ return [
'p-sortable-column-icon pi pi-fw',
{ {
'pi-sort-alt': !sorted, SortAltIcon: !sorted,
'pi-sort-amount-up-alt': sorted && sortOrder > 0, SortAmountUpAltIcon: sorted && sortOrder > 0,
'pi-sort-amount-down': sorted && sortOrder < 0 SortAmountDownIcon: sorted && sortOrder < 0
},
{
sorted,
sortOrder
} }
]; ];
}, },
findSortIcon() {
const sortIcon = this.sortableColumnIcon[0];
return Object.keys(sortIcon).find((key) => sortIcon[key] === true);
},
ariaSort() { ariaSort() {
if (this.columnProp('sortable')) { if (this.columnProp('sortable')) {
const sortIcon = this.sortableColumnIcon; const sortIcon = this.sortableColumnIcon[0];
if (sortIcon[1]['pi-sort-amount-down']) return 'descending'; if (sortIcon['SortAmountDownIcon']) return 'descending';
else if (sortIcon[1]['pi-sort-amount-up-alt']) return 'ascending'; else if (sortIcon['SortAmountUpAltIcon']) return 'ascending';
else return 'none'; else return 'none';
} else { } else {
return null; return null;
} }
} }
},
components: {
SortAltIcon: SortAltIcon,
SortAmountUpAltIcon: SortAmountUpAltIcon,
SortAmountDownIcon: SortAmountDownIcon
} }
}; };
</script> </script>

View File

@ -382,6 +382,31 @@ export interface TreeTableSlots {
* Custom empty template. * Custom empty template.
*/ */
empty(): VNode[]; empty(): VNode[];
/**
* Custom loading icon template.
*/
loadingicon(): VNode[];
/**
* Custom toggler icon template.
*/
togglericon(): VNode[];
/**
* Custom checkbox icon template.
*/
checkboxicon(): VNode[];
/**
* Custom sort icon template.
*/
sorticon(scope: {
/**
* Whether or not column is sorted
*/
sorted: TreeNode;
/**
* Current sort order
*/
sortOrder: boolean;
}): VNode[];
} }
/** /**

View File

@ -2,7 +2,9 @@
<div :class="containerClass" data-scrollselectors=".p-treetable-scrollable-body" role="table"> <div :class="containerClass" data-scrollselectors=".p-treetable-scrollable-body" role="table">
<div v-if="loading" class="p-treetable-loading"> <div v-if="loading" class="p-treetable-loading">
<div class="p-treetable-loading-overlay p-component-overlay"> <div class="p-treetable-loading-overlay p-component-overlay">
<i :class="loadingIconClass"></i> <slot name="loadingicon">
<component :is="loadingIcon ? 'span' : 'SpinnerIcon'" spin :class="['p-treetable-loading-icon', loadingIcon]" />
</slot>
</div> </div>
</div> </div>
<div v-if="$slots.header" class="p-treetable-header"> <div v-if="$slots.header" class="p-treetable-header">
@ -41,6 +43,7 @@
:sortOrder="d_sortOrder" :sortOrder="d_sortOrder"
:multiSortMeta="d_multiSortMeta" :multiSortMeta="d_multiSortMeta"
:sortMode="sortMode" :sortMode="sortMode"
:templates="$slots['sorticon']"
@column-click="onColumnHeaderClick" @column-click="onColumnHeaderClick"
@column-resizestart="onColumnResizeStart" @column-resizestart="onColumnResizeStart"
></TTHeaderCell> ></TTHeaderCell>
@ -69,6 +72,7 @@
:ariaSetSize="dataToRender.length" :ariaSetSize="dataToRender.length"
:ariaPosInset="index + 1" :ariaPosInset="index + 1"
:tabindex="setTabindex(node, index)" :tabindex="setTabindex(node, index)"
:templates="$slots"
@node-toggle="onNodeToggle" @node-toggle="onNodeToggle"
@node-click="onNodeClick" @node-click="onNodeClick"
@checkbox-change="onCheckboxChange" @checkbox-change="onCheckboxChange"
@ -118,6 +122,7 @@
<script> <script>
import { FilterService } from 'primevue/api'; import { FilterService } from 'primevue/api';
import SpinnerIcon from 'primevue/icon/spinner';
import Paginator from 'primevue/paginator'; import Paginator from 'primevue/paginator';
import { DomHandler, ObjectUtils } from 'primevue/utils'; import { DomHandler, ObjectUtils } from 'primevue/utils';
import FooterCell from './FooterCell.vue'; import FooterCell from './FooterCell.vue';
@ -214,7 +219,7 @@ export default {
}, },
loadingIcon: { loadingIcon: {
type: String, type: String,
default: 'pi pi-spinner' default: undefined
}, },
rowHover: { rowHover: {
type: Boolean, type: Boolean,
@ -970,16 +975,14 @@ export default {
return data ? data.length : 0; return data ? data.length : 0;
} }
},
loadingIconClass() {
return ['p-treetable-loading-icon pi-spin', this.loadingIcon];
} }
}, },
components: { components: {
TTRow: TreeTableRow, TTRow: TreeTableRow,
TTPaginator: Paginator, TTPaginator: Paginator,
TTHeaderCell: HeaderCell, TTHeaderCell: HeaderCell,
TTFooterCell: FooterCell TTFooterCell: FooterCell,
SpinnerIcon: SpinnerIcon
} }
}; };
</script> </script>

View File

@ -27,6 +27,7 @@
:selectionMode="selectionMode" :selectionMode="selectionMode"
:checked="checked" :checked="checked"
:partialChecked="partialChecked" :partialChecked="partialChecked"
:templates="templates"
@node-toggle="$emit('node-toggle', $event)" @node-toggle="$emit('node-toggle', $event)"
@checkbox-toggle="toggleCheckbox" @checkbox-toggle="toggleCheckbox"
></TTBodyCell> ></TTBodyCell>
@ -46,6 +47,7 @@
:indentation="indentation" :indentation="indentation"
:ariaPosInset="node.children.indexOf(childNode) + 1" :ariaPosInset="node.children.indexOf(childNode) + 1"
:ariaSetSize="node.children.length" :ariaSetSize="node.children.length"
:templates="templates"
@node-toggle="$emit('node-toggle', $event)" @node-toggle="$emit('node-toggle', $event)"
@node-click="$emit('node-click', $event)" @node-click="$emit('node-click', $event)"
@checkbox-change="onCheckboxChange" @checkbox-change="onCheckboxChange"
@ -104,6 +106,10 @@ export default {
ariaPosInset: { ariaPosInset: {
type: Number, type: Number,
default: null default: null
},
templates: {
type: null,
default: null
} }
}, },
nodeTouched: false, nodeTouched: false,