17.1.2 • Published 5 days ago

@dimanoid/ngx-dm-table v17.1.2

Weekly downloads
76
License
MIT
Repository
github
Last release
5 days ago

ngx-dm-table

npm version bundle size build Coverage Status

Demo page: https://dimanoid.github.io/ngx-dm-table/

Installation

Install the library and dependecies:

npm i -S @angular/cdk resize-observer-polyfill @dimanoid/ngx-dm-table

Add module to imports:

import { DmTableModule } from '@dimanoid/ngx-dm-table';

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule, BrowserAnimationsModule, CommonModule,
        .......
        DmTableModule  // <-------
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }

API

DmTableComponent

<dm-table>
    <!-- see DmColumnDirective below -->
    <dm-column></dm-column>
    <dm-column></dm-column>
    <dm-column></dm-column>

    <!-- optional header for groups -->
    <ng-template #groupHeader
        let-row="row"
        let-rowIndex="ri"
        let-group="group"> <!-- group: DmTableRowsGroup -->
    </ng-template>

    <!-- optional footer for groups -->
    <ng-template #groupFooter
        let-row="row"
        let-rowIndex="ri"
        let-group="group"> <!-- group: DmTableRowsGroup -->
    </ng-template>
</dm-table>
PropertyDescriptionTypeDefault value
[data]Array of rows to displayany[]
[trackBy]trackBy function that will be used in *cdkVirtualFor(index: number, item: T) => any
[itemSize]Row height in pixels, minimum if rows has variable heightnumberMIN_ITEM_SIZE (30)
[moveableColumns]Whether table columns can be reordered by drag-n-drop or notbooleantrue
[(colsOrder)]Array of row's IDs defining the current display order, can be changed if [moveableColumns] is set to truestring[]
(colsOrderChange)Callback executed when [colsOrder] is changedEventEmitter<string[]>
[(colsWidth)]Hashmap of columns widths, object where key is column ID and value is width in pixels{ [id: string]: number }
(colsWidthChange)Callback executed when [colsWidth] is changedEventEmitter<{ [id: string]: number }>
[colsVisibility]Hashmap of columns visibility, object where key is column ID and value is boolean indicating if this column should be displayed{ [id: string]: boolean }
[externalSort]If true no internal sort will be performed, just change value and displaybooleanfalse
[(sort)]Column ID and order used for internal sortingDmTableSort
(sortChange)Callback executed when [sort] is changedEventEmitter<DmTableSort>
[defaultColumnConfig]Default config for columns, can be overriden in column's definitionDmTableColumnConfig
[tableClass]CSS classes that will be added to the <table> tags (header, body and footer tables)string
[rowClasses]Hashmap where key is CSS classes that will be added to row's <tr> tag if value function will return true{ [className: string]: (row: { [colId: string]: any },index: number,group:DmTableRowsGroup) => boolean }
(headerClick)Fires when table header is clickedEventEmitter<DmTableHeaderEvent>
(headerContextMenu)Fires when table header is right-clickedEventEmitter<DmTableHeaderEvent>
(rowClick)Fires when table row is clickedEventEmitter<DmTableRowEvent>
(rowContextMenu)Fires when table row is right-clickedEventEmitter<DmTableRowEvent>
[rowsDragEnabled]Enable DragEvents on rowsbooleanfalse
(rowDragStart)Fires (if rowsDragEnabled = true) when table row gets ondragstart event.EventEmitter<DmTableRowDragEvent>
(rowDragEnd)Fires (if rowsDragEnabled = true) when table row gets ondragend event.EventEmitter<DmTableRowDragEvent>
[rowsDropEnabled]Enable DropEvents on rowsbooleanfalse
(rowDrop)Fires (if rowsDropEnabled = true) when table row gets ondrop event.EventEmitter<DmTableRowDragEvent>
[rowDropAllowed]Callback function that determines if the dragged object can be dropped on this row(event:DmTableRowDragEvent) => boolean() => true

DmColumnDirective

<dm-column>
    <ng-template #header></ng-template> <!-- optional header template for column -->

    <!-- optional cell template for column -->
    <ng-template #cell
        let-row="row"
        let-dmColumnDirective="ct"
        let-colIndex="ci"
        let-rowIndex="ri">
    </ng-template>

    <!-- OR -->
    <ng-template #cell let-cellValue></ng-template>
    
    <ng-template #footer></ng-template> <!-- optional footer template for column -->
</dm-column>
PropertyDescriptionType
[colId]Unique ID of the columnstring
[colIdAlias]Alternative ID of the column that can be used to match the current sortstring
[title]Column header title string, will be displayed if no #header template is definedstring
[pinnable]Not yet implementedboolean
[sortable]Whether the table can be sorted by this column or notboolean
[resizable]Whether this column can be resized or notboolean
[flexible]Should be set for the column that will "accumulate" all the size change first, if not set the last column will be marked as flexible, if more then one column set as flexible last one will be usedboolean
[whitespace]This will be set as a value of the CSS property whitespace for every cell in this columnstring
[minWidth]Minimum width of the column in pixels, column will not be shrinked less then this valuenumber
[maxWidth]Maximum width of the column in pixels, column will not be expanded more then this valuenumber
[frozen]Not yet implemented'left' \| 'right' \| 'no'
[headerTooltip]This will be set as a title of column's header tagstring
[headerClass]CSS classes that will be added to column's header <th> tagstring
[cellClass]CSS classes that will be added to column's cell <td> tagstring
[cellClasses]Hashmap where key is CSS classes that will be added to cell's <td> tag if value function will return true{ [className: string]: (row: { [colId: string]: any },colId: string,rowIndex: number,colIndex: number,group:DmTableRowsGroup) => boolean }
[footerClass]CSS classes that will be added to column's footer <td> tagstring
[sort]Type of data for internal sort or custom sort function'string' \| 'number' \| 'boolean' \| ((a: any, b: any) => number)

DmTableSort

export interface DmTableSort {
    colId: string;
    order: number;
}

DmTableColumnConfig

export class DmTableColumnConfig {
    pinnable: boolean = false;
    sortable: boolean = false;
    resizable: boolean = true;
    whitespace: string = 'normal';
    minWidth: number;
    headerClass: string;
    cellClass: string;
    footerClass: string;
    sort: 'string' | 'number' | 'boolean' | ((a: any, b: any) => number);

    constructor(json?: any) { }
}

DmTableHeaderEvent

export interface DmTableHeaderEvent {
    colId: string;
    index: number;
    first: boolean;
    last: boolean;
    event: MouseEvent;
}

DmTableRowEvent

export interface DmTableRowEvent {
    index: number;
    row: any;
    event: MouseEvent;
}

DmTableRowDragEvent

export interface DmTableRowDragEvent {
    index: number;
    row: any;
    event: DragEvent;
}

DmTableRowsGroup

export interface DmTableRowsGroup {
    index: number;
    first: number;
    last: number;
    rows: any[];
    data: any;
}

Example

<dm-table class="ngx-dmt-stripes"
    [data]="[
        [1, 'one', { key: 'value1' }],
        [2, 'two', { key: 'value2' }],
        [3, 'three', { key: 'value3' }]
    ]"
    [colsWidth]="{ 0: 50 }"
    [defaultColumnConfig]="{ minWidth: 200 }">
    <dm-column title="ID"
        minWidth="50" maxWidth="150"
        sortable="true" sort="number">
    </dm-column>
    <dm-column title="Text" sortable="true" sort="string"></dm-column>
    <dm-column>
        <ng-template #header>
            <div>
                <i style="color: red">
                    <u>Key value</u>
                </i>
            </div>
        </ng-template>
        <ng-template #cell let-item>
            <div>
                key: <b>{{ item['key'] }}</b>
            </div>
        </ng-template>
    </dm-column>
</dm-table>

Result

17.1.2

5 days ago

17.1.1

4 months ago

17.1.0

4 months ago

17.0.7

4 months ago

17.0.6

4 months ago

17.0.8

4 months ago

17.0.3

5 months ago

16.0.2

11 months ago

16.0.1

11 months ago

16.0.0

11 months ago

16.0.3

11 months ago

15.0.0

1 year ago

14.1.3

1 year ago

14.1.4

1 year ago

14.0.18

1 year ago

14.1.0

1 year ago

14.0.13

1 year ago

14.1.1

1 year ago

14.0.12

1 year ago

14.1.2

1 year ago

14.0.11

1 year ago

14.0.10

1 year ago

14.0.17

1 year ago

14.0.15

1 year ago

14.0.14

1 year ago

14.0.9

1 year ago

0.7.17

2 years ago

0.7.15

2 years ago

0.7.14

2 years ago

0.7.16

2 years ago

0.7.13

2 years ago

0.7.12

3 years ago

0.7.11

3 years ago

0.7.10

3 years ago

0.7.9

3 years ago

0.7.8

3 years ago

0.7.7

3 years ago

0.7.6

3 years ago

0.7.5

3 years ago

0.7.2

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.6.36

3 years ago

0.6.35

3 years ago

0.6.37

3 years ago

0.6.32

3 years ago

0.6.31

3 years ago

0.6.30

3 years ago

0.6.29

3 years ago

0.6.28

3 years ago

0.6.27

3 years ago

0.6.21

3 years ago

0.6.20

3 years ago

0.6.23

3 years ago

0.6.22

3 years ago

0.6.25

3 years ago

0.6.24

3 years ago

0.6.26

3 years ago

0.6.18

3 years ago

0.6.17

3 years ago

0.6.19

3 years ago

0.6.14

3 years ago

0.6.16

3 years ago

0.6.15

3 years ago

0.6.12

3 years ago

0.6.11

3 years ago

0.6.9

3 years ago

0.6.7

3 years ago

0.6.8

3 years ago

0.6.6

3 years ago

0.6.3

3 years ago

0.6.2

3 years ago

0.6.5

3 years ago

0.5.12

3 years ago

0.5.13

3 years ago

0.5.10

3 years ago

0.5.7

4 years ago

0.5.6

4 years ago

0.5.5

4 years ago

0.5.4

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.15

4 years ago

0.3.14

4 years ago

0.3.13

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.2.16

4 years ago

0.2.15

4 years ago

0.2.13

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.1.32

5 years ago

0.1.29

5 years ago

0.1.25

5 years ago

0.1.22

5 years ago

0.1.21

5 years ago

0.1.20

5 years ago

0.1.19

5 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.10

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.0.1

5 years ago