1.0.11 • Published 5 years ago

@epcelone/ng-tree-grid v1.0.11

Weekly downloads
16
License
-
Repository
-
Last release
5 years ago

NgTreeGrid

Angular 7 Multi level Tree Grid. Simple, Light Weight and dependency free. Basically it groups data by a field or multiple fields..

Installation

    npm i @epcelone/ng-tree-grid

Usage

Import

Import NgtreegridModule Module in your application module.

  import {NgTreeGridModule} from '@epcelone/ng-tree-grid'; 

Add it to your imports array.

    @NgModule({
      imports: [
        NgTreeGridModule
      ]
    })

Data

Format of the data should be like below.

  products: any[] = [
      { product_type: 'Book', name: 'Angular', price: 90 },
      { product_type: 'Book', name: 'Python', price: 70 },
      { product_type: 'Book', name: 'PHP', price: 80 },
      { product_type: 'Book', name: 'Java', price: 50 },
      { product_type: 'Electronic', name: 'Mouse', price: 50 },
      { product_type: 'Electronic', name: 'Earphone', price: 20 },
      { product_type: 'Electronic', name: 'Speaker', price: 45 },
      { product_type: 'Electronic', name: 'Hard Drive', price: 55 }
];

Configs

Grid Configurations

FieldTypeDefaultDescription
*group_bystring/Arrayn/at's a mandatory field. It is a column key. It can be an array of columns for multilevel group_by.
group_by_headerstring/Arrayn/aHeader for the GroupBy Column. It can be an array of Column Headers.
group_by_widthstring/Array'auto'Width of the GroupBy Column. It can be an array of GroupBy Column widths.
action_column_widthstring50pxWidth of the Action Column.
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.
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.
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.
actionsObjectn/aSettings for Action column. See Below
cssObjectn/aCss class for icons. See Below
columnsObjectn/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.
resolve_editbooleanfalseManually resolve edit.
resolve_deletebooleanfalseManually resolve delete feature.
css
FieldTypeDefaultDescription
expand_classstringplusIcon class for Expand icon. Font Awesome class can be given.
collapse_classstringminusIcon class for Collapse icon. Font Awesome class can be given.
add_classstringplusIcon class for Add icon. Font Awesome class can be given.
edit_classstringeditIcon class for Edit icon. Font Awesome class can be given.
delete_classstringdeleteIcon class for Delete icon. Font Awesome class can be given.
save_classstringsaveIcon class for Save icon. Font Awesome class can be given.
cancel_classstringcancelIcon class for Cancel icon. Font Awesome class can be given.
row_selection_classstringn/aCSS Class for selected row.
header_classstringn/aCSS Class for header.
parent_classstringn/aClass for parent(group by) row.
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).
hiddenbooleanfalseShow/Hide column.
filterbooleantrueEnable/Disable filter.
editablebooleanfalseTo make a specific column editable. By default columns are not editable. edit option needs to be true at grid level.
sortablebooleanfalseTo make a specific column sortable.
rendererFunctionn/aIt is a method to render customized value for the column.
group_aggregatorFunctionn/aIt is a method which can be used to show data at the parent level for the corresponding column. This field for the parent will be left blank if not provided.
typestring''Set to 'custom' to have custom component for the column. Otherwise leave blank.
componentObjectn/aCustom View Component. Mandatory if type is custom.
editorObjectn/aCustom Editor Component. If given custom editor component will be used instead of default editor.
onComponentInitFunctionn/aCallback function for the column on component init.

Basic Example

  configs: any = {      
      'group_by': 'product_type',
      'group_by_header': 'Product Type',
      'group_by_width': '100px',
      'columns': [{
        'header': 'Product Name',
        'name': 'name',
        'sortable': false
      }, {
        'header': 'Price',
        'name': 'price',
        'width': '200px',
        'group_aggregator': (array) => {
          const prices = array.map((item) => item.price);
          return '$' + prices.reduce((acc, item) => acc + item);
        }
      }]
};

HTML

Add below node to your html.

  <db-ngtreegrid [data]="products" [configs]="configs"></db-ngtreegrid>

Events

EventArgumentsDescription
expandrow_data: Expanded RowEvent fires when parent is expanded.
collapserow_data: Collapsed RowEvent fires when parent is collapsed.
cellclickevent Consist of: row: Selected Row column: 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.

License

This project is licensed under the MIT license.

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

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