File

src/table/head/table-head.component.ts

Description

A subcomponent that creates the thead of the table

Basic usage

Example :
    <thead cdsTableHead [model]="model"></thead>

Implements

AfterViewInit

Metadata

Index

Properties
Methods
Inputs
Outputs
Accessors

Constructor

constructor(i18n: I18n)
Parameters :
Name Type Optional
i18n I18n No

Inputs

checkboxHeaderLabel
Type : string | Observable
enableSingleSelect
Type : boolean
Default value : false
filterTitle
Type : string | Observable
model
Type : TableModel
selectAllCheckbox
Type : boolean
Default value : false
selectAllCheckboxSomeSelected
Type : boolean
Default value : false
showExpandAllToggle
Type : boolean
Default value : false
showSelectionColumn
Type : boolean
Default value : true
skeleton
Type : boolean
Default value : false
sortable
Type : boolean
Default value : true

Setting sortable to false will disable all headers including headers which are sortable. Is is possible to set the sortable state on the header item to disable/enable sorting for only some headers.

sortAscendingLabel
Type : string | Observable
sortDescendingLabel
Type : string | Observable
stickyHeader
Type : boolean
Default value : false

Outputs

collapseAllRows
Type : EventEmitter

Emits if all rows are collapsed.

deselectAll
Type : EventEmitter

Emits if all rows are deselected.

expandAllRows
Type : EventEmitter

Emits if all rows are expanded.

selectAll
Type : EventEmitter

Emits if all rows are selected.

sort
Type : EventEmitter

Emits an index of the column that wants to be sorted.

Methods

getCheckboxHeaderLabel
getCheckboxHeaderLabel()
Returns : Observable<string>
getFilterTitle
getFilterTitle()
Returns : Observable<string>
getSortAscendingLabel
getSortAscendingLabel()
Returns : Observable<string>
getSortDescendingLabel
getSortDescendingLabel()
Returns : Observable<string>
ngAfterViewInit
ngAfterViewInit()
Returns : void
onExpandAllRowsChange
onExpandAllRowsChange(expand: boolean)
Parameters :
Name Type Optional
expand boolean No
Returns : void
onSelectAllCheckboxChange
onSelectAllCheckboxChange()
Returns : void

Properties

Protected _checkboxHeaderLabel
Default value : this.i18n.getOverridable("TABLE.CHECKBOX_HEADER")
Protected _filterTitle
Default value : this.i18n.getOverridable("TABLE.FILTER")
Protected _sortAscendingLabel
Default value : this.i18n.getOverridable("TABLE.SORT_ASCENDING")
Protected _sortDescendingLabel
Default value : this.i18n.getOverridable("TABLE.SORT_DESCENDING")
Public scrollbarWidth
Type : number
Default value : 0

Accessors

checkboxHeaderLabel
getcheckboxHeaderLabel()
setcheckboxHeaderLabel(value: string | Observable)
Parameters :
Name Type Optional
value string | Observable<string> No
Returns : void
sortDescendingLabel
getsortDescendingLabel()
setsortDescendingLabel(value: string | Observable)
Parameters :
Name Type Optional
value string | Observable<string> No
Returns : void
sortAscendingLabel
getsortAscendingLabel()
setsortAscendingLabel(value: string | Observable)
Parameters :
Name Type Optional
value string | Observable<string> No
Returns : void
filterTitle
getfilterTitle()
setfilterTitle(value: string | Observable)
Parameters :
Name Type Optional
value string | Observable<string> No
Returns : void
import {
	Component,
	Input,
	Output,
	EventEmitter,
	AfterViewInit
} from "@angular/core";

import { TableModel } from "../table-model.class";
import { getScrollbarWidth } from "carbon-components-angular/utils";
import { I18n, Overridable } from "carbon-components-angular/i18n";
import { Observable } from "rxjs";
import { TableRowSize } from "../table.types";

/**
 * A subcomponent that creates the thead of the table
 *
 * ## Basic usage
 *
 * ```html
 * 	<thead cdsTableHead [model]="model"></thead>
 * ```
 */
@Component({
	// tslint:disable-next-line:component-selector
	selector: "[cdsTableHead], [ibmTableHead]",
	template: `
	<ng-container *ngIf="model">
		<tr>
			<th
				cdsTableHeadExpand
				*ngIf="model.hasExpandableRows()"
				scope="col"
				[showExpandAllToggle]="showExpandAllToggle"
				[ngClass]="{'cds--table-expand-v2': stickyHeader}"
				[id]="model.getId('expand')"
				[expanded]="model.expandableRowsCount() === model.expandedRowsCount()"
				(expandedChange)="onExpandAllRowsChange($event)">
			</th>
			<th
				*ngIf="!skeleton && showSelectionColumn && enableSingleSelect"
				scope="col"
				[id]="model.getId('select')">
				<!-- add width 0; since the carbon styles don't seem to constrain this headers width -->
			</th>
			<th
				cdsTableHeadCheckbox
				*ngIf="!skeleton && showSelectionColumn && !enableSingleSelect"
				scope="col"
				[checked]="selectAllCheckbox"
				[indeterminate]="selectAllCheckboxSomeSelected"
				[ariaLabel]="getCheckboxHeaderLabel()"
				[skeleton]="skeleton"
				[name]="model.getHeaderId('select')"
				(change)="onSelectAllCheckboxChange()"
				[id]="model.getId('select')">
			</th>
			<ng-container *ngFor="let column of model.header; let i = index">
				<th
					*ngIf="column && column.visible"
					[ngStyle]="column.style"
					cdsTableHeadCell
					scope="col"
					[class]="column.className"
					[sortable]="sortable"
					[skeleton]="skeleton"
					[id]="model.getId(i)"
					[column]="column"
					[filterTitle]="getFilterTitle()"
					[attr.colspan]="column.colSpan"
					[attr.rowspan]="column.rowSpan"
					(sort)="sort.emit(i)">
				</th>
			</ng-container>
			<th *ngIf="!skeleton && stickyHeader && scrollbarWidth"
				scope="col"
				[ngStyle]="{'width': scrollbarWidth + 'px', 'padding': 0, 'border': 0}">
				<!--
					Scrollbar pushes body to the left so this header column is added to push
					the title bar the same amount and keep the header and body columns aligned.
				-->
			</th>
		</tr>
	</ng-container>
	<ng-content></ng-content>
	`,
	styles: [`
		.cds--table-expand-v2 {
			padding-left: 2.5rem;
		}
	`]
})
export class TableHead implements AfterViewInit {
	@Input() model: TableModel;

	@Input() showSelectionColumn = true;

	@Input() enableSingleSelect = false;

	@Input() selectAllCheckboxSomeSelected = false;

	@Input() selectAllCheckbox = false;

	@Input() skeleton = false;

	@Input() stickyHeader = false;

	@Input() showExpandAllToggle = false;

	/**
	 * Setting sortable to false will disable all headers including headers which are sortable. Is is
	 * possible to set the sortable state on the header item to disable/enable sorting for only some headers.
	 */
	@Input() sortable = true;

	@Input()
	set checkboxHeaderLabel(value: string | Observable<string>) {
		this._checkboxHeaderLabel.override(value);
	}

	get checkboxHeaderLabel() {
		return this._checkboxHeaderLabel.value;
	}

	@Input()
	set sortDescendingLabel(value: string | Observable<string>) {
		this._sortDescendingLabel.override(value);
	}

	get sortDescendingLabel() {
		return this._sortDescendingLabel.value;
	}

	@Input()
	set sortAscendingLabel(value: string | Observable<string>) {
		this._sortAscendingLabel.override(value);
	}

	get sortAscendingLabel() {
		return this._sortAscendingLabel.value;
	}

	@Input()
	set filterTitle(value: string | Observable<string>) {
		this._filterTitle.override(value);
	}

	get filterTitle() {
		return this._filterTitle.value;
	}

	/**
	 * Emits an index of the column that wants to be sorted.
	 */
	@Output() sort = new EventEmitter<number>();
	/**
	 * Emits if all rows are selected.
	 *
	 * @param model
	 */
	@Output() selectAll = new EventEmitter<TableModel>();
	/**
	 * Emits if all rows are deselected.
	 *
	 * @param model
	 */
	@Output() deselectAll = new EventEmitter<TableModel>();
	/**
	 * Emits if all rows are expanded.
	 *
	 * @param model
	 */
	@Output() expandAllRows = new EventEmitter<TableModel>();
	/**
	 * Emits if all rows are collapsed.
	 *
	 * @param model
	 */
	@Output() collapseAllRows = new EventEmitter<TableModel>();

	public scrollbarWidth = 0;

	protected _checkboxHeaderLabel = this.i18n.getOverridable("TABLE.CHECKBOX_HEADER");
	protected _sortDescendingLabel = this.i18n.getOverridable("TABLE.SORT_DESCENDING");
	protected _sortAscendingLabel = this.i18n.getOverridable("TABLE.SORT_ASCENDING");
	protected _filterTitle = this.i18n.getOverridable("TABLE.FILTER");

	constructor(protected i18n: I18n) {}

	ngAfterViewInit() {
		setTimeout(() => {
			this.scrollbarWidth = getScrollbarWidth();
		});
	}

	onSelectAllCheckboxChange() {
		if (!this.selectAllCheckbox && !this.selectAllCheckboxSomeSelected) {
			this.selectAll.emit(this.model);
		} else {
			this.deselectAll.emit(this.model);
		}
	}

	onExpandAllRowsChange(expand: boolean) {
		if (expand) {
			this.expandAllRows.emit(this.model);
		} else {
			this.collapseAllRows.emit(this.model);
		}
	}

	getCheckboxHeaderLabel(): Observable<string> {
		return this._checkboxHeaderLabel.subject;
	}

	getSortDescendingLabel(): Observable<string> {
		return this._sortDescendingLabel.subject;
	}

	getSortAscendingLabel(): Observable<string> {
		return this._sortAscendingLabel.subject;
	}

	getFilterTitle(): Observable<string> {
		return this._filterTitle.subject;
	}
}

		.cds--table-expand-v2 {
			padding-left: 2.5rem;
		}
	
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""