Added grid refresh

This commit is contained in:
Zakary Timson 2018-06-28 19:53:50 -04:00
parent fe566961ce
commit 2258c12b56
3 changed files with 45 additions and 41 deletions

View File

@ -107,6 +107,10 @@ Clear filters being applied to. Update can be set to false to prevent instant fi
Clear all selected rows. Clear all selected rows.
#### refresh()
Refreshes the grid
##### selectAll() ##### selectAll()
Select all rows. Ignores pagination but not filtering. Select all rows. Ignores pagination but not filtering.

View File

@ -1,6 +1,6 @@
{ {
"name": "@ztimson/ng-datatable", "name": "@ztimson/ng-datatable",
"version": "1.7.5", "version": "1.8.5",
"homepage": "https://github.com/ztimson/ng-datatable", "homepage": "https://github.com/ztimson/ng-datatable",
"license": "Apache-2.0", "license": "Apache-2.0",
"author": { "author": {

View File

@ -43,7 +43,7 @@ export class NgDatatableComponent implements OnInit {
get data(): any[] { return this.processedData; } // Return the processed data get data(): any[] { return this.processedData; } // Return the processed data
@Input() set data(data: any[]) { @Input() set data(data: any[]) {
this._data = data; this._data = data;
this._process(); this.refresh();
} }
// =================================================================================================================== // ===================================================================================================================
@ -60,7 +60,44 @@ export class NgDatatableComponent implements OnInit {
} }
// Helpers =========================================================================================================== // Helpers ===========================================================================================================
private _process() { _convertWidth(width) {
if(typeof width == 'number') return `${width}px`;
return width;
}
_dotNotation(obj: object, prop: string) {
return prop.split('.').reduce((obj, prop) => obj[prop], obj);
}
addFilter(...filters: ((row?: any, index?: number, arr?: any[]) => boolean)[]) {
this.filters = this.filters.concat(filters);
this.refresh();
this.filterChanged.emit(this.filters);
}
changePage(page: number) {
if(!this.paginate || page < 1 || page > this.pages.length) return;
this.page = page;
this.refresh();
this.pageChanged.emit(this.page);
}
clearFilters(update=true) {
this.filters = [];
if(update) this.refresh();
this.filterChanged.emit(this.filters);
}
clearSelected() {
let emit = this.selectedRows.size > 0;
this.selectedRows.clear();
if(emit) this.selectionChanged.emit([]);
}
@HostListener('window:resize', ['$event'])
onResize(event) { this.width = event.target.innerWidth; }
refresh() {
this.processing.emit(this.processedData); this.processing.emit(this.processedData);
this.clearSelected(); this.clearSelected();
this.processedData = this._data; this.processedData = this._data;
@ -88,43 +125,6 @@ export class NgDatatableComponent implements OnInit {
this.finished.emit(this.processedData); this.finished.emit(this.processedData);
} }
_convertWidth(width) {
if(typeof width == 'number') return `${width}px`;
return width;
}
_dotNotation(obj: object, prop: string) {
return prop.split('.').reduce((obj, prop) => obj[prop], obj);
}
addFilter(...filters: ((row?: any, index?: number, arr?: any[]) => boolean)[]) {
this.filters = this.filters.concat(filters);
this._process();
this.filterChanged.emit(this.filters);
}
changePage(page: number) {
if(!this.paginate || page < 1 || page > this.pages.length) return;
this.page = page;
this._process();
this.pageChanged.emit(this.page);
}
clearFilters(update=true) {
this.filters = [];
if(update) this._process();
this.filterChanged.emit(this.filters);
}
clearSelected() {
let emit = this.selectedRows.size > 0;
this.selectedRows.clear();
if(emit) this.selectionChanged.emit([]);
}
@HostListener('window:resize', ['$event'])
onResize(event) { this.width = event.target.innerWidth; }
selectAll() { selectAll() {
this.processedData.forEach((ignore, i) => this.selectedRows.add(i)); this.processedData.forEach((ignore, i) => this.selectedRows.add(i));
this.selectionChanged.emit(this.processedData); this.selectionChanged.emit(this.processedData);
@ -143,7 +143,7 @@ export class NgDatatableComponent implements OnInit {
this.sortedDesc = desc; this.sortedDesc = desc;
// Preform sort // Preform sort
this._process(); this.refresh();
} }
updateSelected(index: number) { updateSelected(index: number) {