# DataTable library Contains the DataTable component and other related components and classes. - [DataTable component](#datatable-component) * [Basic usage](#basic-usage) + [Properties](#properties) + [Events](#events) * [Details](#details) + [DataColumn Properties](#datacolumn-properties) + [DataTable DOM Events](#datatable-dom-events) + [Automatic column header translation](#automatic-column-header-translation) + [Custom tooltips](#custom-tooltips) + [Custom Empty content template](#custom-empty-content-template) + [Loading content template](#loading-content-template) + [Column Templates](#column-templates) + [Events](#events-1) - [rowClick event](#rowclick-event) - [rowDblClick event](#rowdblclick-event) - [showRowContextMenu event](#showrowcontextmenu-event) - [showRowActionsMenu event](#showrowactionsmenu-event) - [executeRowAction event](#executerowaction-event) + [Data sources](#data-sources) + [Generate schema](#generate-schema) - [Pagination Component](#pagination-component) * [Basic Usage](#basic-usage) + [Properties](#properties-1) + [Events](#events-2) * [Details](#details-1) - [Project Information](#project-information) * [Prerequisites](#prerequisites) * [Install](#install) * [Build from sources](#build-from-sources) * [NPM scripts](#npm-scripts) * [Demo](#demo) * [License](#license) ## DataTable component Displays data as a table with customizable columns and presentation. ![DataTable demo](docs/assets/datatable-demo.png) See it live: [DataTable Quickstart](https://embed.plnkr.co/80qr4YFBeHjLMdAV0F6l/) ### Basic usage **app.component.html** ```html ``` **app.component.ts** ```ts import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable'; @Component({...}) export class DataTableDemo { data: ObjectDataTableAdapter; constructor() { this.data = new ObjectDataTableAdapter( // data [ {id: 1, name: 'Name 1'}, {id: 2, name: 'Name 2'} ], // schema [ { type: 'text', key: 'id', title: 'Id', sortable: true }, { type: 'text', key: 'name', title: 'Name', cssClass: 'full-width', sortable: true } ] ); } } ``` You can also use HTML-based schema declaration like shown below: ```html ``` ```ts import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable'; @Component({...}) export class DataTableDemo { data: ObjectDataTableAdapter; constructor() { this.data = new ObjectDataTableAdapter( // data [ { id: 1, name: 'Name 1', createdBy : { name: 'user'}, createdOn: 123, icon: 'http://example.com/img.png' }, { id: 2, name: 'Name 2', createdBy : { name: 'user 2'}, createdOn: 123, icon: 'http://example.com/img.png' } ] ); } } ``` #### Properties | Name | Type | Default | Description | | --- | --- | --- | --- | | selectionMode | string | 'single' | Row selection mode. Can be none, `single` or `multiple`. For `multiple` mode you can use Cmd (macOS) or Ctrl (Win) modifier key to toggle selection for multiple rows. | | rowStyle | string | | The inline style to apply to every row, see [NgStyle](https://angular.io/docs/ts/latest/api/common/index/NgStyle-directive.html) docs for more details and usage examples | | rowStyleClass | string | | The CSS class to apply to every row | | data | DataTableAdapter | instance of **ObjectDataTableAdapter** | data source | | rows | Object[] | [] | The rows that the datatable should show | | multiselect | boolean | false | Toggles multiple row selection, renders checkboxes at the beginning of each row | | actions | boolean | false | Toggles data actions column | | actionsPosition | string (left\|right) | right | Position of the actions dropdown menu. | | fallbackThumbnail | string | | Fallback image for row where thumbnail is missing| | contextMenu | boolean | false | Toggles custom context menu for the component | | allowDropFiles | boolean | false | Toggle file drop support for rows (see **ng2-alfresco-core/UploadDirective** for more details) | | loading | boolean | false | Flag that indicates if the datatable is in loading state and needs to show the loading template. Read the documentation above to see how to configure a loading template | | showHeader | boolean | true | Toggles header visibility | | selection | DataRow[] | [] | Contains selected rows | #### Events | Name | Description | --- | --- | | [rowClick](#rowclick-event) | Emitted when user clicks the row | | [rowDblClick](#rowdblclick-event) | Emitted when user double-clicks the row | | [showRowContextMenu](#showrowcontextmenu-event) | Emitted before context menu is displayed for a row | | [showRowActionsMenu](#showrowactionsmenu-event) | Emitted before actions menu is displayed for a row | | [executeRowAction](#executerowaction-event) | Emitted when row action is executed by user | ### Details #### DataColumn Properties | Name | Type | Default | Description | | --- | --- | --- | --- | | key | string | | Data source key, can be either column/property key like `title` or property path like `createdBy.name` | | type | string (text\|image\|date) | text | Value type | | format | string | | Value format (if supported by components), for example format of the date | | sortable | boolean | true | Toggles ability to sort by this column, for example by clicking the column header | | title | string | | Display title of the column, typically used for column headers. You can use the i18n resouce key to get it translated automatically. | | template | `TemplateRef` | | Custom column template | | sr-title | string | | Screen reader title, used for accessibility purposes | | class | string | | Additional CSS class to be applied to column (header and cells) | | formatTooltip | Function | | Custom tooltip formatter function. | #### DataTable DOM Events Below are the DOM events raised by DataTable component. These events bubble up the component tree and can be handled by any parent component. | Name | Description | | --- | --- | | row-click | Raised when user clicks a row | | row-dblclick | Raised when user double-clicks a row | | row-select | Raised after user selects a row | | row-unselect | Raised after user unselects a row | For example: ```html ``` ```ts onRowClick(event) { console.log(event); } ``` ![](docs/assets/datatable-dom-events.png) #### Automatic column header translation You can also use i18n resource keys with DataColumn `title` property. The component will automatically check the corresponding i18n resources and fetch corresponding value. ```html ``` This feature is optional. Regular text either plain or converted via the `translate` pipe will still be working as it was before. #### Custom tooltips You can create custom tooltips for the table cells by providing a `formatTooltip` property with a tooltip formatter function when declaring a data column. ```html ``` And the code in this case will be similar to the following: ```ts import { DataColumn, DataRow } from 'ng2-alfresco-datatable'; @Component({...}) export class MyComponent { ... getNodeNameTooltip(row: DataRow, col: DataColumn): string { if (row) { return row.getValue('name'); } return null; } } ``` To disable the tooltip your function can return `null` or an empty string. #### Custom Empty content template You can add a template that will be shown when there are no results in your datatable: ```html

Sorry, no content

``` You can use the empty list component if you want to show the default ADF empty template. You can use any HTML layout or Angular component as a content of the empty template section by using the special `, , ` elements: ```html "'My custom Header'" "'My custom body'" "'My custom footer'" "'HTML Layout'" ``` | Name | Type | Default | Description | --- | --- | --- | --- | | emptyListImageUrl | String | empty_doc_lib.svg | The default image used as background | | emptyMsg | String | This list is empty | The default title message | | dragDropMsg | String | Drag and drop | The default drag and drop message | | additionalMsg | String | Drag and drop | The default additional message | ![](docs/assets/adf-empty-list.png) #### Loading content template You can add a template that will be shown during the loading of your data: ```html ``` ```js isLoading(): boolean { //your custom logic to identify if you are in a loading state } ``` Note: the `` and `` can be used together #### Column Templates It is possible to assign a custom column template like the following: ```html ``` Example above shows access to the underlying cell value by binding `value` property to the underlying context `value`: ```html