7.0.0 • Published 2 months ago

angular-tree-grid v7.0.0

Weekly downloads
648
License
MIT
Repository
github
Last release
2 months ago

Angular Tree Component

Angular Tree Grid to show hierarchical data. Basically if data has Parent-Child relationship. It also supports sub-grid/nested-grid. If data needs to be grouped by fields then check out this ngtreegrid Package. If header needs to be fixed/freezed and body needs to be scrollable then check out this Fix Header Grid Package.

Demo

Click here for demo. This readme is the documentation. Visit my Website to know other packages.

Donate :hearts:

Please consider a donation if it is useful to you.

Version

Choose the correct version for your application.

Angularangular-tree-grid
<= 82.8.76
>= 9 and <= 125.0.2
>= 127.0.0

Installation

    npm i angular-tree-grid

Usage

Import

Import AngularTreeGridModule Module in your application module.

import { AngularTreeGridModule } from "angular-tree-grid";

Add it to your imports array.

    @NgModule({
      imports: [
        AngularTreeGridModule
      ]
    })

Data

Data should look like below. Data should have Unique field(id) and Parent field(parent) which is foreign key of the id. Ofcourse these fields are configurable. See below.

  data= [
    { id: 1, name: 'Ashok', age: 60, parent: 0},
    { id: 2, name: 'Sam', age: 40, parent: 1},
    { id: 3, name: 'Sriya', age: 36, parent: 1},
    { id: 4, name: 'Prakash', age: 20, parent: 2},
    { id: 5, name: 'Sneha', age: 21, parent: 3},
    { id: 6, name: 'Pritam', age: 60, parent: 34},
    { id: 7, name: 'Roshan', age: 40, parent: 6},
    { id: 8, name: 'Suraj', age: 36, parent: 6},
    { id: 9, name: 'Swarup', age: 20, parent: 8},
    { id: 10, name: 'Aditya', age: 21, parent: 8},
  ];

Configs

Below are configs that can be set

Grid Configurations

FieldTypeDefaultDescription
*id_fieldstringn/aIt's a mandatory field. It is the primary key.
*parent_id_fieldstringn/aIt's a mandatory field. It is the foreign key.
*parent_display_fieldstringn/aIt's a mandatory field. It is the display field of the row that will be expanded.
data_loading_textstring'Loading...'Loading place holder. This will be displayed when data is empty.
filterbooleanfalseIt enables filter toolbar. Filter is customizable at column level.
multi_selectbooleanfalseIt enables checkbox selection.
rtl_directionbooleanfalseIt is for right to left drawing.
cascade_selectionbooleanfalseIt enables selection of children on selection of Parent and viceversa.
paginationbooleanfalseIt enables Pagination.
per_pagenumber10Number of rows per page.
row_draggablebooleanfalseIt enables dragging and dropping of a row over another. See Example for more information.
show_summary_rowbooleanfalseIt enables summary or footer row. Use summary_renderer at the column level
load_children_on_expandbooleanfalseIt enables dynamic children loading. It means children will be loaded on row-expand. See Example for more information.
subgridbooleanfalseIt enables subgrid feature. parent_id_field is not mandatory for subgrid. Add feature is disabled when it is true. See this Example for more information
subgrid_configObjectn/aConfigs for subgrid. See below table for this.
show_parent_on_editbooleantrueShow Parent column On Edit. It is true by default.
row_class_functionFunctionn/aCallback function for row class. A custom class can be returned which will be added to the row.
row_edit_functionFunctionn/aCallback function for edit feature. Based on the return type(Boolean) of this function, edit can be enabled/disabled for a specific row. See Example for more information.
row_delete_functionFunctionn/aCallback function for delete feature. Based on the return type(Boolean) of this function, delete can be enabled/disabled for a specific row. See Example for more information.
actionsObjectn/aSettings for Action column. See Below
cssObjectn/aCss class for icons. See Below
columnsArrayn/aIt is an Array. If not provided all keys of the data Array will be used as Column Headers. Please find the description below
actions
FieldTypeDefaultDescription
addbooleanfalseIt enables add feature.
editbooleanfalseIt enables edit feature.
deletebooleanfalseIt enables delete feature.
resolve_addbooleanfalseManually resolve add(after making call to server). It defaults to false. See example for more information.
resolve_editbooleanfalseManually resolve edit.
resolve_deletebooleanfalseManually resolve delete feature.
css
FieldTypeDefaultDescription
expand_iconstringplusIcon for Expand icon. Font Awesome class can be given. See example for more information.
collapse_iconstringminusIcon for Collapse icon. Font Awesome class can be given.
add_iconstringplusIcon for Add icon. Font Awesome class can be given.
edit_iconstringeditIcon for Edit icon. Font Awesome class can be given.
delete_iconstringdeleteIcon for Delete icon. Font Awesome class can be given.
save_iconstringsaveIcon for Save icon. Font Awesome class can be given.
cancel_iconstringcancelIcon for Cancel icon. Font Awesome class can be given.
row_selection_classstringn/aCSS Class for selected row.
header_classstringn/aCSS Class for header.
table_classstringn/aCSS Class for Table.
columns
FieldTypeDefaultDescription
namestringn/akey of the column.
headerstringn/aHeader of the column that will be displayed in the table.
widthstringn/aWidth of the column with unit(px/rem).
css_classstringn/aCustom css class for the column.
hiddenbooleanfalseShow/Hide column.
filterbooleantrueEnable/Disable filter.
filter_functionFunctionn/aCustom filter function. filter must be enabled for this. See this Example for more information.
case_sensitive_filterbooleanfalseCase Sensitive/Insensitive Filter.
editablebooleanfalseTo make a specific column editable. By default columns are not editable. edit option needs to be true at grid level.
rendererFunctionn/aIt is a method to render customized value for the column. See this Example.
header_rendererFunctionn/aIt is a method to customize column header.
typestring''Set to 'custom' to have custom component for the column. Otherwise leave blank.
componentObjectn/aCustom View Component. Mandatory if type is custom.See this Example.
editorObjectn/aCustom Editor Component. If given custom editor component will be used instead of default editor. See this Example.
on_component_initFunctionn/aCallback function for the column on component init.
summary_rendererFunctionn/aRenderer for summary. See this Example for more information.
sortablebooleanfalseSort Column. Only available for subgrid feature.
subgrid_config
FieldTypeDefaultDescription
*id_fieldstringn/aIt’s a mandatory field. It is the primary key of child data.
data_loading_textstring'Loading...'Loading place holder. This will be displayed when data is getting loaded.
show_summary_rowbooleanfalseTo show summary row. It defaults to false. Use summary_renderer at the column level.
columnsArrayn/aSee above columns table.

Example

  configs: any = {
    id_field: 'id',
    parent_id_field: 'parent',
    columns: [
      {
        name: 'name',
        header: 'Name',
      },
      {
        name: 'age',
        header: 'Age',
        renderer: function(value) {
          return value + ' years';
        }
      }
    ]
  };

Events

EventArgumentsDescription
expandrow_data: Expanded Row For Subgrid and Dynamic-Children-Loading: event Consist of: data: Selected Row resolve: Promise ObjectEvent fires when parent is expanded. For Subgrid, see this Example. For Dynamic-Children-Loading, see this Example
collapserow_data: Collapsed RowEvent fires when parent is collapsed.
cellclickevent Consist of: row: Selected Row column: Selected Column event: Selected ColumnEvent fires when a child cell is clicked.
rowselectevent Consist of: data: Selected Row event: Event ObjectEvent fires when a row is selected.
rowdeselectevent Consist of: data: Selected Row event: Event ObjectEvent fires when a row is deselected.
rowselectallevent: Event ObjectEvent fires when select-all checkbox is checked.
rowdeselectallevent: Event ObjectEvent fires when select-all checkbox is unchecked.
rowsaveevent Consist of: data: Selected Row event: Event ObjectEvent fires when a row is saved.
rowdeleteevent Consist of: data: Selected Row event: Event ObjectEvent fires when a row is deleted.
rowaddevent Consist of: data: Selected Row event: Event ObjectEvent fires when a row is added.

HTML

Add below node to your html.

  <db-angular-tree-grid [data]="data" [configs]="configs"></db-angular-tree-grid>

Functions

AngularTreeGridComponent has some very useful functions. Below is an example how to call.

    @Component({
      selector: 'app-basic-tree-grid',
      template: `
        <button (click)="collapseAll()">Collapse All</button><button (click)="expandAll()">Expand All</button>
        <p></p>
        <db-angular-tree-grid #angularGrid [data]="data" [configs]="configs"></db-angular-tree-grid>
      `
    })
    export class BasicTreeGridComponent {
      @ViewChild('angularGrid') angularGrid: AngularTreeGridComponent;

      expandAll() {
        this.angularGrid.expandAll();
      }
      collapseAll() {
        this.angularGrid.collapseAll();
      }
    }
FunctionArgumentsDescription
expandAllNoneExpands all rows
collapseAllNoneCollapses all rows
selectAllNoneSelects all rows
deSelectAllNoneDeSelects all rows
expandRow id: Row id(Primary Key) suppress_event: Suppress expand event. It defaults to false.Expands a specific row. see this Example.
collapseRow id: Row id(Primary Key) suppress_event: Suppress expand event. It defaults to false.Collapses a specific row. see this Example.
disableRowSelectionid: Row id(Primary Key)Disables Row Selection for the specific Row id.
enableRowSelectionid: Row id(Primary Key)Enables Row Selection for the specific Row id.
disableRowExpandid: Row id(Primary Key)Disables Row Expand for the specific Row id.
enableRowExpandid: Row id(Primary Key)Enables Row Expand for the specific Row id.
exportname: StringExports table content to csv.

Can I hire you guys?

Yes. Please contact us at debabratapatra12@gmail.com for any professional support. We will be happy to work with you!

License

This project is licensed under the MIT license.

7.0.0

2 months ago

6.0.1

11 months ago

4.0.7

2 years ago

4.0.6

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

6.0.0

2 years ago

4.0.8

2 years ago

2.8.76

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

4.0.5

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.0.1

3 years ago

2.8.75

3 years ago

2.8.74

3 years ago

2.8.73

3 years ago

2.8.72

4 years ago

2.8.71

4 years ago

3.0.0

4 years ago

2.8.8

4 years ago

2.8.7

4 years ago

2.8.6

4 years ago

2.8.5

4 years ago

2.8.4

4 years ago

2.8.3

4 years ago

2.8.1

4 years ago

2.8.0

4 years ago

2.7.9

4 years ago

2.7.8

4 years ago

2.7.7

4 years ago

2.7.6

4 years ago

2.7.5

4 years ago

2.7.4

4 years ago

2.7.3

5 years ago

2.7.2

5 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.6.9

5 years ago

2.6.8

5 years ago

2.6.7

5 years ago

2.6.6

5 years ago

2.6.5

5 years ago

2.6.4

5 years ago

2.6.3

5 years ago

2.6.2

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.5.9

5 years ago

2.5.8

5 years ago

2.5.7

5 years ago

2.5.6

5 years ago

2.5.5

5 years ago

2.5.4

5 years ago

2.5.3

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.9

5 years ago

2.2.8

5 years ago

2.2.7

5 years ago

2.2.6

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago