alfresco-ng2-components/docs/core/interfaces/datatable-adapter.interface.md
Maurizio Vitale 1fa81962a0
👽 Angular 14 rebase 👽 (#7769)
* fix after rebase

* new release strategy for ng next

Signed-off-by: eromano <eugenioromano16@gmail.com>

* peer dep

Signed-off-by: eromano <eugenioromano16@gmail.com>

* Angular 14

fix unit test and storybook

Signed-off-by: eromano <eugenioromano16@gmail.com>

fix after rebase

Signed-off-by: eromano <eugenioromano16@gmail.com>

update pkg.json

Signed-off-by: eromano <eugenioromano16@gmail.com>

missing dep

Signed-off-by: eromano <eugenioromano16@gmail.com>

Fix mistake and missing code

Dream....build only affected libs

Add utility run commands

* Use nx command to run affected tests

* Fix nx test core

fix content tests

Run unit with watch false

core test fixes

reduce test warnings

Fix process cloud unit

Fix adf unit test

Fix lint process cloud

Disable lint next line

Use right core path

Fix insights unit

fix linting insights

Fix process-services unit

fix the extensions test report

fix test warnings

Fix content unit

Fix bunch of content unit

* Produce an adf alpha of 14

* hopefully fixing the content

* Push back the npm publish

* Remove flaky unit

* Fix linting

* Make the branch as root

* Get rid of angualar13

* Remove the travis depth

* Fixing version for npm

* Enabling cache for unit and build

* Fix scss for core and paths

Copy i18 and asset by using ng-packager

Export the theming alias and fix path

Use ng-package to copy assets process-services-cloud

Use ng-package to copy assets process-services

Use ng-package to copy assets content-services

Use ng-package to copy assets insights

* feat: fix api secondary entry point

* fix storybook rebase

* Move dist under dist/libs from lib/dist

* Fix the webstyle

* Use only necessary nrwl deps and improve lint

* Fix unit for libs

* Convert lint.sh to targets - improve performance

* Use latest of angular

* Align alfresco-js-api

Signed-off-by: eromano <eugenioromano16@gmail.com>
Co-authored-by: eromano <eugenioromano16@gmail.com>
Co-authored-by: Mikolaj Serwicki <mikolaj.serwicki@hyland.com>
Co-authored-by: Tomasz <tomasz.gnyp@hyland.com>
2022-08-25 10:50:30 +01:00

6.2 KiB

Title, Added, Status
Title Added Status
DataTableAdapter interface v2.0.0 Active

DataTableAdapter interface

Defines how table data is supplied to DataTable and Tasklist components.

Properties

Name Type Description
selectedRow DataRow The data for the currently selected row.

Events

Name Type Description
rowsChanged Subject<Array<DataRow>> Raised when data adapter gets new rows.

Methods

getRows(): Array<DataRow>;
setRows(rows: Array<DataRow>): void;
Get/set the values for display in the table using an array of rows.

getColumns(): Array<DataColumn>;
setColumns(columns: Array<DataColumn>): void;
Get/set an array of column specifications.

getValue(row:DataRow,col: DataColumn): any;
Get the data value from a specific table cell.

getSorting():DataSorting;
setSorting(sorting: DataSorting): void;
Get/set the sorting key and direction (ascending or descending).

sort(key?: string, direction?: string): void;
Sort the table with a specified key and direction (ascending or descending).

Details

You can implement DataTableAdapter in your own class to display your data with the DataTable and Tasklist components. This interface (along with other interfaces for column and row data) hides the details of your class from the caller, so you can store your data internally however you like. The DataTable library implements the interface in the ObjectDataTableAdapter class which is the standard adapter for the Datatable component.

The basic idea of DataTableAdapter is that the caller can request your class to return an array of column definition objects. Each of these objects specifies the unique key, name, type and other properties of a single column.

The caller can also request the data values for the table as an array of row objects. The caller accesses the data from a row using a getValue method that returns the data from a specified column. This column is identified by the unique key that was set during the column definition.

The data-hiding works the other way around when the caller needs to set data in the DataTableAdapter class - the internal details of the caller's storage are hidden by the column and row interfaces. When the setColumns and setRows methods are called on the adapter, it can simply query the column/row objects it receives and then store the data in its own format.

Columns and rows

Columns are defined by the DataColumn interface:

interface DataColumn {
    key: string;
    type: string;
    format?: string;
    sortable?: boolean;
    title?: string;
    srTitle?: string;
    cssClass?: string;
    template?: TemplateRef<any>;
    formatTooltip?: Function;
    focus?: boolean;
}

An array of these objects is passed to your object when the setColumns method is called. The key property is used to identify columns and so each column's key should be unique. The type string can have a value of 'text', 'image' or 'date'.

An array of DataRow objects is passed to your object when the setRows method is called:

interface DataRow {
    isSelected: boolean;
    isDropTarget?: boolean;
    cssClass?: string;
    hasValue(key: string): boolean;
    getValue(key: string): any;
}

Each row contains a set of values. An item in the set is retrieved by passing its key (specified in the column description) to the getValue method. As a result, the row does not need to store its data items in any particular order or format as long as it can retrieve the right item using its key.

ObjectDataTableAdapter

The DataTable library provides a implementation of DataTableAdapter, called ObjectDataTableAdapter. This is a simple adapter that binds to object arrays and turns object fields into columns:

let data = new ObjectDataTableAdapter(
    // Row data
    [
        { id: 1, name: 'Name 1' },
        { id: 2, name: 'Name 2' }
    ],
    // Column schema
    [
        { 
            type: 'text', 
            key: 'id', 
            title: 'Id', 
            sortable: true 
        },
        {
            type: 'text', 
            key: 'name', 
            title: 'Name', 
            sortable: true
        }
    ]
);

DataTable demo

If you don't specify the column array then the constructor will infer the layout of the columns from the structure of the row objects. The field names ('id' and 'name' in the example below) will be used for both the key and title properties of the columns:

let data =  [
    { id: 2, name: 'abs' },
    { id: 1, name: 'xyz' }
];

let schema = ObjectDataTableAdapter.generateSchema(data);

/*Auto generated column schema:
[
    { 
        type: 'text', 
        key: 'id', 
        title: 'Id', 
        sortable: false 
    },
    {
        type: 'text', 
        key: 'name', 
        title: 'Name', 
        sortable: false
    }
] 
*/

See also