1.5.40 • Published 6 months ago

dynamic-mat-table v1.5.40

Weekly downloads
55
License
MIT
Repository
github
Last release
6 months ago

Dynamic Table for Angular

Screen Shot

Online Demo

You can view the table in stackblitz here:

https://stackblitz.com/edit/angular-ivy-wge9lp

version (1.3.2):

https://stackblitz.com/edit/angular-ivy-s4ne42

A full demo can be found on the github repository.

Getting Started

1. First you need to install with npm:

Write npm i dynamic-mat-table in your terminal to install the package

2. After installation you need to include DynamicMatTableModule in your module imports:

import { DynamicMatTableModule } from 'dynamic-mat-table';
...
imports: [
    DynamicMatTableModule
  ],
...

How Use The Table

Creating the table html element

first you need to write the html element like so:

<dynamic-mat-table
  tableName="my-table"
  [columns]="columns"
  [setting]="setting"
  [dataSource]="dataSource$"
></dynamic-mat-table>

Full Specification:

<dynamic-mat-table
  tableName="demo_table" 
  [scrollStrategyType]="scrollStrategyType"
  [contextMenuItems]="contextMenuItems"
  [showReload]="showReloadData"
  [direction]="direction"
  [expandComponent]="expandComponent"
  [rowHeight]="rowHeight"
  [columns]="fields"
  [pending]="pending"
  [setting]="setting"
  [sticky]="stickyHeader"
  [dataSource]="dataSource$"
  [pagingMode]="paginationMode"
  [pagination]="pagination"
  [showNoData]="showNoData"
  [printConfig]="printConfig"
  [rowSelectionMode]="rowSelectionMode"
  [rowSelectionModel]="selectionModel"
  [showProgress]="showProgress"
  [rowContextMenuItems]="contextMenuItems"
  (onTableEvent)="tableEvent_onClick($event)"
  (onRowEvent)="rowEvent_onClick($event)"
  [class.conditional-class]="conditinalClass"
  (settingChange)="table_onChangeSetting($event)"
  (rowSelectionChange)="table_onRowSelectionChange($event)"
>
</dynamic-mat-table>

by binding the properties you can set columns, set the table settings , set a datasource and more to the table

Setting the columns

to set the columns you first need to import TableField and creat a porpery that takes this type as an arry like so:

import { TableField } from 'dynamic-mat-table'
...
export class MyTable {
  columns:TableField<any>[] = [];
}

then you can set each column as an object of this arry

...
const colusmnsConfig:TableField<any>[] = [
  {
    name: 'column-one',  //this is a key for data
    header: 'column-one', //this is the name displayed
    type:'number', //type of the data
  },
  {
    name:'column-two',
    header:'column-two',
    type:'number',
  },
  ...
];

The full column type is defined as follow:

export interface TableField<R extends TableRow> extends AbstractField {
    classNames?: string;
    rowClass?: string | AtClassFunc;
    customSortFunction?: AtSortFunc<R>;
    customFilterFunction?: AtSortFunc<R>;
    toPrint?: ToPrint;
    toExport?: ToExport;
}
export interface AbstractField {
    index?: number;
    name: string; //data  key
    type?: FieldType; //data type
    width?: number; //width of the column
    header?: string; //displayed name of the column
    isKey?: boolean; // turn column in to unique key column 
    inlineEdit?: boolean; // allows column to have inline edit
    display?: FieldDisplay; // allow column to be hidden or visible
    sticky?: FieldSticky; // allow column to stick in horizontal scrolling
    filter?: FieldFilter; // sets data filtering mode(none: hidden filter button)
    sort?: FieldSort; // set data sorting mode( none: hidden sort button)
    cellClass?: string; // set a class for column cells
    cellStyle?: any; //set a style for column cells
    icon?: string; // displays a mat-icon in column header
    iconColor?: string; // set a color for column header icon
    dynamicCellComponent?: any; // set the component used in column cells
    draggable?: boolean; // allows column to be rearranged with drag and drop 
    // filterable?: boolean; // allows column to filter its data (shows filter button)
    clickable?: boolean; // allows column to have a function when clicked
    clickType?: 'cell' | 'label' | 'custom'; // sets the click ability region
    printable?: boolean; // allows column to print its data
    exportable?: boolean; // allows column data to be exported
    enableContextMenu?: boolean; // enables context menu in columns
    rowSelectable?: boolean; // Coming soon...
    footer?: FooterCell[]; // creates footers for column
    cellEllipsisRow?: number; // maximum number of cells shown before ellipses 
    cellTooltipEnable?: boolean; // allows column cell to have a tooltip
    headerEllipsisRow?: number;  // maximum number of rows shown in column before ellipses
    headerTooltipEnable?: boolean; // allows column header to have a tooltip
    option?: any; // a spacial object for storing data state (like saving in inline edit)
    categoryData?: any[]; // Coming soon...
    toString?: (column: TableField<any>, row: TableRow) => string; // turns column data to a string (used mostly for exporting data)
    customSort?: (column: TableField<any>, row: any) => string; // allows you customize data sorting in column
}

Ceateing a data source

after setting the columns you need to set the data you want to use in your table.

Your data source must be a BehaviourSubject<any[]>

so in order to creat a data source you must do so like wise:

import { BehaviourSubject } from 'rx-js';
...
type dataType = {...};

const data:dataType[] = [
  { "row": 1, "name": "Element #4", "weight": "65 KG", "color": "Magenta", "brand": "Zanjan Benz", "type": "Van" }, ...];
...
export class MyTable implements OnInit {

  public dataSource$: BehaviorSubject<any[]>;

  constructor(){}

  ngOnInit(){
    this.dataSource$.next(data);
  }

}

Configureing the table settings

next thing is configuring the table settings.

to do so we need to create a property that takes the TableSetting type like so:

import { TableSetting } from 'dynamic-mat-table';
...
export class MyTable {
  settings:TableSettings = {};
}

then we can set the values of this object to customize our table.

For Exmaple:

const tableSettinsConfig:TableSetting = {
  direction: 'ltr',
  visibleActionMenu: actionMenu,
  rowStyle: {
    'background-color': '#70e181',
    color: 'ffffff',
  },
  alternativeRowStyle: {
    'background-color': 'afafaf',
    color: '55fab3',
  },
  autoHeight: true,
}

the full interface is described below:

export interface TableSetting {
    direction?: Direction; // sets the directopn of the table
    columnSetting?: AbstractField[]; // 
    visibleActionMenu?: VisibleActionMenu; // configures the actoin menu 
    visibleTableMenu?: boolean; // controls the table men's visablity 
    alternativeRowStyle?: any; // sets a style for the odd rows
    normalRowStyle?: any; // sets a style for the even rows
    scrollStrategy?: TableScrollStrategy; // sets a scroll strategy
    rowStyle?: any; //
    enableContextMenu?: boolean; // controls the context menu visablity
    autoHeight?: boolean; // allows the table to automaticly controls its height
    saveSettingMode?: 'simple' | 'multi' | 'none'; // controls the saving mode
    settingName?: string; // name for the setting 
    settingList?: TableSetting[]; //
    currentSetting?: string; //
}

Adding a paginator

adding a paginator is just like columns and setting.

first we add the Property with the TablePagination type then we configure it like so:

import { TablePagination } from 'dynamic-mat-table';
...
export class MyTable {
  pagination:TablePagination = {};
}

the full description for the TablePagination is as below:

export interface TablePagination {
    length?: number; // total number of data records 
    pageIndex?: number; // initial page
    pageSize?: number; // number of rows in each page
    pageSizeOptions?: number[]; // page ination options
    showFirstLastButtons?: boolean; // controls the first/last button display
}

How to add international

to support new language you must declare new class and implement LanguagePack for example this is persian language:

import { MatPaginatorIntl } from "@angular/material/paginator";
import {
  FilterLabels,
  LanguagePack,
  MenuLabels,
  TableLabels,
} from "dynamic-mat-table";
export class PersionLanguage implements LanguagePack {
  constructor() {}

  menuLabels: MenuLabels = {
    saveData: "ذخیره داده ها ",
    columnSetting: "تنظیمات ستون ها ",
    saveTableSetting: "ذخیره  تنظیمات جدول",
    clearFilter: "فیلتر را پاک کنید",
    jsonFile: "Json فایل",
    csvFile: "CSV فایل",
    printTable: "چاپ جدول",
    filterMode: "نوع فیلتر",
    filterLocalMode: "محلی",
    filterServerMode: "سرور",
    sortMode: "حالت مرتب سازی",
    sortLocalMode: "سمت کاربر",
    sortServerMode: "سمت سرور",
    printMode: "حالت چاپ",
    printYesMode: "بله",
    printNoMode: "خیر",
    pinMode: "حالت پین ",
    pinNoneMode: "هیچ کدام",
    pinStartMode: "شروع",
    pinEndMode: "پایان",
  };

  paginatorLabels: MatPaginatorIntl = {
    changes: null,
    itemsPerPageLabel: "ایتم های هر صفحه:",
    nextPageLabel: "صفحه بعدی:",
    previousPageLabel: "صفحه قبلی:",
    firstPageLabel: "اولین صفحه:",
    lastPageLabel: "آخرین صفحه:",
    getRangeLabel: (page: number, pageSize: number, length: number) => {
      if (length === 0 || pageSize === 0) {
        return `0 از ${length}`;
      }
      length = Math.max(length, 0);
      const startIndex = page * pageSize;
      const endIndex =
        startIndex < length
          ? Math.min(startIndex + pageSize, length)
          : startIndex + pageSize;
      return `${startIndex + 1} - ${endIndex} از ${length}`;
    },
  };

  tableLabels: TableLabels = {
    NoData: "هیچ رکوردی پیدا نشد",
  };

  filterLabels: FilterLabels = {
    Clear: "پاک کردن",
    Search: "جستجو",
    And: "و",
    Or: "یا",
    /* Text Compare */
    Text: "متن",
    TextContains: "دربرگرفتن",
    TextEmpty: "خالی بودن",
    TextStartsWith: "شروع شدن با",
    TextEndsWith: " پایان گرفتن با",
    TextEquals: "مساوی بودن",
    TextNotEmpty: "خالی نبودن",
    /* Number Compare */
    Number: "تعداد",
    NumberEquals: "مساوی",
    NumberNotEquals: "مساوی نبودن",
    NumberGreaterThan: " بزرگ تر از",
    NumberLessThan: "کم تر از ",
    NumberEmpty: "خالی بودن",
    NumberNotEmpty: "خالی نبودن",
    /* Category List Compare */
    CategoryContains: "در برگرفتن",
    CategoryNotContains: "در بر نگرفتن",
    /* Boolean Compare */
    /* Date Compare */
  };
}

and passed this class to grid so :

providers: [{ provide: TableIntl, useFactory: languageIntl }];

And

export function languageIntl() {
  return new PersionLanguage();
}
1.5.40

6 months ago

1.5.39

9 months ago

1.5.36

10 months ago

1.5.38

9 months ago

1.5.30

12 months ago

1.5.32

11 months ago

1.5.31

11 months ago

1.5.34

11 months ago

1.5.33

11 months ago

1.5.35

11 months ago

1.5.27

12 months ago

1.5.26

12 months ago

1.5.29

12 months ago

1.5.28

12 months ago

1.5.21

1 year ago

1.5.23

12 months ago

1.5.22

12 months ago

1.5.25

12 months ago

1.5.24

12 months ago

1.5.8

1 year ago

1.5.7

2 years ago

1.5.6

2 years ago

1.5.10

1 year ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.4.28

2 years ago

1.4.27

2 years ago

1.4.29

2 years ago

1.4.31

2 years ago

1.4.30

2 years ago

1.4.22

2 years ago

1.4.21

2 years ago

1.4.24

2 years ago

1.4.23

2 years ago

1.4.26

2 years ago

1.4.25

2 years ago

1.4.20

2 years ago

1.4.19

2 years ago

1.4.18

2 years ago

1.4.17

3 years ago

1.4.15

3 years ago

1.4.14

3 years ago

1.4.16

3 years ago

1.4.13

3 years ago

1.4.12

3 years ago

1.4.11

3 years ago

1.4.10

3 years ago

1.4.9

3 years ago

1.4.8

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.7

3 years ago

1.3.19

3 years ago

1.3.20

3 years ago

1.3.21

3 years ago

1.3.18

3 years ago

1.3.17

3 years ago

1.3.15

3 years ago

1.3.16

3 years ago

1.3.14

3 years ago

1.3.13

3 years ago

1.3.12

3 years ago

1.3.11

3 years ago

1.3.10

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.2.21

3 years ago

1.2.19

3 years ago

1.2.20

3 years ago

1.2.18

3 years ago

1.2.17

3 years ago

1.2.16

3 years ago

1.2.15

3 years ago

1.2.14

3 years ago

1.2.13

3 years ago

1.2.12

3 years ago

1.2.10

3 years ago

1.2.11

3 years ago

1.2.9

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

0.0.1

4 years ago