4.1.3 • Published 3 years ago

@neoprospecta/angular-data-box v4.1.3

Weekly downloads
4
License
MIT
Repository
bitbucket
Last release
3 years ago

Neoprospecta DataBox

Data table with REST implementation.

##Parameters

AttributeTypeDefaultfunction
titlestringundefinedThe table title
title-sizenumberundefinedThe size of the table title h1, h2, h3, h4, h5, h6 or p
columnsDataBoxColumn[] Columns list configuration. See the Columns section.
actionsany Actions to be used in each row. See the Actions section.
dataany The data to be shown in the table. Can be an array of objects or a REST Api address as: myapi.com/articles
strippedbooleantrueStripped table
condensedbooleanfalseTurn the lines compact
hoverbooleantrueHover the line when the mouse is over
searchablebooleantrueDefines if the table should be searchable or not
selectablebooleantrueDefines if the rows should be selectable or not
modelanyundefinedThe models to be used to add new items
max-rowsnumberundefinedThe max number of rows in a page. If not defined, pagination wont be done
tipsbooleantrueDefines if the tips button and div should be included
counterbooleantrueDefines if the counter should be included
auto-savebooleanfalseDefines if the changes should be automaticaly saved
http-serviceanyundefinedThe service used to send and get data from backend
track-bystringindexDefines the field to be used in track by function in for loop
insertboolean | FunctionfalseDefines if the insert button should be displayed or not. It receives a boolean or a function that returns an Observable.
insert-positionstring'start'Defines where a new item should be placed. Options are 'start' and 'end'
on-paginationFunctionundefinedFunction to be called when pagination arrow is clicked.
totalItemsnumberfilteredList.lengthThe total of items to be paginated.
currentPagenumberundefinedThe current page of paginated list.
amountPerPagenumberundefinedAmount of items per page.

##Events

Eventfunction
changeEvent fired when some data change inside the table

##Usage

####Load the DataBox Module in your module

import { DataBoxModule } from '@neoprospecta/angular-data-box';
...
@NgModule({
  imports: [
    ...
    DataBoxModule,
    ...
  ]
  ...
})
...

####Configure the columns of your DataBox in the component that uses it The column object have many parameters to be configured:

ParametertypeDefaultfunction
attrstring | FunctionundefinedObject attribute to be shown in the column
attr2string | FunctionundefinedSub object attribute to be shown in the column
arrayAttrstring | FunctionundefinedUsed to define the label of items in a given array.
headerstringundefinedThe header of the column
optionsArray<{id: string, label: string}>[]The options to be used in columns of type 'option'
sortboolean = trueundefinedIf should sort the column
searchboolean = trueundefinedIf should include the the column in the search
alignstring'left'Where the content should be aligned. Options are: 'left' | 'center' | 'right'
fitTextboolean = falseundefinedIf true, the width of the table will be equal que text contained in it
tooltipstringundefinedText to be shown when the mouse is over the header
maxLengthnumberundefinedMax length of the content in the cell. The rest is shown by a tooltip
editableboolean = falseundefinedAllow object edition directly in the table
selectableboolean = falseundefinedAllow object edition directly in the table
typestring'text'The type pf the data that will be displayed. Options are: 'text' | 'number' | 'date' | 'date-time' | 'boolean' | 'array' | 'currency' | 'option' | 'text-icon'
actionsarray[]Used when type column is 'actions'.
dateFormatstringundefinedIn case of date or date-time tipe, the format should be passed
currencyLocationstring'USD'Used to set the currency location. Some other options 'EUR', 'BRL'...
maxnumberundefinedDefines the maximum number value of a number type input
minnumberundefinedDefines the minimum number value of a number type input
fontIconstring | FunctionundefinedDefines the icon used when column is 'text-icon'
colorIconstring | Function'black'Defines the color of icon when column is 'text-icon'
disableboolean | FunctionfalseDefines if the option cell column "" will be disabled

app.component.ts

// Import the colum model
import { DataBoxColumn } from '@neoprospecta/angular-data-box';
...
export class AppListComponent {
...
    columns = [
        new DataBoxColumn({header: 'Code', attr: 'id', sort: true, align: 'left', tooltip: 'Person code'}),
        new DataBoxColumn({header: 'Name', attr: 'name', sort: true, align: 'left', tooltip: 'Person name'}),
        new DataBoxColumn({header: 'More than 18?', attr: (app) => app.age >= 18 ? true : false, type: 'boolean', editable: true, sort: true, align: 'left', tooltip: 'Detects if person have more than 18 years'}),
    ];
...
}

####Configure the actions of your DataBox in the component that uses it (FIXED COLUMN AT THE END)

The action object have 4 parameters to be configured:

ParameterTypeDefaultfunction
titlestringundefinedDefines the title of the action
actionstring | functionundefinedCan be a string that triggers a built-in action like 'delete' or 'add' or a custom function that receives the object as parameter
iconstringundefinedThe icon to be used. Ex: fa-trash
colorstringundefinedThe color of the icon. Oprions are primary | accent | warn
hideboolean | functionfalseDefines if action should be hide or not

app.component.ts

export class AppComponent {
...
    gotoDetail = () => {
        ...
    }

    actions = [
        {title: 'Excluir oportunidade', action: 'delete', icon: 'fa-trash', color: 'warn'},
        {title: 'Abrir', action: this.gotoDetail, icon: 'fa-external-link', color: 'primary'},
    ]
...

#####Built-in actions

  • delete: removes a reccord from the table
  • add: create a new reccord and add it in the table

#####New feature: Create a custom actions column

The action object have 5 parameters to be configured:

ParameterTypeDefaultfunction
titlestringundefinedDefines the title of the action
actionstring | functionundefinedCan be a string 'menu' that built a menu or a custom function that receives the object as parameter
optionsarray[]Defines an array of object functions to show inside of menu
iconstringundefinedThe icon to be used. Ex: fa-trash
colorstringundefinedThe color of the icon. Oprions are primary | accent | warn

app.component.ts

functionMenuOption1 = (obj) => {
    console.log('Teste para abrir functionMenuOption1.');
}

functionMenuOption2 = (obj) => {
    console.log('Teste para abrir functionMenuOption2.');
}

export class AppComponent {
...

    actionsColumn = [
        { title: 'Teste menu', action: 'menu', options: [{name: 'option 1', function: this.functionMenuOption1}, {name: 'option 2', function: this.functionMenuOption2}],  color: 'primary' },
        { title: 'Abrir notificações', action: this.openNotifications,  color: 'primary' },
        { title: 'Abrir mensagens', action: this.openMessages, icon: 'fa-comments', color: 'primary' }
    ];

...

    columns = [
        new DataBoxColumn({ header: 'Notificações', type: 'actions', actions: this.actionsColumn, align: 'left', tooltip: 'Notificações, alertas, mensagens, etc' }),
        ...
    ];
...

####Place the DataBox in your component HTML app.component.html

<data-box
    [columns]="columns"
    [actions]="actions"
    [http-service]="myService" // REST OPERATIONS. See Add data to your DataBox section
    [data]="myList" // LOCAL DATA - NO HTTP CALLS. See Add data to your DataBox section
    track-by="id"
></data-box>

####Add data to your DataBox You have two ways of adding data to your DataBox. The options are local and remote.

1 - To load LOCAL DATA, use the [data] attribute in your html component tag and pass an array of objects that shuold be displayed in the table.

app.component.ts

export class AppListComponent {

    ...
    myList = [
        {id: 1, name: 'Andreas', age: 32},
        {id: 2, label: 'Helio', age: 19},
        {id: 4, label: 'Maria', age: 14},
        {id: 5, label: 'Karl', age: 24},
    ]
    ...

app.component.html

<data-box
    ...
    [data]="myList"
    ...
></data-box>

2 - To load REMOTE DATA, use the [http-service] attribute in your html component tag and pass a service that must have the crud operations (filter, get, save, delete) implemented so the DataBox component can interate with each reccord in the table using this service that you have total control and can make any custom configuration.

app.service.ts

export class myService {
    ...
    app: BehaviorSubject<Array<App>>;

    filter = (filter: URLSearchParams) => {
        this.http.get('app endpoint', filter).then(app => this.app.next(app));
        return this.app;
    }

    delete(app: App) {
        return this.http.delete('app endpoint', app);
    }

    save(app: App): Promise<App>  {
        return this.http.post('app endpoint', app);
    }
}

app.component.html

<data-box
    ...
    [http-service]="myService"
    ...
></data-box>

##Todo

  • Remove edit from table and place it inside a modal to remove unnecessary watchers and a bunch of input components.
4.1.3

3 years ago

4.1.2

4 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.40

6 years ago

4.0.39

6 years ago

4.0.38

6 years ago

4.0.37

6 years ago

4.0.36

6 years ago

4.0.35

6 years ago

4.0.34

6 years ago

4.0.33

7 years ago

4.0.32

7 years ago

4.0.31

7 years ago

4.0.30

7 years ago

4.0.29

7 years ago

4.0.28

7 years ago

4.0.27

7 years ago

4.0.26

7 years ago

4.0.25

7 years ago

4.0.24

7 years ago

4.0.23

7 years ago

4.0.22

7 years ago

4.0.21

7 years ago

4.0.20

7 years ago

4.0.19

7 years ago

4.0.18

7 years ago

4.0.17

7 years ago

4.0.16

7 years ago

4.0.15

7 years ago

4.0.14

7 years ago

4.0.13

7 years ago

4.0.12

7 years ago

4.0.11

7 years ago

4.0.10

7 years ago

4.0.9

7 years ago

4.0.8

7 years ago

4.0.7

7 years ago

4.0.6

7 years ago

4.0.5

7 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

0.0.35

7 years ago

0.0.34

7 years ago

0.0.33

7 years ago

0.0.32

7 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago