diff --git a/ng2-components/ng2-alfresco-datatable/README.md b/ng2-components/ng2-alfresco-datatable/README.md index 3df44cf5cd..5000815c61 100644 --- a/ng2-components/ng2-alfresco-datatable/README.md +++ b/ng2-components/ng2-alfresco-datatable/README.md @@ -74,6 +74,44 @@ export class MyView { | rowClick | emitted when user clicks the row | | rowDblClick | emitted when user double-clicks the row | +## Data sources + +DataTable component gets data by means of data adapter. +It is possible having data retrieved from different kinds of sources by implementing +a custom `DataTableAdapter`: + +```ts +interface DataTableAdapter { + + getRows(): Array; + setRows(rows: Array): void; + getColumns(): Array; + setColumns(columns: Array): void; + getValue(row: DataRow, col: DataColumn): any; + getSorting(): DataSorting; + setSorting(sorting: DataSorting): void; + sort(key?: string, direction?: string): void; + +} +``` + +DataTable ships `ObjectDataTableAdapter` out-of-box. This is a simple data adapter +that binds to object arrays and turns object fields into columns: + +```ts +let 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', sortable: true} + ] +); +``` ## Build from sources