1.0.0 • Published 2 years ago

@squareconcepts/smart-table v1.0.0

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

UNDER CONSTRUCTION

This package is still under construction and isn't working properly.

SQUAREConcepts Smart table

Provides a smart datatable that displays data received via http requests.

Compatible

This version of smart table is compatible with todo

Install

To install this package simply run

npm install @squareconcepts/smart-table

In case of any dependency errors try installing without dependencies. In this case you have to install @sreyaj/ng-shimmer manually.

npm install @squareconcepts/smart-table @sreyaj/ng-shimmer --legacy-peer-deps

Usage

Module

// root app NgModule
import {SmartTableModule} from "@squareconcepts/smart-table";

imports: [
  SmartTableModule,
]

Or in case you would like to change any of the options

// root app NgModule
import {SmartTableModule} from "@squareconcepts/smart-table";

imports: [
  SmartTableModule.forRoot(
    {
      createNewButtonText: 'Create',
      actionsColumnTitle: 'Actions',
      searchButtonText: 'Search',
      perPageText: 'Per page',
      pageText: 'Page',
      totalText: 'Total',
      previousText: 'Previous',
      nextText: 'Next'
    })
]

Component

import {Component, OnInit, ViewChild} from '@angular/core';
import {SmartTableComponent} from '@squareconcepts/sc-smart-table';

import {ApiService} from './services/api.service';

@Component({
  selector: 'app-table-page',
  templateUrl: './table-page.component.html',
  styleUrls: ['./table-page.component.scss']
})
export class TablePageComponent implements OnInit {
  @ViewChild('smartTable') private smartTable: SmartTableComponent; //Optional
  public settings = {
    actionsColumnTitle: 'Other title', //Can be set to default in module
    defaultSorting: {
        column: 'id',
        direction: 'ASC'
    },
    searchButtonText: 'Search',
    createNewButtonText: 'Create new',
    customCardButtons:[{
        buttonContent: '<i class="fa fa-download"></i> Export data',
        loadingState: boolean,
        method: () => {
            //do something
             },
    },],
    columns: {
      title: {
        title: 'Title',
        filter: true
      },
      description: {
        title: 'Description',
        filter: true
      },
      create_at: {
        title: "Create date",
        type: 'date|dd-MM-yyy', // First is type name second is format as Angular Date
        filter: {
          display: true,
          type: 'date'
        },
      },
      time: {
        title: 'Van',
        type: 'date|HH:mm',
        filter: {
          display: true,
          type: 'time'
        },
        valuePrepareFunction: (cell, row) => {
          return row.created_at;
        },
      },
      some_html: {
        title: 'Html in field',
        type: 'html',
        sort: false,
        filter: true,
        valuePrepareFunction: (cell, row) => {
          return '<p> with some html</p>'
        },
      }
    },
    create: true,
    edit: true,
    delete: {buttonContent: '<i class="fa fa-trash"></i>'},
    actions: [ //Custom buttons that will be added to the actions column
      {
        title: '<p>this can contain html</p>',
        method: (row) => {
          //do something on click. Function will provide the entire row.
        },
      }
    ]
  };

  constructor(
      public apiService: ApiService
  ) {
  }
  
  editClicked(rowId: number){
      //do something when edit is clicked
  }

  deleteClicked(rowId: number){
    //do something when delete is clicked
  }

  createClicked(){
    //do something when create is clicked
  }

}

Service

Make sure the service implements ScSmartTableInterface

import {ScSmartTableInterface} from "@squareconcepts/sc-smart-table.interface";

@Injectable({
  providedIn: 'root'
})
export class ServiceName implements ScSmartTableInterface {
    //impement methods
}

Options

<sc-smart-table 
  [title]="'title'" 
  [noItemsFoundString]="'No items found'" 
  [service]="service"
  [settings]="settings"
  (editClicked)="editClicked($event)"
  (createClicked)="creteClicked($event)"
  (deleteClicked)="editClicked($event)"
  #smartTable
></sc-smart-table>

Explanation of options

OptionTypeRequiredDescription
titlestringtrueThe title of the page
notItemsFoundStringstringfalseString shown in case of no items
settingsobjecttrueSettings object that will be used to build the table.
serviceScSmartTableInterfacetrueA service to get the data from your api. The service has to implement the ScSmartTableInterface
#smartTableComponentIdentifierfalseCan be edit to perform a method on the smart table

Explanation of methods

FunctionParameterDescription
CreateClickedbooleanWil be emitted when the new item button is clicked
editClickedrowId: numberWil be emitted when the edit button is clicked
deleteClickedrowId: numberWil be emitted when the delete button is clicked

Settings options

FieldRequiredOptionsDescription
actionsColumnTitlefalseAny StringTitle displayed in the table head in the actions column. Default will be Actions This can be change in the Module.forRoot method
createButtonTextfalseAny StringText that is showed in the create button. Default: Create new
searchButtonTextfalseAny StringText that is showed in the search button. Default: Search
actionsColumnTitlefalseAny StringTitle displayed in the table head in the actions column.
customCardButtonsfalse[] of customCardActions {buttonContent: string, loadingState: boolean, method: () => {}}Buttons that will be displayed at the top right corner of the card
defaultSortingfalse{column: 'id', direction: 'ASC'}Adds default sorting to the request on the initial data.
columnstrueFields is in See Colums optionsFields to fill the table See Colums options
createtruetrue or falseWhether or not to display the add new button
edittruetrue/false or {buttonContent: string} (html is allowed)Whether or not to display the edit button and/if with content
deletetruetrue/false or {buttonContent: string} (html is allowed)Whether or not to display the delete button and/if with content
actionsfalse[] of actions {title: string, method: Function}Custom actions that need to be added to the actions column.
rowClassFunctionfalse(row) => {//function}class will be added to the row.

Column Options

FieldRequiredOptionsDescription
titletruetrue or falseTitle will be displayed in the table had.
filterfalsetrue or false or {display: boolean, type: string}Default: trueWill display a input on to filter.
sortfalsetrue or falseCan be sorted by this field.
typefalsedate [pipe] dd-MM-yyyy or rating or htmlwhat type of data will be displayed in the column.
valuePrepareFunctionfalse(cell, row) => {return value you like to display}The data needs to be displayed differently.

Filter Type Options

OptionDescriptionExample
listShows a dropdownfilter: { 'type': 'list', 'config': { 'placeholder': '', 'selectText': 'Select an item', 'list': [{title: 'first item', value: 'item 1'}]}},
dateShows a date fieldfilter: {type: date: display: true}
timeShows time fieldfilter: {type: time: display: true}
1.0.0

2 years ago

0.0.63

2 years ago

0.0.62

2 years ago

0.0.61

2 years ago

0.0.60

2 years ago

0.0.59

2 years ago

0.0.58

2 years ago

0.0.57

2 years ago

0.0.56

2 years ago

0.0.55

2 years ago

0.0.54

2 years ago

0.0.53

2 years ago

0.0.52

2 years ago

0.0.51

2 years ago

0.0.50

2 years ago

0.0.49

2 years ago

0.0.48

2 years ago

0.0.47

2 years ago

0.0.46

2 years ago

0.0.45

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.39

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.31

2 years ago

0.0.30

2 years ago

0.0.29

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago