# DataTable Component - [Prerequisites](#prerequisites) - [Install](#install) - [Basic usage](#basic-usage) * [DataTable Properties](#datatable-properties) * [DataColumn Properties](#datacolumn-properties) * [DataTable Events](#datatable-events) * [DataTable DOM Events](#datatable-dom-events) * [Custom Empty content template](#custom-empty-content-template) * [Default Empty content template](#default-empty-content-template) * [Loading content template](#loading-content-template) * [Column Templates](#column-templates) * [Events](#events) + [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) * [Properties](#properties) * [Events](#events-1) - [Build from sources](#build-from-sources) - [NPM scripts](#npm-scripts) - [Demo](#demo) - [License](#license) See it live: [DataTable Quickstart](https://embed.plnkr.co/80qr4YFBeHjLMdAV0F6l/) ## Prerequisites Before you start using this development framework, make sure you have installed all required software and done all the necessary configuration, see this [page](https://github.com/Alfresco/alfresco-ng2-components/blob/master/PREREQUISITES.md). > If you plan using this component with projects generated by Angular CLI, please refer to the following article: [Using ADF with Angular CLI](https://github.com/Alfresco/alfresco-ng2-components/wiki/Angular-CLI) ## Install ```sh npm install ng2-alfresco-datatable ``` ## 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 } ] ); } } ``` ![DataTable demo](docs/assets/datatable-demo.png) 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' } ] ); } } ``` ### DataTable 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 ehre thubnail 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 indicate if the datable is in loading state and need to show the loading template. Read the documentation above to know how to configure a loading template | | showHeader | boolean | true | Toggles header visibility | ### DataColumn Properties Here's the list of available properties you can define for a Data Column definition. | 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 | | 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) | ### DataTable 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 | ### DataTable DOM Events Below are the DOM events raised by DataTable component. | Name | Description | | --- | --- | | row-click | Emitted when user clicks the row | | row-dblclick | Emitted when user double-clicks the row | These events are bubbled up the element tree and can be subscribed to from within parent components. ```html ``` ```ts onRowClick(event) { console.log(event); } ``` ![](docs/assets/datatable-dom-events.png) ### Custom Empty content template You can add a template that will be showed when there are no result in your datatable: ```html

Sorry, no content

``` ### Default Empty content template You can use the empty list component if you want show the default ADF empty template: ```html ``` | 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 showed 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 assigning 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