0.0.18 • Published 3 years ago

tabledy v0.0.18

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

Tabledy

MIT licensed

Overview

An angular +9 module that provides an easy-to-use data-table that supports filtering, sorting, and pagination.

It is a MatTable wrapper that enables you to implement nice-looking tables rapidly.

Getting started

npm install tabledy

Import the 'Tabledy' module

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { TabledyModule } from 'tabledy';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    TabledyModule // <-- Tabledy module
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Configure the table in your component

import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { IColumnDescription } from 'tabledy';

export interface ITodo {
  id: number;
  userId: number;
  title: string;
  completed: boolean;
}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

  // Data must be an observable.
  // The component will listen to any changes and update accordingly
  data: Observable<ITodo []>;

  // Define each of your columns
  columns: IColumnDescription<ITodo> [] = [
    {
      name: 'id',
      label: 'Id',
      sortable: false,
      responsive: true
    },
    {
      name: 'userId',
      label: 'User',
      sortable: false,
      responsive: true
    },
    {
      name: 'title',
      label: 'Title',
      sortable: true,
      accessor: item => {
          return item.title;
      }
    },
    {
      name: 'completed',
      label: 'Done',
      sortable: false
    }
  ];

  constructor(private httpClient: HttpClient) {}

  ngOnInit(): void {
    this.data = this.httpClient.get<ITodo []>(`https://jsonplaceholder.typicode.com/todos/`);
  }
}

Add the table in your template

<!--
Create a template for each of the columns you want to display
You can access the elemnt at that cell with let-element.
You can customize your table however you want
-->
<ng-template #idCell let-element='element'>
  {{ element.id }}
</ng-template>

<ng-template #userCell let-element='element'>
  {{ element.userId }}
</ng-template>

<ng-template #titleCell let-element='element'>
  {{ element.title }}
</ng-template>

<ng-template #completedCell let-element='element'>
  <span *ngIf="element.completed">&#10003;</span>
  <span *ngIf="!element.completed">X</span>
</ng-template>

<!--
Create a template that will show up on mobile devices
-->

<ng-template #responsiveCell let-element='element'>
  {{ element.id }}
</ng-template>

<!--
Your awesome table!
-->
<ngx-tabledy
    searchLabel="Search Item"
    [data]="data"
    [columns]="columns"
    [columnTemplates]="[idCell, userCell, titleCell, completedCell]"
    [responsiveTemplate]="responsiveCell">
</ngx-tabledy>

Properties

NameDescriptionDefault Value
searchLabelString for the search label'Search'
placeholderLabelString for the placeholder of the search input'Search'
hasPaginatorWhether the table will support paginationtrue
pageSizeOptionsThe number of available page sizes5, 10, 25
pageSizeThe default number of items per page5
hasFilterWhether the table will support search filtertrue
isResponsiveWhether the table will support responsive templatestrue
hasExpandibleRowWhether the table will have an expandible row which can be defined with a responsive templatefalse
dataAn observable of the data to display
columnsAn array of column descriptions
columnTemplatesAn array of ng-templates which should match the column description
columnWidthsAn array of widths (percentage) that each column will occupy
responsiveTemplateThe responsive/expandible row template

License

MIT

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago