UNPKG

angular-9-datatable

Version:

DataTable component for Angular 9 framework

16 lines (14 loc) 11.3 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("lodash"),require("rxjs"),require("@angular/common")):"function"==typeof define&&define.amd?define("angular-9-datatable",["exports","@angular/core","lodash","rxjs","@angular/common"],e):e((t=t||self)["angular-9-datatable"]={},t.ng.core,t.lodash,t.rxjs,t.ng.common)}(this,(function(t,e,a,s,i){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */function n(t,e,a,s){var i,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,a):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,a,s);else for(var o=t.length-1;o>=0;o--)(i=t[o])&&(r=(n<3?i(r):n>3?i(e,a,r):i(e,a))||r);return n>3&&r&&Object.defineProperty(e,a,r),r}function r(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function o(t){var e="function"==typeof Symbol&&t[Symbol.iterator],a=0;return e?e.call(t):{next:function(){return t&&a>=t.length&&(t=void 0),{value:t&&t[a++],done:!t}}}}var c=function(){function t(t){this.differs=t,this.inputData=[],this.sortBy="",this.sortOrder="asc",this.sortByChange=new e.EventEmitter,this.sortOrderChange=new e.EventEmitter,this.rowsOnPage=1e3,this.activePage=1,this.mustRecalculateData=!1,this.onSortChange=new s.ReplaySubject(1),this.onPageChange=new e.EventEmitter,this.diff=t.find([]).create(null)}return t.prototype.getSort=function(){return{sortBy:this.sortBy,sortOrder:this.sortOrder}},t.prototype.setSort=function(t,e){this.sortBy===t&&this.sortOrder===e||(this.sortBy=t,this.sortOrder=a.includes(["asc","desc"],e)?e:"asc",this.mustRecalculateData=!0,this.onSortChange.next({sortBy:t,sortOrder:e}),this.sortByChange.emit(this.sortBy),this.sortOrderChange.emit(this.sortOrder))},t.prototype.getPage=function(){return{activePage:this.activePage,rowsOnPage:this.rowsOnPage,dataLength:this.inputData.length}},t.prototype.setPage=function(t,e){this.rowsOnPage===e&&this.activePage===t||(this.activePage=this.activePage!==t?t:this.calculateNewActivePage(this.rowsOnPage,e),this.rowsOnPage=e,this.mustRecalculateData=!0,this.onPageChange.emit({activePage:this.activePage,rowsOnPage:this.rowsOnPage,dataLength:this.inputData?this.inputData.length:0}))},t.prototype.calculateNewActivePage=function(t,e){var a=(this.activePage-1)*t+1;return Math.ceil(a/e)},t.prototype.recalculatePage=function(){var t=Math.ceil(this.inputData.length/this.rowsOnPage);this.activePage=t<this.activePage?t:this.activePage,this.activePage=this.activePage||1,this.onPageChange.emit({activePage:this.activePage,rowsOnPage:this.rowsOnPage,dataLength:this.inputData.length})},t.prototype.ngOnChanges=function(t){t.rowsOnPage&&(this.rowsOnPage=t.rowsOnPage.previousValue,this.setPage(this.activePage,t.rowsOnPage.currentValue),this.mustRecalculateData=!0),(t.sortBy||t.sortOrder)&&(a.includes(["asc","desc"],this.sortOrder)||(console.warn("angular2-datatable: value for input mfSortOrder must be one of ['asc', 'desc'], but is:",this.sortOrder),this.sortOrder="asc"),this.sortBy&&this.onSortChange.next({sortBy:this.sortBy,sortOrder:this.sortOrder}),this.mustRecalculateData=!0),t.inputData&&(this.inputData=t.inputData.currentValue||[],this.recalculatePage(),this.mustRecalculateData=!0)},t.prototype.ngDoCheck=function(){this.diff.diff(this.inputData)&&(this.recalculatePage(),this.mustRecalculateData=!0),this.mustRecalculateData&&(this.fillData(),this.mustRecalculateData=!1)},t.prototype.fillData=function(){this.activePage=this.activePage,this.rowsOnPage=this.rowsOnPage;var t=(this.activePage-1)*this.rowsOnPage,e=this.inputData,s=this.sortBy;e="string"==typeof s||s instanceof String?a.orderBy(e,this.caseInsensitiveIteratee(s),"asc"==this.sortOrder?"asc":"desc"):a.orderBy(e,s,"asc"==this.sortOrder?"asc":"desc"),e=a.slice(e,t,t+this.rowsOnPage),this.data=e},t.prototype.caseInsensitiveIteratee=function(t){return function(e){var a,s,i=e;try{for(var n=o(t.split(".")),r=n.next();!r.done;r=n.next()){var c=r.value;i&&(i=i[c])}}catch(t){a={error:t}}finally{try{r&&!r.done&&(s=n.return)&&s.call(n)}finally{if(a)throw a.error}}return i&&"string"==typeof i||i instanceof String?i.toLowerCase():i}},t.ctorParameters=function(){return[{type:e.IterableDiffers}]},n([e.Input("mfData"),r("design:type",Array)],t.prototype,"inputData",void 0),n([e.Input("mfSortBy"),r("design:type",Object)],t.prototype,"sortBy",void 0),n([e.Input("mfSortOrder"),r("design:type",Object)],t.prototype,"sortOrder",void 0),n([e.Output("mfSortByChange"),r("design:type",Object)],t.prototype,"sortByChange",void 0),n([e.Output("mfSortOrderChange"),r("design:type",Object)],t.prototype,"sortOrderChange",void 0),n([e.Input("mfRowsOnPage"),r("design:type",Object)],t.prototype,"rowsOnPage",void 0),n([e.Input("mfActivePage"),r("design:type",Object)],t.prototype,"activePage",void 0),t=n([e.Directive({selector:"table[mfData]",exportAs:"mfDataTable"}),r("design:paramtypes",[e.IterableDiffers])],t)}(),g=function(){function t(t){this.mfTable=t,this.isSortedByMeAsc=!1,this.isSortedByMeDesc=!1}return t.prototype.ngOnInit=function(){var t=this;this.mfTable.onSortChange.subscribe((function(e){t.isSortedByMeAsc=e.sortBy==t.sortBy&&"asc"==e.sortOrder,t.isSortedByMeDesc=e.sortBy==t.sortBy&&"desc"==e.sortOrder}))},t.prototype.sort=function(){this.isSortedByMeAsc?this.mfTable.setSort(this.sortBy,"desc"):this.mfTable.setSort(this.sortBy,"asc")},t.ctorParameters=function(){return[{type:c}]},n([e.Input("by"),r("design:type",String)],t.prototype,"sortBy",void 0),t=n([e.Component({selector:"mfDefaultSorter",template:'\n <a style="cursor: pointer" (click)="sort()" class="text-nowrap">\n <ng-content></ng-content>\n <span *ngIf="isSortedByMeAsc" class="glyphicon glyphicon-triangle-top fa fa-sort-up" aria-hidden="true"></span>\n <span *ngIf="isSortedByMeDesc" class="glyphicon glyphicon-triangle-bottom fa fa-sort-down" aria-hidden="true"></span>\n </a>'}),r("design:paramtypes",[c])],t)}(),l=function(){function t(t){var e=this;this.injectMfTable=t,this.dataLength=0,this.onPageChangeSubscriber=function(t){e.activePage=t.activePage,e.rowsOnPage=t.rowsOnPage,e.dataLength=t.dataLength,e.lastPage=Math.ceil(e.dataLength/e.rowsOnPage)}}var a,s;return t.prototype.ngOnChanges=function(t){this.mfTable=this.inputMfTable||this.injectMfTable,this.onPageChangeSubscriber(this.mfTable.getPage()),this.mfTable.onPageChange.subscribe(this.onPageChangeSubscriber)},t.prototype.setPage=function(t){this.mfTable.setPage(t,this.rowsOnPage)},t.prototype.setRowsOnPage=function(t){this.mfTable.setPage(this.activePage,t)},t.ctorParameters=function(){return[{type:c,decorators:[{type:e.Optional}]}]},n([e.Input("mfTable"),r("design:type",c)],t.prototype,"inputMfTable",void 0),t=n([e.Component({selector:"mfPaginator",template:"<ng-content></ng-content>"}),(a=0,s=e.Optional(),function(t,e){s(t,e,a)}),r("design:paramtypes",[c])],t)}(),p=function(){function t(){this.rowsOnPageSet=[],this.minRowsOnPage=0}return t.prototype.ngOnChanges=function(t){t.rowsOnPageSet&&(this.minRowsOnPage=a.min(this.rowsOnPageSet))},n([e.Input("rowsOnPageSet"),r("design:type",Object)],t.prototype,"rowsOnPageSet",void 0),n([e.Input("mfTable"),r("design:type",c)],t.prototype,"mfTable",void 0),t=n([e.Component({selector:"mfBootstrapPaginator",template:'\n <mfPaginator #p [mfTable]="mfTable">\n <ul class="pagination" *ngIf="p.dataLength > p.rowsOnPage">\n <li class="page-item" [class.disabled]="p.activePage <= 1" (click)="p.setPage(1)">\n <a class="page-link" style="cursor: pointer">&laquo;</a>\n </li>\n <li class="page-item" *ngIf="p.activePage > 4 && p.activePage + 1 > p.lastPage" (click)="p.setPage(p.activePage - 4)">\n <a class="page-link" style="cursor: pointer">{{p.activePage-4}}</a>\n </li>\n <li class="page-item" *ngIf="p.activePage > 3 && p.activePage + 2 > p.lastPage" (click)="p.setPage(p.activePage - 3)">\n <a class="page-link" style="cursor: pointer">{{p.activePage-3}}</a>\n </li>\n <li class="page-item" *ngIf="p.activePage > 2" (click)="p.setPage(p.activePage - 2)">\n <a class="page-link" style="cursor: pointer">{{p.activePage-2}}</a>\n </li>\n <li class="page-item" *ngIf="p.activePage > 1" (click)="p.setPage(p.activePage - 1)">\n <a class="page-link" style="cursor: pointer">{{p.activePage-1}}</a>\n </li>\n <li class="page-item active">\n <a class="page-link" style="cursor: pointer">{{p.activePage}}</a>\n </li>\n <li class="page-item" *ngIf="p.activePage + 1 <= p.lastPage" (click)="p.setPage(p.activePage + 1)">\n <a class="page-link" style="cursor: pointer">{{p.activePage+1}}</a>\n </li>\n <li class="page-item" *ngIf="p.activePage + 2 <= p.lastPage" (click)="p.setPage(p.activePage + 2)">\n <a class="page-link" style="cursor: pointer">{{p.activePage+2}}</a>\n </li>\n <li class="page-item" *ngIf="p.activePage + 3 <= p.lastPage && p.activePage < 3" (click)="p.setPage(p.activePage + 3)">\n <a class="page-link" style="cursor: pointer">{{p.activePage+3}}</a>\n </li>\n <li class="page-item" *ngIf="p.activePage + 4 <= p.lastPage && p.activePage < 2" (click)="p.setPage(p.activePage + 4)">\n <a class="page-link" style="cursor: pointer">{{p.activePage+4}}</a>\n </li>\n <li class="page-item" [class.disabled]="p.activePage >= p.lastPage" (click)="p.setPage(p.lastPage)">\n <a class="page-link" style="cursor: pointer">&raquo;</a>\n </li>\n </ul>\n <ul class="pagination pull-right float-sm-right" *ngIf="p.dataLength > minRowsOnPage">\n <li class="page-item" *ngFor="let rows of rowsOnPageSet" [class.active]="p.rowsOnPage===rows" (click)="p.setRowsOnPage(rows)">\n <a class="page-link" style="cursor: pointer">{{rows}}</a>\n </li>\n </ul>\n </mfPaginator>\n '})],t)}(),u=function(){function t(){}return t=n([e.NgModule({imports:[i.CommonModule],declarations:[c,g,l,p],exports:[c,g,l,p]})],t)}();t.BootstrapPaginator=p,t.DataTable=c,t.DefaultSorter=g,t.NgxDataTableModule=u,t.Paginator=l,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=angular-9-datatable.umd.min.js.map