File

projects/ngx-list-view/src/lib/components/list-filter/ngx-list-filter.component.ts

Implements

OnInit

Metadata

selector ngx-list-filter
templateUrl ngx-list-filter.component.html

Index

Properties
Methods
Inputs

Inputs

checkedItems

Type: any

Default value: {}

dataService

Type: literal type

displayName

Default value: 'label'

filterEmitter

Type: EventEmitter<any>

items

Type: Array<any>

Default value: []

name

Default value: ''

title

Default value: ''

value

Default value: 'value'

Methods

Public closeMenu
closeMenu(e: Event)
Parameters :
Name Type Optional
e Event no
Returns : void
Public ngOnInit
ngOnInit()
Returns : void
Public reset
reset()
Returns : void
Public rowChecked
rowChecked(name: string, event: Event)

When a filter is made active or deactivated.

Parameters :
Name Type Optional Description
name string no

The name of the item.

event Event no

The filter returned.

Returns : void
Public showDropDown
showDropDown()
Returns : "block" | "hide"
Public toggleClickMenu
toggleClickMenu(e: Event)
Parameters :
Name Type Optional
e Event no
Returns : void

Properties

Public checkboxes
checkboxes: QueryList<NgxIcheckDirective>
Type : QueryList<NgxIcheckDirective>
Decorators : ContentChildren
Public itemsActive
itemsActive: number
Type : number
Default value : 0
Public menuShown
menuShown:
Default value : false
Public timeout
timeout: any
Type : any
import {Component, Input, OnInit, EventEmitter, QueryList, ContentChildren} from '@angular/core';
import {NgxIcheckDirective} from '../../directives/ngx-icheck.directive';

@Component({
    selector: 'ngx-list-filter',
    templateUrl: 'ngx-list-filter.component.html'
})
export class NgxListFilterComponent implements OnInit {

    @Input() public title = '';
    @Input() public name = '';
    @Input() public items: Array<any> = [];
    @Input() public displayName = 'label';
    @Input() public value = 'value';
    @Input() public dataService: {
        getFilters: () => Array<any>,
        setParam: (name: string, filters: any) => any,
        fetchAll: (id?: any, payloadOnly?: boolean) => any
    };
    @Input() public checkedItems: any = {};
    @Input() public filterEmitter: EventEmitter<any>;
    @ContentChildren(NgxIcheckDirective) public checkboxes: QueryList<NgxIcheckDirective>;
    public itemsActive = 0;
    public timeout: any;
    public menuShown = false;

    public ngOnInit() {

        // If data is specified and items is empty fetch and fill.
        if (this.dataService) {
            this.dataService
                .fetchAll()
                .subscribe((data: any) => {
                    this.items = data.payload;
                });
        }
    }

    public reset() {
        this.itemsActive = 0;
        this.checkedItems = {};
        this.checkboxes.forEach((item) => {
            item.unCheck();
        });
    }

    /**
     * When a filter is made active or deactivated.
     *
     * @param name The name of the item.
     * @param event The filter returned.
     */
    public rowChecked(name: string, event: Event) {
        this.checkedItems[name] = event;
        clearTimeout(this.timeout);
        this.timeout = setTimeout(() => {
          const value = Object.keys(this.checkedItems)
            .reduce((accum, key) => {
              if (this.checkedItems[key]) {
                accum.push(key);
              }
              return accum;
            }, []);

          this.filterEmitter.emit({
              name: this.name,
              value: value,
              operator: 'IN'
          });
          this.itemsActive = value.length;
      }, 1000);

    }

    public toggleClickMenu(e: Event) {
        e.stopPropagation();
        e.preventDefault();
        this.menuShown = !this.menuShown;
    }

    public closeMenu(e: Event) {
        this.menuShown = false;
    }

    public showDropDown() {
        return this.menuShown ? 'block' : 'hide';
    }

}
<ng-content></ng-content>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""