@appcarvers/ngx-unitelist
Version:
This library is for Angular (2+) projects to build a list from passed data and provide pagination and filters and their callbacks after proper configuration.
122 lines (101 loc) • 3.15 kB
text/typescript
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { BsDatepickerConfig } from 'ngx-bootstrap/datepicker';
export class UnitelistComponent implements OnInit {
_totalPages;
_filters : Array<any> = [];
_showSearchRemove = false;
bsConfig: Partial<BsDatepickerConfig>;
searchVal;
displayTable = true;
tableData;
tableHeaders;
currentPage: number;
searchBox = false;
showSearchButtons = true;
pagesToShow;
tableBlockClass = 'table';
filterBlockClass = 'my-col col-xs-3';
filterCoverClass = 'my-filters row';
searchBoxClass = 'my-col col-xs-3';
totalPages;
set data(value){
this.tableData = value;
};
set filters(value){
this._filters = value;
// [0,1,2,3,4]
this._filters.forEach(element => {
this.myFilterObj.values[element.name] = element.value;
});
};
pageChanged = new EventEmitter();
filterChanged = new EventEmitter();
searchInput = new EventEmitter();
searchButtonsClicked = new EventEmitter();
checkingTableBody;
myOptions: Array<any>;
mySelectValue: Array<string>;
myFilterObj = {values : {}, change : {}};
constructor() {
}
ngOnInit() {
}
filterSelected(e, f, i){
this.myFilterObj.change = {status : 'selected', name : f, value : e.id, text : e.text};
this.myFilterObj.values[f] = e.id;
this.filterChanged.emit(this.myFilterObj);
}
filterRemoved(e, f, i){
this.myFilterObj.change = {status : 'removed', name : f, value : e.id, text : e.text};
this.myFilterObj.values[f] = '';
this.filterChanged.emit(this.myFilterObj);
}
checkPageChanged($e){
this.pageChanged.emit($e);
}
dateChanged(e, f, i){
if(e)
{
this._filters[i].value = e;
this.myFilterObj.change = {status : 'selected', name : f, value : e};
this.myFilterObj.values[f] = e;
}
else
{
this._filters[i].value = '';
this.myFilterObj.change = {status : 'removed', name : f, value : ''};
this.myFilterObj.values[f] = '';
}
this.filterChanged.emit(this.myFilterObj);
}
searchValueChanged(e){
let obj = {keyPressed : e.key, searchVal : e.target.value, keyCode : e.which};
this.searchInput.emit(obj);
}
searchButtonClicked($e?)
{
if(this.searchVal)
{
this.searchButtonsClicked.emit(this.searchVal);
}
else if($e && $e.key == 'Backspace')
{
this.searchButtonsClicked.emit(this.searchVal);
}
}
searchCancle()
{
this.searchVal = '';
this.searchButtonsClicked.emit('');
}
clearDate(fieldName, index){
this._filters[index].value = '';
this.myFilterObj.change = {status : 'removed', name : fieldName, value : ''};
this.myFilterObj.values[fieldName] = '';
}
}