1.5.0 • Published 6 years ago

@teamhive/ngx-table v1.5.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

@teamhive/ngx-table

A simple template and configuration driven table framework for Angular 5+.

DEMO: https://teamhive.github.io/ngx-table

Contribution Guidelines

Changelog

Installation

npm i @teamhive/ngx-table --save

Usage

This is the most basic implementation of ngx-table.

my.module.ts

import { NgxTableModule } from '@teamhive/ngx-table';

@NgModule({
  imports: [
    ...,
    NgxTableModule
  ]
})

sample-data.interface.ts

export interface TableData {
  name: string;
  bio: string;
  age: number;
  active: boolean;
  location: string;
}

basic-table.component.ts

import { Component } from '@angular/core';
import { TableConfiguration } from '@teamhive/ngx-table';

@Component({
  selector: 'app-basic-table',
  templateUrl: 'basic-table.component.html',
  styleUrls: ['basic-table.component.scss']
})
export class BasicTableComponent {

  readonly tableConfig: TableConfiguration<TableData> = {
    tableId: 'basicTable',
    columns: ['name', 'bio', 'age', 'active'],
    definitions: {
      bio: {
        columnSize: 3
      }
    }
  };

  readonly data: TableData[] = [{
    active: true,
    age: 30,
    bio: 'Lorem ipsum dolor sit amet...',
    name: 'Scott',
    location: 'USA'
  }, {
    active: false,
    age: 25,
    bio: 'Duis aute irure dolor in reprehenderit...',
    name: 'Bart',
    location: 'JPN'
  };
}

basic-table.component.html

<hive-ngx-table [configuration]="tableConfig" [items]="data">
    <ng-container *ngFor="let columnId of tableConfig.columns">
        <ng-template let-item [header]="columnId">
            <h3>{{ columnId }}</h3>
        </ng-template>

        <ng-template let-item [column]="columnId">
          <span>{{ item.data[columnId] }}</span>
      </ng-template>
    </ng-container>
</hive-ngx-table>

Inputs and Configuration

Directives and Inputs

InputsDescription
itemsthe data to display in the table
configurationThe configuration (TableConfiguration) used to define the table. The tableId and columns properties are required. - tableId allows for multiple tables in the same view. - columns defines the properties of the data - passed to items input - to show This object can be extended to provide any implementation specific data to the header and row cells.
headerA directive indicating a header template for a column. The value must match a column within the columns array of the table configuration. let-item provides the variable item:HeaderCellContext to the ng-template
columnA directive indicating a data cell template for a row. The template will be applied in every row of the data. The value must match a column within the columns array of the table configuration. let-item provides the variable item:RowCellContext to the ng-template

CSS Variables

VariableDescriptionDefault
--ngx-table-border-radiusThe border radius of the outermost edges of the table0
--ngx-table-border-widthThe width of all borders in the table1px
--ngx-table-border-colorThe color of all borders in the table#cccccc
--ngx-table-border-styleThe style of all borders in the tablesolid
--ngx-table-borderThe base setting for all borders in the tablevar(--ngx-table-border-width) var(--ngx-table-border-style) var(--ngx-table-border-color)
--ngx-table-outer-borderThe border for the outside edge of the tablevar(--ngx-table-border)
--ngx-header-borderThe border for the bottom edge of the headervar(--ngx-table-border)
--ngx-column-borderThe border for the columns of the tablevar(--ngx-table-border)
--ngx-row-borderThe border for the rows of the tablevar(--ngx-table-border)
--ngx-table-background-colorThe default color for all backgroundswhite
--ngx-table-header-background-colorThe background color of the table headervar(--ngx-table-background-color)
--ngx-table-odd-row-background-colorThe background color of the odd rowsvar(--ngx-table-background-color)
--ngx-table-even-row-background-colorThe background color of the even rowsvar(--ngx-table-background-color)
--ngx-table-colorThe text color of the tablecurrentColor
--ngx-table-header-colorThe text color of the headersvar(--ngx-table-color)
--ngx-table-body-colorThe text color of the bodyvar(--ngx-table-color)
--ngx-table-odd-row-colorThe text color of the even rowsvar(--ngx-table-body-color)
--ngx-table-even-row-colorThe text color of the odd rowsvar(--ngx-table-body-color)
--ngx-table-row-heightThe height of the rows of the tableauto
--ngx-table-cell-align-itemsThe flex align-items value for a cellcenter
--ngx-table-cell-justify-contentThe flex justify-content value for a cellcenter
--ngx-table-cell-paddingThe padding value for the cell0
--ngx-table-header-pointer-eventsThe pointer events for the header. Set to none if you want to prevent interactioninitial
--ngx-table-content-pointer-eventsThe pointer events for the table body. Set to none if you want to prevent interactioninitial

More Examples

See the Demo for more configuration, and styling options.

1.5.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.1.0

6 years ago

0.1.0-pipeline.2

6 years ago