import Component from '@glimmer/component'; import { type RowSortingSignature } from '../../../../interfaces/components/models-table/themes/default/row-sorting-signature.interface'; import ModelsTableColumn, { propertyNameToTitle, } from '../../../../utils/emt/emt-column'; import { shownColumnsBody } from '../../../../utils/emt/shown-columns-body.function'; /** * Table header item used within {@link DefaultTheme.TableHeader | TableHeader}. * * Component generates tr with column titles in the separated cells. Click by each cell will sort table data by selected field. * Check properties {@link Core.ModelsTableColumn.disableSorting} and {@link Core.ModelsTableColumn.sortedBy}. * * Usage example: * * ```html * * * * * {{! ... }} * * {{! ... }} * * {{! .... }} * * ``` * * Usage with a block context: * * ```html * * * * * {{#each MT.visibleProcessedColumns as |column|}} * {{column.columnTitle}} * {{/each}} * * {{! ... }} * * {{! ... }} * * {{! .... }} * * ``` * * ModelsTableRowSorting yields references to the following contextual components: * * * {@link DefaultTheme.RowSortingCell | RowSortingCell} - component used as sorting row cell. Clicking on it causes column sorting * * References to the following properties are yielded: * * * {@link shouldAddExtraColumn} - determines if extra column should be added to the row in the `thead`. It happens when rows grouping is used and extra column with group values exists * * Check own docs for each component to get detailed info. */ export default class RowSorting extends Component { protected get shownColumns(): ModelsTableColumn[] { return shownColumnsBody(this.args.processedColumns, 'colspanForSortCell'); } /** * @default false */ protected get shouldAddExtraColumn(): boolean { return ( this.args.displayGroupedValueAs === 'column' && this.args.useDataGrouping && !!this.args.visibleProcessedColumns.length ); } protected get currentGroupingPropertyNameTitlelized(): string | undefined { return propertyNameToTitle(this.args.currentGroupingPropertyName); } }