File

src/table/body/table-row.component.ts

Metadata

Index

Properties
Methods
Inputs
Outputs
HostBindings
HostListeners
Accessors

Constructor

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

Inputs

checkboxLabel
Type : string | Observable
enableSingleSelect
Type : boolean
Default value : false

Controls whether to enable multiple or single row selection.

expandable
Type : boolean
Default value : false
expandButtonAriaLabel
Type : string | Observable
expanded
Type : boolean
Default value : false
model
Type : TableModel

TableModel with data the table is to display.

row
Type : TableItem[]
selected
Type : boolean
Default value : false
selectionLabelColumn
Type : number

Used to populate the row selection checkbox label with a useful value if set.

Example:

Example :
<cds-table [selectionLabelColumn]="0"></cds-table>
<!-- results in aria-label="Select first column value"
(where "first column value" is the value of the first column in the row -->
showSelectionColumn
Type : boolean
Default value : true

Controls whether to show the selection checkboxes column or not.

showSelectionColumnCheckbox
Type : boolean
Default value : true

Shows or hide the checkbox in the selection column when showSelectionColumn is set to true

size
Type : TableRowSize
Default value : "md"

Size of the table rows.

skeleton
Type : boolean
Default value : false

Outputs

deselectRow
Type : EventEmitter

Emits when the row is deselected.

expandRow
Type : EventEmitter

Emits when the row is expanded

rowClick
Type : EventEmitter

Emits when a row is clicked regardless of enableSingleSelect or showSelectionColumn. Should only get emitted when a row item is selected excluding expand buttons, checkboxes, or radios.

selectRow
Type : EventEmitter

Emits when the row is selected.

HostBindings

attr.data-parent-row
Type : boolean
attr.tabindex
Type : number
class.cds--data-table--selected
Type : boolean
class.cds--expandable-row
Type : boolean
class.cds--parent-row
Type : boolean
class.tbody_row--selectable
Type : boolean

HostListeners

click
click()

Methods

getCheckboxLabel
getCheckboxLabel()
Returns : Observable<string>
getExpandButtonAriaLabel
getExpandButtonAriaLabel()
Returns : Observable<string>
onHostClick
onHostClick()
Decorators :
@HostListener('click')
Returns : void
onRowClick
onRowClick()
Returns : void
onSelectionChange
onSelectionChange()
Returns : void

Properties

Protected _checkboxLabel
Default value : this.i18n.getOverridable("TABLE.CHECKBOX_ROW")
Protected _expandButtonAriaLabel
Default value : this.i18n.getOverridable("TABLE.EXPAND_BUTTON")

Accessors

expandButtonAriaLabel
getexpandButtonAriaLabel()
setexpandButtonAriaLabel(value: string | Observable)
Parameters :
Name Type Optional
value string | Observable<string> No
Returns : void
checkboxLabel
getcheckboxLabel()
setcheckboxLabel(value: string | Observable)
Parameters :
Name Type Optional
value string | Observable<string> No
Returns : void
selectedClass
getselectedClass()
parentRowClass
getparentRowClass()
expandableRowClass
getexpandableRowClass()
selectableClass
getselectableClass()
isParentRow
getisParentRow()
isAccessible
getisAccessible()
import {
	Component,
	Input,
	Output,
	EventEmitter,
	HostBinding,
	HostListener
} from "@angular/core";
import { TableModel } from "../table-model.class";
import { I18n, Overridable } from "carbon-components-angular/i18n";
import { TableItem } from "../table-item.class";
import { Observable } from "rxjs";
import { TableRowSize } from "../table.types";

@Component({
	// tslint:disable-next-line: component-selector
	selector: "[cdsTableRow], [ibmTableRow]",
	template: `
		<ng-container *ngIf="model">
			<td
				*ngIf="model.hasExpandableRows()"
				cdsTableExpandButton
				class="cds--table-expand-v2"
				[expanded]="expanded"
				[expandable]="expandable"
				[skeleton]="skeleton"
				[ariaLabel]="getExpandButtonAriaLabel()"
				[headers]="model.getHeaderId('expand')"
				(expandRow)="expandRow.emit()">
			</td>
			<ng-container *ngIf="!skeleton && showSelectionColumn && !enableSingleSelect">
				<td
					*ngIf="!showSelectionColumnCheckbox; else tableCheckboxTemplate">
				</td>
				<ng-template #tableCheckboxTemplate>
					<td
						cdsTableCheckbox
						class="cds--table-column-checkbox"
						[size]="size"
						[selected]="selected"
						[label]="getCheckboxLabel()"
						[row]="row"
						[skeleton]="skeleton"
						[headers]="model.getHeaderId('select')"
						(selectedChange)="onSelectionChange()">
					</td>
				</ng-template>
			</ng-container>
			<td
				*ngIf="!skeleton && showSelectionColumn && enableSingleSelect"
				cdsTableRadio
				[selected]="selected"
				[label]="getCheckboxLabel()"
				[row]="row"
				[skeleton]="skeleton"
				[headers]="model.getHeaderId('select')"
				(change)="onSelectionChange()">
			</td>
			<ng-container *ngFor="let item of row; let j = index">
				<td
					*ngIf="item && model.getHeader(j) && model.getHeader(j).visible"
					cdsTableData
					[headers]="model.getHeaderId(j, item.colSpan)"
					[item]="item"
					[title]="item.title"
					[class]="model.getHeader(j).className"
					[ngStyle]="model.getHeader(j).style"
					[skeleton]="skeleton"
					[attr.colspan]="item.colSpan"
					[attr.rowspan]="item.rowSpan"
					(click)="onRowClick()"
					(keydown.enter)="onRowClick()">
				</td>
				<td
					*ngIf="item && model.getHeader(j) == null"
					cdsTableData
					[headers]="model.getHeaderId(j, item.colSpan)"
					[item]="item"
					[title]="item.title"
					[skeleton]="skeleton"
					[attr.colspan]="item.colSpan"
					[attr.rowspan]="item.rowSpan"
					(click)="onRowClick()"
					(keydown.enter)="onRowClick()">
				</td>
			</ng-container>
		</ng-container>
		<ng-content></ng-content>
	`
})
export class TableRowComponent {
	/**
	 * `TableModel` with data the table is to display.
	 */
	@Input() model: TableModel;

	@Input() row: TableItem[];

	@Input() expanded = false;

	@Input() expandable = false;

	@Input() selected = false;

	/**
	 * Size of the table rows.
	 */
	@Input() size: TableRowSize = "md";

	/**
	 * Controls whether to enable multiple or single row selection.
	 */
	@Input() enableSingleSelect = false;

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

	get expandButtonAriaLabel() {
		return this._expandButtonAriaLabel.value;
	}

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

	get checkboxLabel() {
		return this._checkboxLabel.value;
	}

	/**
	 * Controls whether to show the selection checkboxes column or not.
	 */
	@Input() showSelectionColumn = true;

	/**
	 * Shows or hide the checkbox in the selection column when `showSelectionColumn`
	 * is set to true
	 */
	@Input() showSelectionColumnCheckbox = true;

	/**
	 * Used to populate the row selection checkbox label with a useful value if set.
	 *
	 * Example:
	 * ```
	 * <cds-table [selectionLabelColumn]="0"></cds-table>
	 * <!-- results in aria-label="Select first column value"
	 * (where "first column value" is the value of the first column in the row -->
	 * ```
	 */
	@Input() selectionLabelColumn: number;

	@Input() skeleton = false;

	/**
	 * Emits when the row is selected.
	 */
	@Output() selectRow = new EventEmitter();

	/**
	 * Emits when the row is deselected.
	 */
	@Output() deselectRow = new EventEmitter();

	/**
	 * Emits when the row is expanded
	 */
	@Output() expandRow = new EventEmitter();

	/**
	 * Emits when a row is clicked regardless of `enableSingleSelect` or `showSelectionColumn`.
	 * Should only get emitted when a row item is selected excluding expand buttons,
	 * checkboxes, or radios.
	 */
	@Output() rowClick = new EventEmitter();

	@HostBinding("class.cds--data-table--selected") get selectedClass() {
		return this.selected;
	}

	@HostBinding("class.cds--parent-row") get parentRowClass() {
		return this.expandable;
	}

	@HostBinding("class.cds--expandable-row") get expandableRowClass() {
		return this.expanded;
	}

	@HostBinding("class.tbody_row--selectable") get selectableClass() {
		return false; // this.singleSelect
	}

	@HostBinding("attr.data-parent-row") get isParentRow() {
		return this.expandable ? true : null;
	}

	@HostBinding("attr.tabindex") get isAccessible() {
		return this.enableSingleSelect && !this.showSelectionColumn ? 0 : null;
	}

	protected _checkboxLabel = this.i18n.getOverridable("TABLE.CHECKBOX_ROW");
	protected _expandButtonAriaLabel = this.i18n.getOverridable("TABLE.EXPAND_BUTTON");

	constructor(protected i18n: I18n) { }

	@HostListener("click")
	onHostClick() {
		if (this.enableSingleSelect && !this.showSelectionColumn) {
			this.onSelectionChange();
		}
	}

	onRowClick() {
		this.rowClick.emit();
	}

	onSelectionChange() {
		if (this.selected) {
			this.deselectRow.emit();
		} else {
			this.selectRow.emit();
		}
	}

	getCheckboxLabel(): Observable<string> {
		return this._checkboxLabel.subject;
	}

	getExpandButtonAriaLabel(): Observable<string> {
		return this._expandButtonAriaLabel.subject;
	}
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""