2.0.16 • Published 2 years ago

med-table v2.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

med-table

Wrapper over table of primeng library for Ministry of Health

NPM

npm version

Dependencies

$ npm i @angular/cdk primeng primeflex primeicons

Styles

node_modules/primeicons/primeicons.css
node_modules/primeflex/primeflex.css
node_modules/primeng/resources/primeng.min.css

Installation

NPM

$ npm i med-table

YARN

$ yarn add med-table

Register the component

Global

import { MedTableModule } from 'med-table';

imports: [
  MedTableModule,
]

med-table properties

Name               Type                                                                           RequiredDescription
dataObject[]trueTable data
configMedTableColumnConfig []trueColumns config
loadingBooleanfalseShow loading data process Default: false
settingsMedTableSettingsfalseDefault

Usage

Table usage

<med-table
  [data]="data"
  [loading]="loading"
  [config]="config"
  [settings]="settings"
></med-table>

Templates

Table is a template driven component with named templates such as header and body that we've used so far. Templates grant a great level of customization and flexibility where you have total control over the presentation while table handles the features such as paging, sorting, filtering and more. This speeds up development without sacrificing flexibility. Here is the full list of available templates.

NameDescription
captionCaption content upper the table
paginatorCustom content for the left section of the paginator
tableHeadCustom content for the table data head cell
tableDataCustom content for the table data cell
rowExpansionA row can be expanded to display additional content
<med-table [data]="data" [loading]="loading" [config]="config">
  <ng-template mTemplate="toolbar">
    <nav>
      <a href="link">Home</a>
    </nav>
  </ng-template>

  <ng-template mTemplate="tableHead" let-column>
    {{ column.label }}
  </ng-template>
  
  <ng-template mTemplate="tableData" let-data>
    {{ data }}
  </ng-template>
  
  <ng-template mTemplate="paginator">
    <button>Click</button>
  </ng-template>
</med-table>

Custom column

tableData template properties:

NameDefaultDescription
datatrueData of the data cell
itemfalseObject from the table row
configfalseObject from the table column
<med-table [data]="data" [loading]="loading" [config]="config">
  <ng-template mTemplate="tableData" let-data let-item="item" let-config="config">
    <ng-container [ngSwitch]="config.key">
      <ng-container *ngSwitchCase="'name'" >
        <a routerLink="/link">{{ data }}</a>
        <button type="button">Отримано</button>
      </ng-container>

      <span *ngSwitchCase="'status.name'" class="final-status">
        {{ data }}
      </span>
    </ng-container>
  </ng-template>
</med-table>

Edit

Cell editing provides a rapid and user friendly way to manipulate data.

MedUpdateEvent

import { MedTableColumnConfig, FIELD_TYPES, MedUpdateEvent } from 'med-table';

interface DataType {
    ...
}

@Component({
  selector: 'app-root',
  template: `
    <med-table
      [data]="data"
      [loading]="loading"
      [config]="tableConfig"
      (updateRow)="onUpdateRow($event)"
    ></med-table>
  `
})
export class AppComponent {
  data: DataType[] = [...];
  tableConfig: MedTableColumnConfig[] = [
    {
      key: 'key',
      label: 'Label',
      editorType: FIELD_TYPES.TEXT,
    },
    ...
  ];

  onUpdateRow(event: MedUpdateEvent<DataType>) {
      ...
  }
}

Editor field types

Link

export enum FIELD_TYPES {
  TEXT = 'text',
  NUMBER = 'number',
  TEXTAREA = 'textarea',
  MASK = 'mask',
  DATE = 'date',
  CHECKBOX = 'checkbox',
  SELECT = 'select', // should set MedTableService.setSelectData
  AUTOCOMPLETE = 'AUTOCOMPLETE', // should set MedTableService.setDatalist
}

If you use FIELD_TYPES.SELECT, you need to set the data for the selected parameters with MedTableService.setSelectData(data: MedSelectOption, key: string).

key param must to be as same as key fields in MedTableColumnConfig

import { MedTableService, MedSelectOption } from 'med-table';

...

constructor(private medTableService: MedTableService) {
  const data: MedSelectOption<any> = [...];
  const key: string = 'key';
  medTableService.setSelectData(data, key);
}

Server side sort, filter and pagination

import {
  MedTableSettings,
  MedTableService,
  MedTableColumnConfig, 
  MedUpdateTableEvent, 
} from 'med-table';

interface DataType {
  ...
}

@Component({
  selector: 'app-root',
  template: `
    <med-table
      [data]="data"
      [loading]="loading"
      [config]="tableConfig"
      [settings]="tableSettings"
      (updateTable)="getData($event)"
    ></med-table>
  `
})
export class AppComponent {
  constructor(private api: ApiService, private tableService: MedTableService) {
  }

  loading = false;
  data: DataType[] = [];
  tableSettings: MedTableSettings = {
    lazy: true,
    rows: 25,
    totalRecords: 0,
  };
  tableConfig: MedTableColumnConfig[] = [
    {
      key: 'key',
      label: 'Label',
    },
    ...
  ];

  getData(event: MedUpdateTableEvent) {
    this.loading = true;

    this.api.getData(event).subscribe(({data, filterSelectData}) => {
      this.tableSettings.totalRecords = data.length;
      this.data = data;

      this.tableSettings.setFilterSelectData(filterSelectData, 'key'); // set data for filter select by key param
      this.loading = false;
    });
  }
}
2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

1.0.63

2 years ago

2.0.1

2 years ago

1.1.1

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

2.0.15

2 years ago

2.0.16

2 years ago

2.0.13

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

1.0.62

2 years ago

1.0.61

2 years ago

1.0.60

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.55

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.49

2 years ago

1.0.48

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

0.0.48

2 years ago

0.0.47

2 years ago

0.0.44

2 years ago

0.0.43

2 years ago

0.0.42

2 years ago

0.0.41

2 years ago

0.0.40

2 years ago

0.0.38

2 years ago

0.0.37

2 years ago

0.0.36

2 years ago

0.0.35

2 years ago

0.0.34

2 years ago

0.0.33

2 years ago

0.0.32

2 years ago

0.0.30

2 years ago

0.0.29

2 years ago

0.0.28

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.18

2 years ago

0.0.5

2 years ago