1.0.7 • Published 1 year ago

@gisgo/dynamic-table v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Gisgo Dynamic Table

Gisgo Dynamic Table is a JSON powered library based on Angular that make complex table simpler & maintainability to your application's tables.

Install

Run npm install @gisgo/dynamic-table

Import Module

After installing the library, go to the AppModule or sub-module and run import DynamicFormModule.forChild()

import {DynamicTableModule} from '@gisgo/dynamic-table';

@NgModule({
  declarations: [],
  imports: [
    DynamicTableModule.forChild({})
  ]
})
export class AppModule { }

Use Dynamic Table

To generate your table you need to define your table columns (fields) by creating table config:

tableConfig: DynamicTableConfig = {
  remotePaginator: false,
  fields: [
    {
      attribute: 'first_name',
      component: 'text',
      label: 'First name',
    },
    {
      attribute: 'last_name',
      component: 'text',
      label: 'Last name'
    },
    {
      attribute: 'company.name',
      component: 'text',
      label: 'Company'
    },
    {
      attribute: 'company.address',
      component: 'text',
      label: 'Address'
    }
  ]
};

Interfaces

DynamicTableConfig

Properties
NameMandatoryDefaultDescription
paginator: booleanNotrueEnable paginator.
remotePaginator: booleanNofalseSet paginator to be manged by external api.
selection: booleanNofalseEnable row selection.
selectionColor: ThemePaletteNoprimarySelection color.
fields: DynamicTableField[]Yes[]Columns Definition.
fields: DynamicTableExpandField[]No[]Columns Definition for expandable row.

DynamicTableField

Properties
NameMandatoryDefaultDescription
attribute: stringYesUnique identifier inside table data row element (can be seperated by . to access sub-object)
component: stringYesComponent reference to be loaded inside table cell.
label: stringYesHeader title.
sortable: booleanNofalseDefine if the column is sortable.
textAlign: stringNo'left'CSS text align.
headerClass: stringNo''Column header css class.
class: stringNo''Column css class.
custom: {[type: string]: any}Nonull

DynamicTableExpandField

Properties
NameMandatoryDefaultDescription
attribute: stringYesUnique identifier inside table data row element (can be seperated by . to access sub-object)
component: stringYesComponent reference to be loaded inside table cell.
textAlign: stringNo'left'CSS text align.
custom: {[type: string]: any}Nonull

And loading data to be showed in the table (the data can be loaded from api):

tableData: DynamicTableData = {
  data: [
    {
      first_name: 'Bilel',
      last_name: 'Dhaouadi',
      company: {
        name: 'Gisgo',
        address: 'State of web artisan'
      }
    },
    {
      first_name: 'John',
      last_name: 'Doe',
      company: {
        name: 'Gisgo',
        address: 'State of web artisan'
      }
    }
  ],
  meta: {
    current_page: 1,
    per_page: 10,
    size_options: [10, 20, 50],
    total: 2
  }
}

Interfaces

DynamicTableData

Properties
NameMandatoryDefaultDescription
data: any[]No[]Set paginator to be manged by external api.
meta: DynamicTableDataMetaYes[]Columns Definition.

DynamicTableDataMeta

Properties
NameMandatoryDefaultDescription
current_page: numberNoCurrent page.
per_page: numberYesTotal record by page.
size_options: number[]YesSize of page can be selected by the user.
total: numberYesTotal count of all records.

in your component html file place gisgo-dynamic-table directive:

<gisgo-dynamic-table [config]="tableConfig"
                     [data]="tableData"
                     (action)="tableAction($event)"
                     (pageChange)="paginatorChange($event)"
                     (sortChange)="sortChange($event)"
                     (selectionChange)="selectionChange($event)">
</gisgo-dynamic-table>

Selectors

gisgo-dynamic-table

Properties
NameMandatoryDescription
@Input() config: DynamicTableConfigYesTable & columns defintion / config.
@Input() data: DynamicTableDataYesTable Data & paginiation.
@Output() action: EventEmitter<DynamicTableAction>NoEmits row click event.
@Output() pageChange: EventEmitter<PageEvent>NoEmits pagintation changes.
@Output() sortChange: EventEmitter<Sort>NoEmits column sort changes.
@Output() selectionChange: EventEmitter<SelectionChange<any>>NoEmits selection changes.

Interfaces

DynamicTableAction

Properties
NameDescription
event: stringEvent type by default row-click
data: anyRow data.

Import Module with custom cell view / fields

import {DynamicTableModule} from '@gisgo/dynamic-table';

@NgModule({
  declarations: [],
  imports: [
    DynamicTableModule.forChild({
      'user': UserCellViewComponent,
      'priority': PriorityCellViewComponent,
      'actions': ActionsCellViewComponent
    })
  ]
})
export class AppModule { }

The custom cell view need to implement the CellView interface

import {CellView} from '@gisgo/dynamic-table';

@Component({
  selector: 'user-cell-view',
  templateUrl: './user-cell-view.component.html',
})
export class UserCellViewComponent implements CellView {
  public data: any;
  public row: any;
  public field: DynamicTableField;
}
1.0.7

1 year ago

1.0.6

2 years ago

1.0.2

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago