1.1.1 • Published 12 months ago

angular-filter-dropdown v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Angular Filter Dropdown

Filter your data respective to any field based on your dataset Also, identifies duplications of data & handles with single checkbox created dynamically.

Installation

npm i angular-filter-dropdown

Usage

Import

import { AngularFilterDropdownModule } from 'angular-filter-dropdown';

@NgModule({
  ...
  imports: [
    ...
    AngularFilterDropdownModule
  ],
  ...
})

Fundamental Usage

<lib-angular-filter-dropdown 
    [tableData]="data" 
    [columnName]="colName" 
    (onCheckBoxStatusChanged)="checkboxStatusChange($event)" 
    (onUnselectAll)="getStatusOfUnselectedAll($event)">
</lib-angular-filter-dropdown>

Configuration - Props

  checkboxStatusChange(event: any){
    console.log(event);
  }

  getStatusOfUnselectedAll(event: any){
    console.log(event);
  }

let data = [
      { id: 1, name: 'John Doe', age: 30, email: 'john@example.com'},
      { id: 2, name: 'Jane Doe', age: 28, email: 'jane@example.com'},
      { id: 3, name: 'Michael Smith', age: 35, email: 'michael@example.com'},
      { id: 4, name: 'Emily Johnson', age: 25, email: 'emily@example.com'},
      { id: 5, name: 'James Brown', age: 32, email: 'james@example.com'},
      { id: 6, name: 'John Doe', age: 30, email: 'john@example.com'},
      { id: 7, name: 'Jane Doe', age: 28, email: 'jane@example.com'},
      { id: 8, name: 'Michael Smith', age: 35, email: 'michael@example.com'},
      { id: 9, name: 'Emily Johnson', age: 25, email: 'emily@example.com'},
      { id: 10, name: 'James Brown', age: 32, email: 'james@example.com'}
    ],

let colName = "name"

For identifiation of duplication of data & handles with single checkbox dynamically Just an instance, shared piece of code below for duplication handling.

ngOnInit(){
  this.replicaData = [...this.data.entries];  
}

checkboxStatusChange(event: any){
    let keysName = Object.keys(event);
    
    if(event[keysName[1]] === true){
      let result = this.replicaData.filter((obj: any) => obj[keysName[0]] === event[keysName[0]]);
      result.forEach((element:any) => {
        this.data.push(element);
        this.data.sort((a: any, b: any) => a.id - b.id)
      });
      
    }else{
      this.data = this.data.filter((obj: any) => obj[keysName[0]] !== event[keysName[0]]);
    }

    this.checkForDuplicationOfItems();
}

getStatusOfUnselectedAll(event: any){
    if(event === false){
      this.data = this.replicaData;
    }else{
      this.data = [];
    }
    this.checkForDuplicationOfItems();
}

checkForDuplicationOfItems(){
    this.data = this.data.filter((data: any, index: number) => data.id !== (this.data[index + 1]?.id));
}

Fundamentals / Mandatories

Property/MethodTypeDescription
tableDataArrayArray of objects data/ table data
columnNamestringTo which field, you want to add filter
onCheckBoxStatusChangedmethodOn checkbox changes
onUnselectAllmethodEmits on select All or Unselect All

Future Plans

  • More decorative Approach in terms of CSS.
  • Will come up with search functionality.

Author

Suraj Motwani - Email: suraj.motwani1306@gmail.com

License

Angular Filter Dropdown is available under the MIT license. See the LICENSE file for more info.

1.1.1

12 months ago

1.1.0

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.1

1 year ago