table.js 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. var __param = (this && this.__param) || function (paramIndex, decorator) {
  12. return function (target, key) { decorator(target, key, paramIndex); }
  13. };
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. var core_1 = require("@angular/core");
  16. var common_1 = require("@angular/common");
  17. var shared_1 = require("../common/shared");
  18. var paginator_1 = require("../paginator/paginator");
  19. var domhandler_1 = require("../dom/domhandler");
  20. var objectutils_1 = require("../utils/objectutils");
  21. var core_2 = require("@angular/core");
  22. var rxjs_1 = require("rxjs");
  23. var filterutils_1 = require("../utils/filterutils");
  24. var TableService = /** @class */ (function () {
  25. function TableService() {
  26. this.sortSource = new rxjs_1.Subject();
  27. this.selectionSource = new rxjs_1.Subject();
  28. this.contextMenuSource = new rxjs_1.Subject();
  29. this.valueSource = new rxjs_1.Subject();
  30. this.totalRecordsSource = new rxjs_1.Subject();
  31. this.columnsSource = new rxjs_1.Subject();
  32. this.sortSource$ = this.sortSource.asObservable();
  33. this.selectionSource$ = this.selectionSource.asObservable();
  34. this.contextMenuSource$ = this.contextMenuSource.asObservable();
  35. this.valueSource$ = this.valueSource.asObservable();
  36. this.totalRecordsSource$ = this.totalRecordsSource.asObservable();
  37. this.columnsSource$ = this.columnsSource.asObservable();
  38. }
  39. TableService.prototype.onSort = function (sortMeta) {
  40. this.sortSource.next(sortMeta);
  41. };
  42. TableService.prototype.onSelectionChange = function () {
  43. this.selectionSource.next();
  44. };
  45. TableService.prototype.onContextMenu = function (data) {
  46. this.contextMenuSource.next(data);
  47. };
  48. TableService.prototype.onValueChange = function (value) {
  49. this.valueSource.next(value);
  50. };
  51. TableService.prototype.onTotalRecordsChange = function (value) {
  52. this.totalRecordsSource.next(value);
  53. };
  54. TableService.prototype.onColumnsChange = function (columns) {
  55. this.columnsSource.next(columns);
  56. };
  57. TableService = __decorate([
  58. core_2.Injectable()
  59. ], TableService);
  60. return TableService;
  61. }());
  62. exports.TableService = TableService;
  63. var Table = /** @class */ (function () {
  64. function Table(el, zone, tableService, cd) {
  65. this.el = el;
  66. this.zone = zone;
  67. this.tableService = tableService;
  68. this.cd = cd;
  69. this.pageLinks = 5;
  70. this.alwaysShowPaginator = true;
  71. this.paginatorPosition = 'bottom';
  72. this.paginatorDropdownScrollHeight = '200px';
  73. this.currentPageReportTemplate = '{currentPage} of {totalPages}';
  74. this.defaultSortOrder = 1;
  75. this.sortMode = 'single';
  76. this.resetPageOnSort = true;
  77. this.selectionChange = new core_1.EventEmitter();
  78. this.contextMenuSelectionChange = new core_1.EventEmitter();
  79. this.contextMenuSelectionMode = "separate";
  80. this.rowTrackBy = function (index, item) { return item; };
  81. this.lazy = false;
  82. this.lazyLoadOnInit = true;
  83. this.compareSelectionBy = 'deepEquals';
  84. this.csvSeparator = ',';
  85. this.exportFilename = 'download';
  86. this.filters = {};
  87. this.filterDelay = 300;
  88. this.expandedRowKeys = {};
  89. this.editingRowKeys = {};
  90. this.rowExpandMode = 'multiple';
  91. this.virtualScrollDelay = 150;
  92. this.virtualRowHeight = 28;
  93. this.columnResizeMode = 'fit';
  94. this.loadingIcon = 'pi pi-spinner';
  95. this.showLoader = true;
  96. this.stateStorage = 'session';
  97. this.editMode = 'cell';
  98. this.onRowSelect = new core_1.EventEmitter();
  99. this.onRowUnselect = new core_1.EventEmitter();
  100. this.onPage = new core_1.EventEmitter();
  101. this.onSort = new core_1.EventEmitter();
  102. this.onFilter = new core_1.EventEmitter();
  103. this.onLazyLoad = new core_1.EventEmitter();
  104. this.onRowExpand = new core_1.EventEmitter();
  105. this.onRowCollapse = new core_1.EventEmitter();
  106. this.onContextMenuSelect = new core_1.EventEmitter();
  107. this.onColResize = new core_1.EventEmitter();
  108. this.onColReorder = new core_1.EventEmitter();
  109. this.onRowReorder = new core_1.EventEmitter();
  110. this.onEditInit = new core_1.EventEmitter();
  111. this.onEditComplete = new core_1.EventEmitter();
  112. this.onEditCancel = new core_1.EventEmitter();
  113. this.onHeaderCheckboxToggle = new core_1.EventEmitter();
  114. this.sortFunction = new core_1.EventEmitter();
  115. this.firstChange = new core_1.EventEmitter();
  116. this.rowsChange = new core_1.EventEmitter();
  117. this.onStateSave = new core_1.EventEmitter();
  118. this.onStateRestore = new core_1.EventEmitter();
  119. this._value = [];
  120. this._totalRecords = 0;
  121. this._first = 0;
  122. this.selectionKeys = {};
  123. this._sortOrder = 1;
  124. }
  125. Table.prototype.ngOnInit = function () {
  126. if (this.lazy && this.lazyLoadOnInit) {
  127. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  128. if (this.restoringFilter) {
  129. this.restoringFilter = false;
  130. }
  131. }
  132. this.initialized = true;
  133. };
  134. Table.prototype.ngAfterContentInit = function () {
  135. var _this = this;
  136. this.templates.forEach(function (item) {
  137. switch (item.getType()) {
  138. case 'caption':
  139. _this.captionTemplate = item.template;
  140. break;
  141. case 'header':
  142. _this.headerTemplate = item.template;
  143. break;
  144. case 'body':
  145. _this.bodyTemplate = item.template;
  146. break;
  147. case 'loadingbody':
  148. _this.loadingBodyTemplate = item.template;
  149. break;
  150. case 'footer':
  151. _this.footerTemplate = item.template;
  152. break;
  153. case 'summary':
  154. _this.summaryTemplate = item.template;
  155. break;
  156. case 'colgroup':
  157. _this.colGroupTemplate = item.template;
  158. break;
  159. case 'rowexpansion':
  160. _this.expandedRowTemplate = item.template;
  161. break;
  162. case 'frozenrows':
  163. _this.frozenRowsTemplate = item.template;
  164. break;
  165. case 'frozenheader':
  166. _this.frozenHeaderTemplate = item.template;
  167. break;
  168. case 'frozenbody':
  169. _this.frozenBodyTemplate = item.template;
  170. break;
  171. case 'frozenfooter':
  172. _this.frozenFooterTemplate = item.template;
  173. break;
  174. case 'frozencolgroup':
  175. _this.frozenColGroupTemplate = item.template;
  176. break;
  177. case 'emptymessage':
  178. _this.emptyMessageTemplate = item.template;
  179. break;
  180. case 'paginatorleft':
  181. _this.paginatorLeftTemplate = item.template;
  182. break;
  183. case 'paginatorright':
  184. _this.paginatorRightTemplate = item.template;
  185. break;
  186. }
  187. });
  188. };
  189. Table.prototype.ngAfterViewInit = function () {
  190. if (this.isStateful() && this.resizableColumns) {
  191. this.restoreColumnWidths();
  192. }
  193. };
  194. Object.defineProperty(Table.prototype, "value", {
  195. get: function () {
  196. return this._value;
  197. },
  198. set: function (val) {
  199. if (this.isStateful() && !this.stateRestored) {
  200. this.restoreState();
  201. }
  202. this._value = val;
  203. if (!this.lazy) {
  204. this.totalRecords = (this._value ? this._value.length : 0);
  205. if (this.sortMode == 'single' && this.sortField)
  206. this.sortSingle();
  207. else if (this.sortMode == 'multiple' && this.multiSortMeta)
  208. this.sortMultiple();
  209. else if (this.hasFilter()) //sort already filters
  210. this._filter();
  211. }
  212. if (this.virtualScroll && this.virtualScrollCallback) {
  213. this.virtualScrollCallback();
  214. }
  215. this.tableService.onValueChange(val);
  216. },
  217. enumerable: true,
  218. configurable: true
  219. });
  220. Object.defineProperty(Table.prototype, "columns", {
  221. get: function () {
  222. return this._columns;
  223. },
  224. set: function (cols) {
  225. this._columns = cols;
  226. this.tableService.onColumnsChange(cols);
  227. if (this._columns && this.isStateful() && this.reorderableColumns && !this.columnOrderStateRestored) {
  228. this.restoreColumnOrder();
  229. }
  230. },
  231. enumerable: true,
  232. configurable: true
  233. });
  234. Object.defineProperty(Table.prototype, "first", {
  235. get: function () {
  236. return this._first;
  237. },
  238. set: function (val) {
  239. this._first = val;
  240. },
  241. enumerable: true,
  242. configurable: true
  243. });
  244. Object.defineProperty(Table.prototype, "rows", {
  245. get: function () {
  246. return this._rows;
  247. },
  248. set: function (val) {
  249. this._rows = val;
  250. },
  251. enumerable: true,
  252. configurable: true
  253. });
  254. Object.defineProperty(Table.prototype, "totalRecords", {
  255. get: function () {
  256. return this._totalRecords;
  257. },
  258. set: function (val) {
  259. this._totalRecords = val;
  260. this.tableService.onTotalRecordsChange(this._totalRecords);
  261. },
  262. enumerable: true,
  263. configurable: true
  264. });
  265. Object.defineProperty(Table.prototype, "sortField", {
  266. get: function () {
  267. return this._sortField;
  268. },
  269. set: function (val) {
  270. this._sortField = val;
  271. //avoid triggering lazy load prior to lazy initialization at onInit
  272. if (!this.lazy || this.initialized) {
  273. if (this.sortMode === 'single') {
  274. this.sortSingle();
  275. }
  276. }
  277. },
  278. enumerable: true,
  279. configurable: true
  280. });
  281. Object.defineProperty(Table.prototype, "sortOrder", {
  282. get: function () {
  283. return this._sortOrder;
  284. },
  285. set: function (val) {
  286. this._sortOrder = val;
  287. //avoid triggering lazy load prior to lazy initialization at onInit
  288. if (!this.lazy || this.initialized) {
  289. if (this.sortMode === 'single') {
  290. this.sortSingle();
  291. }
  292. }
  293. },
  294. enumerable: true,
  295. configurable: true
  296. });
  297. Object.defineProperty(Table.prototype, "multiSortMeta", {
  298. get: function () {
  299. return this._multiSortMeta;
  300. },
  301. set: function (val) {
  302. this._multiSortMeta = val;
  303. if (this.sortMode === 'multiple') {
  304. this.sortMultiple();
  305. }
  306. },
  307. enumerable: true,
  308. configurable: true
  309. });
  310. Object.defineProperty(Table.prototype, "selection", {
  311. get: function () {
  312. return this._selection;
  313. },
  314. set: function (val) {
  315. this._selection = val;
  316. if (!this.preventSelectionSetterPropagation) {
  317. this.updateSelectionKeys();
  318. this.tableService.onSelectionChange();
  319. }
  320. this.preventSelectionSetterPropagation = false;
  321. },
  322. enumerable: true,
  323. configurable: true
  324. });
  325. Table.prototype.updateSelectionKeys = function () {
  326. if (this.dataKey && this._selection) {
  327. this.selectionKeys = {};
  328. if (Array.isArray(this._selection)) {
  329. for (var _i = 0, _a = this._selection; _i < _a.length; _i++) {
  330. var data = _a[_i];
  331. this.selectionKeys[String(objectutils_1.ObjectUtils.resolveFieldData(data, this.dataKey))] = 1;
  332. }
  333. }
  334. else {
  335. this.selectionKeys[String(objectutils_1.ObjectUtils.resolveFieldData(this._selection, this.dataKey))] = 1;
  336. }
  337. }
  338. };
  339. Table.prototype.onPageChange = function (event) {
  340. this.first = event.first;
  341. this.rows = event.rows;
  342. if (this.lazy) {
  343. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  344. }
  345. this.onPage.emit({
  346. first: this.first,
  347. rows: this.rows
  348. });
  349. this.firstChange.emit(this.first);
  350. this.rowsChange.emit(this.rows);
  351. this.tableService.onValueChange(this.value);
  352. if (this.isStateful()) {
  353. this.saveState();
  354. }
  355. this.anchorRowIndex = null;
  356. };
  357. Table.prototype.sort = function (event) {
  358. var originalEvent = event.originalEvent;
  359. if (this.sortMode === 'single') {
  360. this._sortOrder = (this.sortField === event.field) ? this.sortOrder * -1 : this.defaultSortOrder;
  361. this._sortField = event.field;
  362. this.sortSingle();
  363. }
  364. if (this.sortMode === 'multiple') {
  365. var metaKey = originalEvent.metaKey || originalEvent.ctrlKey;
  366. var sortMeta = this.getSortMeta(event.field);
  367. if (sortMeta) {
  368. if (!metaKey) {
  369. this._multiSortMeta = [{ field: event.field, order: sortMeta.order * -1 }];
  370. }
  371. else {
  372. sortMeta.order = sortMeta.order * -1;
  373. }
  374. }
  375. else {
  376. if (!metaKey || !this.multiSortMeta) {
  377. this._multiSortMeta = [];
  378. }
  379. this._multiSortMeta.push({ field: event.field, order: this.defaultSortOrder });
  380. }
  381. this.sortMultiple();
  382. }
  383. if (this.isStateful()) {
  384. this.saveState();
  385. }
  386. this.anchorRowIndex = null;
  387. };
  388. Table.prototype.sortSingle = function () {
  389. var _this = this;
  390. if (this.sortField && this.sortOrder) {
  391. if (this.restoringSort) {
  392. this.restoringSort = false;
  393. }
  394. else if (this.resetPageOnSort) {
  395. this.first = 0;
  396. this.firstChange.emit(this.first);
  397. }
  398. if (this.lazy) {
  399. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  400. }
  401. else if (this.value) {
  402. if (this.customSort) {
  403. this.sortFunction.emit({
  404. data: this.value,
  405. mode: this.sortMode,
  406. field: this.sortField,
  407. order: this.sortOrder
  408. });
  409. }
  410. else {
  411. this.value.sort(function (data1, data2) {
  412. var value1 = objectutils_1.ObjectUtils.resolveFieldData(data1, _this.sortField);
  413. var value2 = objectutils_1.ObjectUtils.resolveFieldData(data2, _this.sortField);
  414. var result = null;
  415. if (value1 == null && value2 != null)
  416. result = -1;
  417. else if (value1 != null && value2 == null)
  418. result = 1;
  419. else if (value1 == null && value2 == null)
  420. result = 0;
  421. else if (typeof value1 === 'string' && typeof value2 === 'string')
  422. result = value1.localeCompare(value2);
  423. else
  424. result = (value1 < value2) ? -1 : (value1 > value2) ? 1 : 0;
  425. return (_this.sortOrder * result);
  426. });
  427. }
  428. if (this.hasFilter()) {
  429. this._filter();
  430. }
  431. }
  432. var sortMeta = {
  433. field: this.sortField,
  434. order: this.sortOrder
  435. };
  436. this.onSort.emit(sortMeta);
  437. this.tableService.onSort(sortMeta);
  438. }
  439. };
  440. Table.prototype.sortMultiple = function () {
  441. var _this = this;
  442. if (this.multiSortMeta) {
  443. if (this.lazy) {
  444. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  445. }
  446. else if (this.value) {
  447. if (this.customSort) {
  448. this.sortFunction.emit({
  449. data: this.value,
  450. mode: this.sortMode,
  451. multiSortMeta: this.multiSortMeta
  452. });
  453. }
  454. else {
  455. this.value.sort(function (data1, data2) {
  456. return _this.multisortField(data1, data2, _this.multiSortMeta, 0);
  457. });
  458. }
  459. if (this.hasFilter()) {
  460. this._filter();
  461. }
  462. }
  463. this.onSort.emit({
  464. multisortmeta: this.multiSortMeta
  465. });
  466. this.tableService.onSort(this.multiSortMeta);
  467. }
  468. };
  469. Table.prototype.multisortField = function (data1, data2, multiSortMeta, index) {
  470. var value1 = objectutils_1.ObjectUtils.resolveFieldData(data1, multiSortMeta[index].field);
  471. var value2 = objectutils_1.ObjectUtils.resolveFieldData(data2, multiSortMeta[index].field);
  472. var result = null;
  473. if (value1 == null && value2 != null)
  474. result = -1;
  475. else if (value1 != null && value2 == null)
  476. result = 1;
  477. else if (value1 == null && value2 == null)
  478. result = 0;
  479. else if (typeof value1 == 'string' || value1 instanceof String) {
  480. if (value1.localeCompare && (value1 != value2)) {
  481. return (multiSortMeta[index].order * value1.localeCompare(value2));
  482. }
  483. }
  484. else {
  485. result = (value1 < value2) ? -1 : 1;
  486. }
  487. if (value1 == value2) {
  488. return (multiSortMeta.length - 1) > (index) ? (this.multisortField(data1, data2, multiSortMeta, index + 1)) : 0;
  489. }
  490. return (multiSortMeta[index].order * result);
  491. };
  492. Table.prototype.getSortMeta = function (field) {
  493. if (this.multiSortMeta && this.multiSortMeta.length) {
  494. for (var i = 0; i < this.multiSortMeta.length; i++) {
  495. if (this.multiSortMeta[i].field === field) {
  496. return this.multiSortMeta[i];
  497. }
  498. }
  499. }
  500. return null;
  501. };
  502. Table.prototype.isSorted = function (field) {
  503. if (this.sortMode === 'single') {
  504. return (this.sortField && this.sortField === field);
  505. }
  506. else if (this.sortMode === 'multiple') {
  507. var sorted = false;
  508. if (this.multiSortMeta) {
  509. for (var i = 0; i < this.multiSortMeta.length; i++) {
  510. if (this.multiSortMeta[i].field == field) {
  511. sorted = true;
  512. break;
  513. }
  514. }
  515. }
  516. return sorted;
  517. }
  518. };
  519. Table.prototype.handleRowClick = function (event) {
  520. var target = event.originalEvent.target;
  521. var targetNode = target.nodeName;
  522. var parentNode = target.parentElement && target.parentElement.nodeName;
  523. if (targetNode == 'INPUT' || targetNode == 'BUTTON' || targetNode == 'A' ||
  524. parentNode == 'INPUT' || parentNode == 'BUTTON' || parentNode == 'A' ||
  525. (domhandler_1.DomHandler.hasClass(event.originalEvent.target, 'ui-clickable'))) {
  526. return;
  527. }
  528. if (this.selectionMode) {
  529. this.preventSelectionSetterPropagation = true;
  530. if (this.isMultipleSelectionMode() && event.originalEvent.shiftKey && this.anchorRowIndex != null) {
  531. domhandler_1.DomHandler.clearSelection();
  532. if (this.rangeRowIndex != null) {
  533. this.clearSelectionRange(event.originalEvent);
  534. }
  535. this.rangeRowIndex = event.rowIndex;
  536. this.selectRange(event.originalEvent, event.rowIndex);
  537. }
  538. else {
  539. var rowData = event.rowData;
  540. var selected = this.isSelected(rowData);
  541. var metaSelection = this.rowTouched ? false : this.metaKeySelection;
  542. var dataKeyValue = this.dataKey ? String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey)) : null;
  543. this.anchorRowIndex = event.rowIndex;
  544. this.rangeRowIndex = event.rowIndex;
  545. if (metaSelection) {
  546. var metaKey = event.originalEvent.metaKey || event.originalEvent.ctrlKey;
  547. if (selected && metaKey) {
  548. if (this.isSingleSelectionMode()) {
  549. this._selection = null;
  550. this.selectionKeys = {};
  551. this.selectionChange.emit(null);
  552. }
  553. else {
  554. var selectionIndex_1 = this.findIndexInSelection(rowData);
  555. this._selection = this.selection.filter(function (val, i) { return i != selectionIndex_1; });
  556. this.selectionChange.emit(this.selection);
  557. if (dataKeyValue) {
  558. delete this.selectionKeys[dataKeyValue];
  559. }
  560. }
  561. this.onRowUnselect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row' });
  562. }
  563. else {
  564. if (this.isSingleSelectionMode()) {
  565. this._selection = rowData;
  566. this.selectionChange.emit(rowData);
  567. if (dataKeyValue) {
  568. this.selectionKeys = {};
  569. this.selectionKeys[dataKeyValue] = 1;
  570. }
  571. }
  572. else if (this.isMultipleSelectionMode()) {
  573. if (metaKey) {
  574. this._selection = this.selection || [];
  575. }
  576. else {
  577. this._selection = [];
  578. this.selectionKeys = {};
  579. }
  580. this._selection = this.selection.concat([rowData]);
  581. this.selectionChange.emit(this.selection);
  582. if (dataKeyValue) {
  583. this.selectionKeys[dataKeyValue] = 1;
  584. }
  585. }
  586. this.onRowSelect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row', index: event.rowIndex });
  587. }
  588. }
  589. else {
  590. if (this.selectionMode === 'single') {
  591. if (selected) {
  592. this._selection = null;
  593. this.selectionKeys = {};
  594. this.selectionChange.emit(this.selection);
  595. this.onRowUnselect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row' });
  596. }
  597. else {
  598. this._selection = rowData;
  599. this.selectionChange.emit(this.selection);
  600. this.onRowSelect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row', index: event.rowIndex });
  601. if (dataKeyValue) {
  602. this.selectionKeys = {};
  603. this.selectionKeys[dataKeyValue] = 1;
  604. }
  605. }
  606. }
  607. else if (this.selectionMode === 'multiple') {
  608. if (selected) {
  609. var selectionIndex_2 = this.findIndexInSelection(rowData);
  610. this._selection = this.selection.filter(function (val, i) { return i != selectionIndex_2; });
  611. this.selectionChange.emit(this.selection);
  612. this.onRowUnselect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row' });
  613. if (dataKeyValue) {
  614. delete this.selectionKeys[dataKeyValue];
  615. }
  616. }
  617. else {
  618. this._selection = this.selection ? this.selection.concat([rowData]) : [rowData];
  619. this.selectionChange.emit(this.selection);
  620. this.onRowSelect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row', index: event.rowIndex });
  621. if (dataKeyValue) {
  622. this.selectionKeys[dataKeyValue] = 1;
  623. }
  624. }
  625. }
  626. }
  627. }
  628. this.tableService.onSelectionChange();
  629. if (this.isStateful()) {
  630. this.saveState();
  631. }
  632. }
  633. this.rowTouched = false;
  634. };
  635. Table.prototype.handleRowTouchEnd = function (event) {
  636. this.rowTouched = true;
  637. };
  638. Table.prototype.handleRowRightClick = function (event) {
  639. if (this.contextMenu) {
  640. var rowData = event.rowData;
  641. if (this.contextMenuSelectionMode === 'separate') {
  642. this.contextMenuSelection = rowData;
  643. this.contextMenuSelectionChange.emit(rowData);
  644. this.onContextMenuSelect.emit({ originalEvent: event.originalEvent, data: rowData, index: event.rowIndex });
  645. this.contextMenu.show(event.originalEvent);
  646. this.tableService.onContextMenu(rowData);
  647. }
  648. else if (this.contextMenuSelectionMode === 'joint') {
  649. this.preventSelectionSetterPropagation = true;
  650. var selected = this.isSelected(rowData);
  651. var dataKeyValue = this.dataKey ? String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey)) : null;
  652. if (!selected) {
  653. if (this.isSingleSelectionMode()) {
  654. this.selection = rowData;
  655. this.selectionChange.emit(rowData);
  656. }
  657. else if (this.isMultipleSelectionMode()) {
  658. this.selection = [rowData];
  659. this.selectionChange.emit(this.selection);
  660. }
  661. if (dataKeyValue) {
  662. this.selectionKeys[dataKeyValue] = 1;
  663. }
  664. }
  665. this.contextMenu.show(event.originalEvent);
  666. this.onContextMenuSelect.emit({ originalEvent: event, data: rowData, index: event.rowIndex });
  667. }
  668. }
  669. };
  670. Table.prototype.selectRange = function (event, rowIndex) {
  671. var rangeStart, rangeEnd;
  672. if (this.anchorRowIndex > rowIndex) {
  673. rangeStart = rowIndex;
  674. rangeEnd = this.anchorRowIndex;
  675. }
  676. else if (this.anchorRowIndex < rowIndex) {
  677. rangeStart = this.anchorRowIndex;
  678. rangeEnd = rowIndex;
  679. }
  680. else {
  681. rangeStart = rowIndex;
  682. rangeEnd = rowIndex;
  683. }
  684. if (this.lazy && this.paginator) {
  685. rangeStart -= this.first;
  686. rangeEnd -= this.first;
  687. }
  688. for (var i = rangeStart; i <= rangeEnd; i++) {
  689. var rangeRowData = this.filteredValue ? this.filteredValue[i] : this.value[i];
  690. if (!this.isSelected(rangeRowData)) {
  691. this._selection = this.selection.concat([rangeRowData]);
  692. var dataKeyValue = this.dataKey ? String(objectutils_1.ObjectUtils.resolveFieldData(rangeRowData, this.dataKey)) : null;
  693. if (dataKeyValue) {
  694. this.selectionKeys[dataKeyValue] = 1;
  695. }
  696. this.onRowSelect.emit({ originalEvent: event, data: rangeRowData, type: 'row' });
  697. }
  698. }
  699. this.selectionChange.emit(this.selection);
  700. };
  701. Table.prototype.clearSelectionRange = function (event) {
  702. var rangeStart, rangeEnd;
  703. if (this.rangeRowIndex > this.anchorRowIndex) {
  704. rangeStart = this.anchorRowIndex;
  705. rangeEnd = this.rangeRowIndex;
  706. }
  707. else if (this.rangeRowIndex < this.anchorRowIndex) {
  708. rangeStart = this.rangeRowIndex;
  709. rangeEnd = this.anchorRowIndex;
  710. }
  711. else {
  712. rangeStart = this.rangeRowIndex;
  713. rangeEnd = this.rangeRowIndex;
  714. }
  715. var _loop_1 = function (i) {
  716. var rangeRowData = this_1.value[i];
  717. var selectionIndex = this_1.findIndexInSelection(rangeRowData);
  718. this_1._selection = this_1.selection.filter(function (val, i) { return i != selectionIndex; });
  719. var dataKeyValue = this_1.dataKey ? String(objectutils_1.ObjectUtils.resolveFieldData(rangeRowData, this_1.dataKey)) : null;
  720. if (dataKeyValue) {
  721. delete this_1.selectionKeys[dataKeyValue];
  722. }
  723. this_1.onRowUnselect.emit({ originalEvent: event, data: rangeRowData, type: 'row' });
  724. };
  725. var this_1 = this;
  726. for (var i = rangeStart; i <= rangeEnd; i++) {
  727. _loop_1(i);
  728. }
  729. };
  730. Table.prototype.isSelected = function (rowData) {
  731. if (rowData && this.selection) {
  732. if (this.dataKey) {
  733. return this.selectionKeys[objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey)] !== undefined;
  734. }
  735. else {
  736. if (this.selection instanceof Array)
  737. return this.findIndexInSelection(rowData) > -1;
  738. else
  739. return this.equals(rowData, this.selection);
  740. }
  741. }
  742. return false;
  743. };
  744. Table.prototype.findIndexInSelection = function (rowData) {
  745. var index = -1;
  746. if (this.selection && this.selection.length) {
  747. for (var i = 0; i < this.selection.length; i++) {
  748. if (this.equals(rowData, this.selection[i])) {
  749. index = i;
  750. break;
  751. }
  752. }
  753. }
  754. return index;
  755. };
  756. Table.prototype.toggleRowWithRadio = function (event, rowData) {
  757. this.preventSelectionSetterPropagation = true;
  758. if (this.selection != rowData) {
  759. this._selection = rowData;
  760. this.selectionChange.emit(this.selection);
  761. this.onRowSelect.emit({ originalEvent: event.originalEvent, index: event.rowIndex, data: rowData, type: 'radiobutton' });
  762. if (this.dataKey) {
  763. this.selectionKeys = {};
  764. this.selectionKeys[String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey))] = 1;
  765. }
  766. }
  767. else {
  768. this._selection = null;
  769. this.selectionChange.emit(this.selection);
  770. this.onRowUnselect.emit({ originalEvent: event.originalEvent, index: event.rowIndex, data: rowData, type: 'radiobutton' });
  771. }
  772. this.tableService.onSelectionChange();
  773. if (this.isStateful()) {
  774. this.saveState();
  775. }
  776. };
  777. Table.prototype.toggleRowWithCheckbox = function (event, rowData) {
  778. this.selection = this.selection || [];
  779. var selected = this.isSelected(rowData);
  780. var dataKeyValue = this.dataKey ? String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey)) : null;
  781. this.preventSelectionSetterPropagation = true;
  782. if (selected) {
  783. var selectionIndex_3 = this.findIndexInSelection(rowData);
  784. this._selection = this.selection.filter(function (val, i) { return i != selectionIndex_3; });
  785. this.selectionChange.emit(this.selection);
  786. this.onRowUnselect.emit({ originalEvent: event.originalEvent, index: event.rowIndex, data: rowData, type: 'checkbox' });
  787. if (dataKeyValue) {
  788. delete this.selectionKeys[dataKeyValue];
  789. }
  790. }
  791. else {
  792. this._selection = this.selection ? this.selection.concat([rowData]) : [rowData];
  793. this.selectionChange.emit(this.selection);
  794. this.onRowSelect.emit({ originalEvent: event.originalEvent, index: event.rowIndex, data: rowData, type: 'checkbox' });
  795. if (dataKeyValue) {
  796. this.selectionKeys[dataKeyValue] = 1;
  797. }
  798. }
  799. this.tableService.onSelectionChange();
  800. if (this.isStateful()) {
  801. this.saveState();
  802. }
  803. };
  804. Table.prototype.toggleRowsWithCheckbox = function (event, check) {
  805. this._selection = check ? this.filteredValue ? this.filteredValue.slice() : this.value.slice() : [];
  806. this.preventSelectionSetterPropagation = true;
  807. this.updateSelectionKeys();
  808. this.selectionChange.emit(this._selection);
  809. this.tableService.onSelectionChange();
  810. this.onHeaderCheckboxToggle.emit({ originalEvent: event, checked: check });
  811. if (this.isStateful()) {
  812. this.saveState();
  813. }
  814. };
  815. Table.prototype.equals = function (data1, data2) {
  816. return this.compareSelectionBy === 'equals' ? (data1 === data2) : objectutils_1.ObjectUtils.equals(data1, data2, this.dataKey);
  817. };
  818. Table.prototype.filter = function (value, field, matchMode) {
  819. var _this = this;
  820. if (this.filterTimeout) {
  821. clearTimeout(this.filterTimeout);
  822. }
  823. if (!this.isFilterBlank(value)) {
  824. this.filters[field] = { value: value, matchMode: matchMode };
  825. }
  826. else if (this.filters[field]) {
  827. delete this.filters[field];
  828. }
  829. this.filterTimeout = setTimeout(function () {
  830. _this._filter();
  831. _this.filterTimeout = null;
  832. }, this.filterDelay);
  833. this.anchorRowIndex = null;
  834. };
  835. Table.prototype.filterGlobal = function (value, matchMode) {
  836. this.filter(value, 'global', matchMode);
  837. };
  838. Table.prototype.isFilterBlank = function (filter) {
  839. if (filter !== null && filter !== undefined) {
  840. if ((typeof filter === 'string' && filter.trim().length == 0) || (filter instanceof Array && filter.length == 0))
  841. return true;
  842. else
  843. return false;
  844. }
  845. return true;
  846. };
  847. Table.prototype._filter = function () {
  848. if (!this.restoringFilter) {
  849. this.first = 0;
  850. this.firstChange.emit(this.first);
  851. }
  852. if (this.lazy) {
  853. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  854. }
  855. else {
  856. if (!this.value) {
  857. return;
  858. }
  859. if (!this.hasFilter()) {
  860. this.filteredValue = null;
  861. if (this.paginator) {
  862. this.totalRecords = this.value ? this.value.length : 0;
  863. }
  864. }
  865. else {
  866. var globalFilterFieldsArray = void 0;
  867. if (this.filters['global']) {
  868. if (!this.columns && !this.globalFilterFields)
  869. throw new Error('Global filtering requires dynamic columns or globalFilterFields to be defined.');
  870. else
  871. globalFilterFieldsArray = this.globalFilterFields || this.columns;
  872. }
  873. this.filteredValue = [];
  874. for (var i = 0; i < this.value.length; i++) {
  875. var localMatch = true;
  876. var globalMatch = false;
  877. var localFiltered = false;
  878. for (var prop in this.filters) {
  879. if (this.filters.hasOwnProperty(prop) && prop !== 'global') {
  880. localFiltered = true;
  881. var filterMeta = this.filters[prop];
  882. var filterField = prop;
  883. var filterValue = filterMeta.value;
  884. var filterMatchMode = filterMeta.matchMode || 'startsWith';
  885. var dataFieldValue = objectutils_1.ObjectUtils.resolveFieldData(this.value[i], filterField);
  886. var filterConstraint = filterutils_1.FilterUtils[filterMatchMode];
  887. if (!filterConstraint(dataFieldValue, filterValue)) {
  888. localMatch = false;
  889. }
  890. if (!localMatch) {
  891. break;
  892. }
  893. }
  894. }
  895. if (this.filters['global'] && !globalMatch && globalFilterFieldsArray) {
  896. for (var j = 0; j < globalFilterFieldsArray.length; j++) {
  897. var globalFilterField = globalFilterFieldsArray[j].field || globalFilterFieldsArray[j];
  898. globalMatch = filterutils_1.FilterUtils[this.filters['global'].matchMode](objectutils_1.ObjectUtils.resolveFieldData(this.value[i], globalFilterField), this.filters['global'].value);
  899. if (globalMatch) {
  900. break;
  901. }
  902. }
  903. }
  904. var matches = void 0;
  905. if (this.filters['global']) {
  906. matches = localFiltered ? (localFiltered && localMatch && globalMatch) : globalMatch;
  907. }
  908. else {
  909. matches = localFiltered && localMatch;
  910. }
  911. if (matches) {
  912. this.filteredValue.push(this.value[i]);
  913. }
  914. }
  915. if (this.filteredValue.length === this.value.length) {
  916. this.filteredValue = null;
  917. }
  918. if (this.paginator) {
  919. this.totalRecords = this.filteredValue ? this.filteredValue.length : this.value ? this.value.length : 0;
  920. }
  921. }
  922. }
  923. this.onFilter.emit({
  924. filters: this.filters,
  925. filteredValue: this.filteredValue || this.value
  926. });
  927. this.tableService.onValueChange(this.value);
  928. if (this.isStateful() && !this.restoringFilter) {
  929. this.saveState();
  930. }
  931. if (this.restoringFilter) {
  932. this.restoringFilter = false;
  933. }
  934. this.cd.detectChanges();
  935. };
  936. Table.prototype.hasFilter = function () {
  937. var empty = true;
  938. for (var prop in this.filters) {
  939. if (this.filters.hasOwnProperty(prop)) {
  940. empty = false;
  941. break;
  942. }
  943. }
  944. return !empty;
  945. };
  946. Table.prototype.createLazyLoadMetadata = function () {
  947. return {
  948. first: this.first,
  949. rows: this.virtualScroll ? this.rows * 2 : this.rows,
  950. sortField: this.sortField,
  951. sortOrder: this.sortOrder,
  952. filters: this.filters,
  953. globalFilter: this.filters && this.filters['global'] ? this.filters['global'].value : null,
  954. multiSortMeta: this.multiSortMeta
  955. };
  956. };
  957. Table.prototype.reset = function () {
  958. this._sortField = null;
  959. this._sortOrder = this.defaultSortOrder;
  960. this._multiSortMeta = null;
  961. this.tableService.onSort(null);
  962. this.filteredValue = null;
  963. this.filters = {};
  964. this.first = 0;
  965. this.firstChange.emit(this.first);
  966. if (this.lazy) {
  967. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  968. }
  969. else {
  970. this.totalRecords = (this._value ? this._value.length : 0);
  971. }
  972. };
  973. Table.prototype.exportCSV = function (options) {
  974. var _this = this;
  975. var data = this.filteredValue || this.value;
  976. var csv = '';
  977. if (options && options.selectionOnly) {
  978. data = this.selection || [];
  979. }
  980. //headers
  981. for (var i = 0; i < this.columns.length; i++) {
  982. var column = this.columns[i];
  983. if (column.exportable !== false && column.field) {
  984. csv += '"' + (column.header || column.field) + '"';
  985. if (i < (this.columns.length - 1)) {
  986. csv += this.csvSeparator;
  987. }
  988. }
  989. }
  990. //body
  991. data.forEach(function (record, i) {
  992. csv += '\n';
  993. for (var i_1 = 0; i_1 < _this.columns.length; i_1++) {
  994. var column = _this.columns[i_1];
  995. if (column.exportable !== false && column.field) {
  996. var cellData = objectutils_1.ObjectUtils.resolveFieldData(record, column.field);
  997. if (cellData != null) {
  998. if (_this.exportFunction) {
  999. cellData = _this.exportFunction({
  1000. data: cellData,
  1001. field: column.field
  1002. });
  1003. }
  1004. else
  1005. cellData = String(cellData).replace(/"/g, '""');
  1006. }
  1007. else
  1008. cellData = '';
  1009. csv += '"' + cellData + '"';
  1010. if (i_1 < (_this.columns.length - 1)) {
  1011. csv += _this.csvSeparator;
  1012. }
  1013. }
  1014. }
  1015. });
  1016. var blob = new Blob([csv], {
  1017. type: 'text/csv;charset=utf-8;'
  1018. });
  1019. if (window.navigator.msSaveOrOpenBlob) {
  1020. navigator.msSaveOrOpenBlob(blob, this.exportFilename + '.csv');
  1021. }
  1022. else {
  1023. var link = document.createElement("a");
  1024. link.style.display = 'none';
  1025. document.body.appendChild(link);
  1026. if (link.download !== undefined) {
  1027. link.setAttribute('href', URL.createObjectURL(blob));
  1028. link.setAttribute('download', this.exportFilename + '.csv');
  1029. link.click();
  1030. }
  1031. else {
  1032. csv = 'data:text/csv;charset=utf-8,' + csv;
  1033. window.open(encodeURI(csv));
  1034. }
  1035. document.body.removeChild(link);
  1036. }
  1037. };
  1038. Table.prototype.updateEditingCell = function (cell, data, field) {
  1039. this.editingCell = cell;
  1040. this.editingCellData = data;
  1041. this.editingCellField = field;
  1042. this.bindDocumentEditListener();
  1043. };
  1044. Table.prototype.isEditingCellValid = function () {
  1045. return (this.editingCell && domhandler_1.DomHandler.find(this.editingCell, '.ng-invalid.ng-dirty').length === 0);
  1046. };
  1047. Table.prototype.bindDocumentEditListener = function () {
  1048. var _this = this;
  1049. if (!this.documentEditListener) {
  1050. this.documentEditListener = function (event) {
  1051. if (_this.editingCell && !_this.editingCellClick && _this.isEditingCellValid()) {
  1052. domhandler_1.DomHandler.removeClass(_this.editingCell, 'ui-editing-cell');
  1053. _this.editingCell = null;
  1054. _this.onEditComplete.emit({ field: _this.editingCellField, data: _this.editingCellData, originalEvent: event });
  1055. _this.editingCellField = null;
  1056. _this.editingCellData = null;
  1057. _this.unbindDocumentEditListener();
  1058. }
  1059. _this.editingCellClick = false;
  1060. };
  1061. document.addEventListener('click', this.documentEditListener);
  1062. }
  1063. };
  1064. Table.prototype.unbindDocumentEditListener = function () {
  1065. if (this.documentEditListener) {
  1066. document.removeEventListener('click', this.documentEditListener);
  1067. this.documentEditListener = null;
  1068. }
  1069. };
  1070. Table.prototype.initRowEdit = function (rowData) {
  1071. var dataKeyValue = String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey));
  1072. this.editingRowKeys[dataKeyValue] = true;
  1073. };
  1074. Table.prototype.saveRowEdit = function (rowData, rowElement) {
  1075. if (domhandler_1.DomHandler.find(rowElement, '.ng-invalid.ng-dirty').length === 0) {
  1076. var dataKeyValue = String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey));
  1077. delete this.editingRowKeys[dataKeyValue];
  1078. }
  1079. };
  1080. Table.prototype.cancelRowEdit = function (rowData) {
  1081. var dataKeyValue = String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey));
  1082. delete this.editingRowKeys[dataKeyValue];
  1083. };
  1084. Table.prototype.toggleRow = function (rowData, event) {
  1085. if (!this.dataKey) {
  1086. throw new Error('dataKey must be defined to use row expansion');
  1087. }
  1088. var dataKeyValue = String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey));
  1089. if (this.expandedRowKeys[dataKeyValue] != null) {
  1090. delete this.expandedRowKeys[dataKeyValue];
  1091. this.onRowCollapse.emit({
  1092. originalEvent: event,
  1093. data: rowData
  1094. });
  1095. }
  1096. else {
  1097. if (this.rowExpandMode === 'single') {
  1098. this.expandedRowKeys = {};
  1099. }
  1100. this.expandedRowKeys[dataKeyValue] = true;
  1101. this.onRowExpand.emit({
  1102. originalEvent: event,
  1103. data: rowData
  1104. });
  1105. }
  1106. if (event) {
  1107. event.preventDefault();
  1108. }
  1109. if (this.isStateful()) {
  1110. this.saveState();
  1111. }
  1112. };
  1113. Table.prototype.isRowExpanded = function (rowData) {
  1114. return this.expandedRowKeys[String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey))] === true;
  1115. };
  1116. Table.prototype.isRowEditing = function (rowData) {
  1117. return this.editingRowKeys[String(objectutils_1.ObjectUtils.resolveFieldData(rowData, this.dataKey))] === true;
  1118. };
  1119. Table.prototype.isSingleSelectionMode = function () {
  1120. return this.selectionMode === 'single';
  1121. };
  1122. Table.prototype.isMultipleSelectionMode = function () {
  1123. return this.selectionMode === 'multiple';
  1124. };
  1125. Table.prototype.onColumnResizeBegin = function (event) {
  1126. var containerLeft = domhandler_1.DomHandler.getOffset(this.containerViewChild.nativeElement).left;
  1127. this.lastResizerHelperX = (event.pageX - containerLeft + this.containerViewChild.nativeElement.scrollLeft);
  1128. event.preventDefault();
  1129. };
  1130. Table.prototype.onColumnResize = function (event) {
  1131. var containerLeft = domhandler_1.DomHandler.getOffset(this.containerViewChild.nativeElement).left;
  1132. domhandler_1.DomHandler.addClass(this.containerViewChild.nativeElement, 'ui-unselectable-text');
  1133. this.resizeHelperViewChild.nativeElement.style.height = this.containerViewChild.nativeElement.offsetHeight + 'px';
  1134. this.resizeHelperViewChild.nativeElement.style.top = 0 + 'px';
  1135. this.resizeHelperViewChild.nativeElement.style.left = (event.pageX - containerLeft + this.containerViewChild.nativeElement.scrollLeft) + 'px';
  1136. this.resizeHelperViewChild.nativeElement.style.display = 'block';
  1137. };
  1138. Table.prototype.onColumnResizeEnd = function (event, column) {
  1139. var delta = this.resizeHelperViewChild.nativeElement.offsetLeft - this.lastResizerHelperX;
  1140. var columnWidth = column.offsetWidth;
  1141. var minWidth = parseInt(column.style.minWidth || 15);
  1142. if (columnWidth + delta < minWidth) {
  1143. delta = minWidth - columnWidth;
  1144. }
  1145. var newColumnWidth = columnWidth + delta;
  1146. if (newColumnWidth >= minWidth) {
  1147. if (this.columnResizeMode === 'fit') {
  1148. var nextColumn = column.nextElementSibling;
  1149. while (!nextColumn.offsetParent) {
  1150. nextColumn = nextColumn.nextElementSibling;
  1151. }
  1152. if (nextColumn) {
  1153. var nextColumnWidth = nextColumn.offsetWidth - delta;
  1154. var nextColumnMinWidth = nextColumn.style.minWidth || 15;
  1155. if (newColumnWidth > 15 && nextColumnWidth > parseInt(nextColumnMinWidth)) {
  1156. if (this.scrollable) {
  1157. var scrollableView = this.findParentScrollableView(column);
  1158. var scrollableBodyTable = domhandler_1.DomHandler.findSingle(scrollableView, 'table.ui-table-scrollable-body-table');
  1159. var scrollableHeaderTable = domhandler_1.DomHandler.findSingle(scrollableView, 'table.ui-table-scrollable-header-table');
  1160. var scrollableFooterTable = domhandler_1.DomHandler.findSingle(scrollableView, 'table.ui-table-scrollable-footer-table');
  1161. var resizeColumnIndex = domhandler_1.DomHandler.index(column);
  1162. this.resizeColGroup(scrollableHeaderTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
  1163. this.resizeColGroup(scrollableBodyTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
  1164. this.resizeColGroup(scrollableFooterTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
  1165. }
  1166. else {
  1167. column.style.width = newColumnWidth + 'px';
  1168. if (nextColumn) {
  1169. nextColumn.style.width = nextColumnWidth + 'px';
  1170. }
  1171. }
  1172. }
  1173. }
  1174. }
  1175. else if (this.columnResizeMode === 'expand') {
  1176. if (newColumnWidth > minWidth) {
  1177. if (this.scrollable) {
  1178. this.setScrollableItemsWidthOnExpandResize(column, newColumnWidth, delta);
  1179. }
  1180. else {
  1181. this.tableViewChild.nativeElement.style.width = this.tableViewChild.nativeElement.offsetWidth + delta + 'px';
  1182. column.style.width = newColumnWidth + 'px';
  1183. var containerWidth = this.tableViewChild.nativeElement.style.width;
  1184. this.containerViewChild.nativeElement.style.width = containerWidth + 'px';
  1185. }
  1186. }
  1187. }
  1188. this.onColResize.emit({
  1189. element: column,
  1190. delta: delta
  1191. });
  1192. if (this.isStateful()) {
  1193. this.saveState();
  1194. }
  1195. }
  1196. this.resizeHelperViewChild.nativeElement.style.display = 'none';
  1197. domhandler_1.DomHandler.removeClass(this.containerViewChild.nativeElement, 'ui-unselectable-text');
  1198. };
  1199. Table.prototype.setScrollableItemsWidthOnExpandResize = function (column, newColumnWidth, delta) {
  1200. var scrollableView = column ? this.findParentScrollableView(column) : this.containerViewChild.nativeElement;
  1201. var scrollableBody = domhandler_1.DomHandler.findSingle(scrollableView, '.ui-table-scrollable-body');
  1202. var scrollableHeader = domhandler_1.DomHandler.findSingle(scrollableView, '.ui-table-scrollable-header');
  1203. var scrollableFooter = domhandler_1.DomHandler.findSingle(scrollableView, '.ui-table-scrollable-footer');
  1204. var scrollableBodyTable = domhandler_1.DomHandler.findSingle(scrollableBody, 'table.ui-table-scrollable-body-table');
  1205. var scrollableHeaderTable = domhandler_1.DomHandler.findSingle(scrollableHeader, 'table.ui-table-scrollable-header-table');
  1206. var scrollableFooterTable = domhandler_1.DomHandler.findSingle(scrollableFooter, 'table.ui-table-scrollable-footer-table');
  1207. var scrollableBodyTableWidth = column ? scrollableBodyTable.offsetWidth + delta : newColumnWidth;
  1208. var scrollableHeaderTableWidth = column ? scrollableHeaderTable.offsetWidth + delta : newColumnWidth;
  1209. var isContainerInViewport = this.containerViewChild.nativeElement.offsetWidth >= scrollableBodyTableWidth;
  1210. var setWidth = function (container, table, width, isContainerInViewport) {
  1211. if (container && table) {
  1212. container.style.width = isContainerInViewport ? width + domhandler_1.DomHandler.calculateScrollbarWidth(scrollableBody) + 'px' : 'auto';
  1213. table.style.width = width + 'px';
  1214. }
  1215. };
  1216. setWidth(scrollableBody, scrollableBodyTable, scrollableBodyTableWidth, isContainerInViewport);
  1217. setWidth(scrollableHeader, scrollableHeaderTable, scrollableHeaderTableWidth, isContainerInViewport);
  1218. setWidth(scrollableFooter, scrollableFooterTable, scrollableHeaderTableWidth, isContainerInViewport);
  1219. if (column) {
  1220. var resizeColumnIndex = domhandler_1.DomHandler.index(column);
  1221. this.resizeColGroup(scrollableHeaderTable, resizeColumnIndex, newColumnWidth, null);
  1222. this.resizeColGroup(scrollableBodyTable, resizeColumnIndex, newColumnWidth, null);
  1223. this.resizeColGroup(scrollableFooterTable, resizeColumnIndex, newColumnWidth, null);
  1224. }
  1225. };
  1226. Table.prototype.findParentScrollableView = function (column) {
  1227. if (column) {
  1228. var parent_1 = column.parentElement;
  1229. while (parent_1 && !domhandler_1.DomHandler.hasClass(parent_1, 'ui-table-scrollable-view')) {
  1230. parent_1 = parent_1.parentElement;
  1231. }
  1232. return parent_1;
  1233. }
  1234. else {
  1235. return null;
  1236. }
  1237. };
  1238. Table.prototype.resizeColGroup = function (table, resizeColumnIndex, newColumnWidth, nextColumnWidth) {
  1239. if (table) {
  1240. var colGroup = table.children[0].nodeName === 'COLGROUP' ? table.children[0] : null;
  1241. if (colGroup) {
  1242. var col = colGroup.children[resizeColumnIndex];
  1243. var nextCol = col.nextElementSibling;
  1244. col.style.width = newColumnWidth + 'px';
  1245. if (nextCol && nextColumnWidth) {
  1246. nextCol.style.width = nextColumnWidth + 'px';
  1247. }
  1248. }
  1249. else {
  1250. throw "Scrollable tables require a colgroup to support resizable columns";
  1251. }
  1252. }
  1253. };
  1254. Table.prototype.onColumnDragStart = function (event, columnElement) {
  1255. this.reorderIconWidth = domhandler_1.DomHandler.getHiddenElementOuterWidth(this.reorderIndicatorUpViewChild.nativeElement);
  1256. this.reorderIconHeight = domhandler_1.DomHandler.getHiddenElementOuterHeight(this.reorderIndicatorDownViewChild.nativeElement);
  1257. this.draggedColumn = columnElement;
  1258. event.dataTransfer.setData('text', 'b'); // For firefox
  1259. };
  1260. Table.prototype.onColumnDragEnter = function (event, dropHeader) {
  1261. if (this.reorderableColumns && this.draggedColumn && dropHeader) {
  1262. event.preventDefault();
  1263. var containerOffset = domhandler_1.DomHandler.getOffset(this.containerViewChild.nativeElement);
  1264. var dropHeaderOffset = domhandler_1.DomHandler.getOffset(dropHeader);
  1265. if (this.draggedColumn != dropHeader) {
  1266. var dragIndex = domhandler_1.DomHandler.indexWithinGroup(this.draggedColumn, 'preorderablecolumn');
  1267. var dropIndex = domhandler_1.DomHandler.indexWithinGroup(dropHeader, 'preorderablecolumn');
  1268. var targetLeft = dropHeaderOffset.left - containerOffset.left;
  1269. var targetTop = containerOffset.top - dropHeaderOffset.top;
  1270. var columnCenter = dropHeaderOffset.left + dropHeader.offsetWidth / 2;
  1271. this.reorderIndicatorUpViewChild.nativeElement.style.top = dropHeaderOffset.top - containerOffset.top - (this.reorderIconHeight - 1) + 'px';
  1272. this.reorderIndicatorDownViewChild.nativeElement.style.top = dropHeaderOffset.top - containerOffset.top + dropHeader.offsetHeight + 'px';
  1273. if (event.pageX > columnCenter) {
  1274. this.reorderIndicatorUpViewChild.nativeElement.style.left = (targetLeft + dropHeader.offsetWidth - Math.ceil(this.reorderIconWidth / 2)) + 'px';
  1275. this.reorderIndicatorDownViewChild.nativeElement.style.left = (targetLeft + dropHeader.offsetWidth - Math.ceil(this.reorderIconWidth / 2)) + 'px';
  1276. this.dropPosition = 1;
  1277. }
  1278. else {
  1279. this.reorderIndicatorUpViewChild.nativeElement.style.left = (targetLeft - Math.ceil(this.reorderIconWidth / 2)) + 'px';
  1280. this.reorderIndicatorDownViewChild.nativeElement.style.left = (targetLeft - Math.ceil(this.reorderIconWidth / 2)) + 'px';
  1281. this.dropPosition = -1;
  1282. }
  1283. if ((dropIndex - dragIndex === 1 && this.dropPosition === -1) || (dropIndex - dragIndex === -1 && this.dropPosition === 1)) {
  1284. this.reorderIndicatorUpViewChild.nativeElement.style.display = 'none';
  1285. this.reorderIndicatorDownViewChild.nativeElement.style.display = 'none';
  1286. }
  1287. else {
  1288. this.reorderIndicatorUpViewChild.nativeElement.style.display = 'block';
  1289. this.reorderIndicatorDownViewChild.nativeElement.style.display = 'block';
  1290. }
  1291. }
  1292. else {
  1293. event.dataTransfer.dropEffect = 'none';
  1294. }
  1295. }
  1296. };
  1297. Table.prototype.onColumnDragLeave = function (event) {
  1298. if (this.reorderableColumns && this.draggedColumn) {
  1299. event.preventDefault();
  1300. this.reorderIndicatorUpViewChild.nativeElement.style.display = 'none';
  1301. this.reorderIndicatorDownViewChild.nativeElement.style.display = 'none';
  1302. }
  1303. };
  1304. Table.prototype.onColumnDrop = function (event, dropColumn) {
  1305. event.preventDefault();
  1306. if (this.draggedColumn) {
  1307. var dragIndex = domhandler_1.DomHandler.indexWithinGroup(this.draggedColumn, 'preorderablecolumn');
  1308. var dropIndex = domhandler_1.DomHandler.indexWithinGroup(dropColumn, 'preorderablecolumn');
  1309. var allowDrop = (dragIndex != dropIndex);
  1310. if (allowDrop && ((dropIndex - dragIndex == 1 && this.dropPosition === -1) || (dragIndex - dropIndex == 1 && this.dropPosition === 1))) {
  1311. allowDrop = false;
  1312. }
  1313. if (allowDrop && ((dropIndex < dragIndex && this.dropPosition === 1))) {
  1314. dropIndex = dropIndex + 1;
  1315. }
  1316. if (allowDrop && ((dropIndex > dragIndex && this.dropPosition === -1))) {
  1317. dropIndex = dropIndex - 1;
  1318. }
  1319. if (allowDrop) {
  1320. objectutils_1.ObjectUtils.reorderArray(this.columns, dragIndex, dropIndex);
  1321. this.onColReorder.emit({
  1322. dragIndex: dragIndex,
  1323. dropIndex: dropIndex,
  1324. columns: this.columns
  1325. });
  1326. if (this.isStateful()) {
  1327. this.saveState();
  1328. }
  1329. }
  1330. this.reorderIndicatorUpViewChild.nativeElement.style.display = 'none';
  1331. this.reorderIndicatorDownViewChild.nativeElement.style.display = 'none';
  1332. this.draggedColumn.draggable = false;
  1333. this.draggedColumn = null;
  1334. this.dropPosition = null;
  1335. }
  1336. };
  1337. Table.prototype.onRowDragStart = function (event, index) {
  1338. this.rowDragging = true;
  1339. this.draggedRowIndex = index;
  1340. event.dataTransfer.setData('text', 'b'); // For firefox
  1341. };
  1342. Table.prototype.onRowDragOver = function (event, index, rowElement) {
  1343. if (this.rowDragging && this.draggedRowIndex !== index) {
  1344. var rowY = domhandler_1.DomHandler.getOffset(rowElement).top + domhandler_1.DomHandler.getWindowScrollTop();
  1345. var pageY = event.pageY;
  1346. var rowMidY = rowY + domhandler_1.DomHandler.getOuterHeight(rowElement) / 2;
  1347. var prevRowElement = rowElement.previousElementSibling;
  1348. if (pageY < rowMidY) {
  1349. domhandler_1.DomHandler.removeClass(rowElement, 'ui-table-dragpoint-bottom');
  1350. this.droppedRowIndex = index;
  1351. if (prevRowElement)
  1352. domhandler_1.DomHandler.addClass(prevRowElement, 'ui-table-dragpoint-bottom');
  1353. else
  1354. domhandler_1.DomHandler.addClass(rowElement, 'ui-table-dragpoint-top');
  1355. }
  1356. else {
  1357. if (prevRowElement)
  1358. domhandler_1.DomHandler.removeClass(prevRowElement, 'ui-table-dragpoint-bottom');
  1359. else
  1360. domhandler_1.DomHandler.addClass(rowElement, 'ui-table-dragpoint-top');
  1361. this.droppedRowIndex = index + 1;
  1362. domhandler_1.DomHandler.addClass(rowElement, 'ui-table-dragpoint-bottom');
  1363. }
  1364. }
  1365. };
  1366. Table.prototype.onRowDragLeave = function (event, rowElement) {
  1367. var prevRowElement = rowElement.previousElementSibling;
  1368. if (prevRowElement) {
  1369. domhandler_1.DomHandler.removeClass(prevRowElement, 'ui-table-dragpoint-bottom');
  1370. }
  1371. domhandler_1.DomHandler.removeClass(rowElement, 'ui-table-dragpoint-bottom');
  1372. domhandler_1.DomHandler.removeClass(rowElement, 'ui-table-dragpoint-top');
  1373. };
  1374. Table.prototype.onRowDragEnd = function (event) {
  1375. this.rowDragging = false;
  1376. this.draggedRowIndex = null;
  1377. this.droppedRowIndex = null;
  1378. };
  1379. Table.prototype.onRowDrop = function (event, rowElement) {
  1380. if (this.droppedRowIndex != null) {
  1381. var dropIndex = (this.draggedRowIndex > this.droppedRowIndex) ? this.droppedRowIndex : (this.droppedRowIndex === 0) ? 0 : this.droppedRowIndex - 1;
  1382. objectutils_1.ObjectUtils.reorderArray(this.value, this.draggedRowIndex, dropIndex);
  1383. this.onRowReorder.emit({
  1384. dragIndex: this.draggedRowIndex,
  1385. dropIndex: dropIndex
  1386. });
  1387. }
  1388. //cleanup
  1389. this.onRowDragLeave(event, rowElement);
  1390. this.onRowDragEnd(event);
  1391. };
  1392. Table.prototype.handleVirtualScroll = function (event) {
  1393. var _this = this;
  1394. this.first = (event.page - 1) * this.rows;
  1395. this.firstChange.emit(this.first);
  1396. this.virtualScrollCallback = event.callback;
  1397. this.zone.run(function () {
  1398. if (_this.virtualScrollTimer) {
  1399. clearTimeout(_this.virtualScrollTimer);
  1400. }
  1401. _this.virtualScrollTimer = setTimeout(function () {
  1402. _this.onLazyLoad.emit(_this.createLazyLoadMetadata());
  1403. }, _this.virtualScrollDelay);
  1404. });
  1405. };
  1406. Table.prototype.isEmpty = function () {
  1407. var data = this.filteredValue || this.value;
  1408. return data == null || data.length == 0;
  1409. };
  1410. Table.prototype.getBlockableElement = function () {
  1411. return this.el.nativeElement.children[0];
  1412. };
  1413. Table.prototype.getStorage = function () {
  1414. switch (this.stateStorage) {
  1415. case 'local':
  1416. return window.localStorage;
  1417. case 'session':
  1418. return window.sessionStorage;
  1419. default:
  1420. throw new Error(this.stateStorage + ' is not a valid value for the state storage, supported values are "local" and "session".');
  1421. }
  1422. };
  1423. Table.prototype.isStateful = function () {
  1424. return this.stateKey != null;
  1425. };
  1426. Table.prototype.saveState = function () {
  1427. var storage = this.getStorage();
  1428. var state = {};
  1429. if (this.paginator) {
  1430. state.first = this.first;
  1431. state.rows = this.rows;
  1432. }
  1433. if (this.sortField) {
  1434. state.sortField = this.sortField;
  1435. state.sortOrder = this.sortOrder;
  1436. }
  1437. if (this.multiSortMeta) {
  1438. state.multiSortMeta = this.multiSortMeta;
  1439. }
  1440. if (this.hasFilter()) {
  1441. state.filters = this.filters;
  1442. }
  1443. if (this.resizableColumns) {
  1444. this.saveColumnWidths(state);
  1445. }
  1446. if (this.reorderableColumns) {
  1447. this.saveColumnOrder(state);
  1448. }
  1449. if (this.selection) {
  1450. state.selection = this.selection;
  1451. }
  1452. if (Object.keys(this.expandedRowKeys).length) {
  1453. state.expandedRowKeys = this.expandedRowKeys;
  1454. }
  1455. if (Object.keys(state).length) {
  1456. storage.setItem(this.stateKey, JSON.stringify(state));
  1457. }
  1458. this.onStateSave.emit(state);
  1459. };
  1460. Table.prototype.clearState = function () {
  1461. var storage = this.getStorage();
  1462. if (this.stateKey) {
  1463. storage.removeItem(this.stateKey);
  1464. }
  1465. };
  1466. Table.prototype.restoreState = function () {
  1467. var storage = this.getStorage();
  1468. var stateString = storage.getItem(this.stateKey);
  1469. if (stateString) {
  1470. var state = JSON.parse(stateString);
  1471. if (this.paginator) {
  1472. this.first = state.first;
  1473. this.rows = state.rows;
  1474. this.firstChange.emit(this.first);
  1475. this.rowsChange.emit(this.rows);
  1476. }
  1477. if (state.sortField) {
  1478. this.restoringSort = true;
  1479. this._sortField = state.sortField;
  1480. this._sortOrder = state.sortOrder;
  1481. }
  1482. if (state.multiSortMeta) {
  1483. this.restoringSort = true;
  1484. this._multiSortMeta = state.multiSortMeta;
  1485. }
  1486. if (state.filters) {
  1487. this.restoringFilter = true;
  1488. this.filters = state.filters;
  1489. }
  1490. if (this.resizableColumns) {
  1491. this.columnWidthsState = state.columnWidths;
  1492. this.tableWidthState = state.tableWidth;
  1493. }
  1494. if (state.expandedRowKeys) {
  1495. this.expandedRowKeys = state.expandedRowKeys;
  1496. }
  1497. if (state.selection) {
  1498. this.selection = state.selection;
  1499. }
  1500. this.stateRestored = true;
  1501. this.onStateRestore.emit(state);
  1502. }
  1503. };
  1504. Table.prototype.saveColumnWidths = function (state) {
  1505. var widths = [];
  1506. var headers = domhandler_1.DomHandler.find(this.containerViewChild.nativeElement, '.ui-table-thead > tr:first-child > th');
  1507. headers.map(function (header) { return widths.push(domhandler_1.DomHandler.getOuterWidth(header)); });
  1508. state.columnWidths = widths.join(',');
  1509. if (this.columnResizeMode === 'expand') {
  1510. state.tableWidth = this.scrollable ? domhandler_1.DomHandler.findSingle(this.containerViewChild.nativeElement, '.ui-table-scrollable-header-table').style.width :
  1511. domhandler_1.DomHandler.getOuterWidth(this.tableViewChild.nativeElement) + 'px';
  1512. }
  1513. };
  1514. Table.prototype.restoreColumnWidths = function () {
  1515. if (this.columnWidthsState) {
  1516. var widths_1 = this.columnWidthsState.split(',');
  1517. if (this.columnResizeMode === 'expand' && this.tableWidthState) {
  1518. if (this.scrollable) {
  1519. this.setScrollableItemsWidthOnExpandResize(null, this.tableWidthState, 0);
  1520. }
  1521. else {
  1522. this.tableViewChild.nativeElement.style.width = this.tableWidthState;
  1523. this.containerViewChild.nativeElement.style.width = this.tableWidthState;
  1524. }
  1525. }
  1526. if (this.scrollable) {
  1527. var headerCols = domhandler_1.DomHandler.find(this.containerViewChild.nativeElement, '.ui-table-scrollable-header-table > colgroup > col');
  1528. var bodyCols = domhandler_1.DomHandler.find(this.containerViewChild.nativeElement, '.ui-table-scrollable-body-table > colgroup > col');
  1529. headerCols.map(function (col, index) { return col.style.width = widths_1[index] + 'px'; });
  1530. bodyCols.map(function (col, index) { return col.style.width = widths_1[index] + 'px'; });
  1531. }
  1532. else {
  1533. var headers = domhandler_1.DomHandler.find(this.tableViewChild.nativeElement, '.ui-table-thead > tr:first-child > th');
  1534. headers.map(function (header, index) { return header.style.width = widths_1[index] + 'px'; });
  1535. }
  1536. }
  1537. };
  1538. Table.prototype.saveColumnOrder = function (state) {
  1539. if (this.columns) {
  1540. var columnOrder_1 = [];
  1541. this.columns.map(function (column) {
  1542. columnOrder_1.push(column.field || column.key);
  1543. });
  1544. state.columnOrder = columnOrder_1;
  1545. }
  1546. };
  1547. Table.prototype.restoreColumnOrder = function () {
  1548. var _this = this;
  1549. var storage = this.getStorage();
  1550. var stateString = storage.getItem(this.stateKey);
  1551. if (stateString) {
  1552. var state = JSON.parse(stateString);
  1553. var columnOrder = state.columnOrder;
  1554. if (columnOrder) {
  1555. var reorderedColumns_1 = [];
  1556. columnOrder.map(function (key) { return reorderedColumns_1.push(_this.findColumnByKey(key)); });
  1557. this.columnOrderStateRestored = true;
  1558. this.columns = reorderedColumns_1;
  1559. }
  1560. }
  1561. };
  1562. Table.prototype.findColumnByKey = function (key) {
  1563. if (this.columns) {
  1564. for (var _i = 0, _a = this.columns; _i < _a.length; _i++) {
  1565. var col = _a[_i];
  1566. if (col.key === key || col.field === key)
  1567. return col;
  1568. else
  1569. continue;
  1570. }
  1571. }
  1572. else {
  1573. return null;
  1574. }
  1575. };
  1576. Table.prototype.ngOnDestroy = function () {
  1577. this.unbindDocumentEditListener();
  1578. this.editingCell = null;
  1579. this.initialized = null;
  1580. };
  1581. __decorate([
  1582. core_1.Input(),
  1583. __metadata("design:type", Array)
  1584. ], Table.prototype, "frozenColumns", void 0);
  1585. __decorate([
  1586. core_1.Input(),
  1587. __metadata("design:type", Array)
  1588. ], Table.prototype, "frozenValue", void 0);
  1589. __decorate([
  1590. core_1.Input(),
  1591. __metadata("design:type", Object)
  1592. ], Table.prototype, "style", void 0);
  1593. __decorate([
  1594. core_1.Input(),
  1595. __metadata("design:type", String)
  1596. ], Table.prototype, "styleClass", void 0);
  1597. __decorate([
  1598. core_1.Input(),
  1599. __metadata("design:type", Object)
  1600. ], Table.prototype, "tableStyle", void 0);
  1601. __decorate([
  1602. core_1.Input(),
  1603. __metadata("design:type", String)
  1604. ], Table.prototype, "tableStyleClass", void 0);
  1605. __decorate([
  1606. core_1.Input(),
  1607. __metadata("design:type", Boolean)
  1608. ], Table.prototype, "paginator", void 0);
  1609. __decorate([
  1610. core_1.Input(),
  1611. __metadata("design:type", Number)
  1612. ], Table.prototype, "pageLinks", void 0);
  1613. __decorate([
  1614. core_1.Input(),
  1615. __metadata("design:type", Array)
  1616. ], Table.prototype, "rowsPerPageOptions", void 0);
  1617. __decorate([
  1618. core_1.Input(),
  1619. __metadata("design:type", Boolean)
  1620. ], Table.prototype, "alwaysShowPaginator", void 0);
  1621. __decorate([
  1622. core_1.Input(),
  1623. __metadata("design:type", String)
  1624. ], Table.prototype, "paginatorPosition", void 0);
  1625. __decorate([
  1626. core_1.Input(),
  1627. __metadata("design:type", Object)
  1628. ], Table.prototype, "paginatorDropdownAppendTo", void 0);
  1629. __decorate([
  1630. core_1.Input(),
  1631. __metadata("design:type", String)
  1632. ], Table.prototype, "paginatorDropdownScrollHeight", void 0);
  1633. __decorate([
  1634. core_1.Input(),
  1635. __metadata("design:type", String)
  1636. ], Table.prototype, "currentPageReportTemplate", void 0);
  1637. __decorate([
  1638. core_1.Input(),
  1639. __metadata("design:type", Boolean)
  1640. ], Table.prototype, "showCurrentPageReport", void 0);
  1641. __decorate([
  1642. core_1.Input(),
  1643. __metadata("design:type", Number)
  1644. ], Table.prototype, "defaultSortOrder", void 0);
  1645. __decorate([
  1646. core_1.Input(),
  1647. __metadata("design:type", String)
  1648. ], Table.prototype, "sortMode", void 0);
  1649. __decorate([
  1650. core_1.Input(),
  1651. __metadata("design:type", Boolean)
  1652. ], Table.prototype, "resetPageOnSort", void 0);
  1653. __decorate([
  1654. core_1.Input(),
  1655. __metadata("design:type", String)
  1656. ], Table.prototype, "selectionMode", void 0);
  1657. __decorate([
  1658. core_1.Output(),
  1659. __metadata("design:type", core_1.EventEmitter)
  1660. ], Table.prototype, "selectionChange", void 0);
  1661. __decorate([
  1662. core_1.Input(),
  1663. __metadata("design:type", Object)
  1664. ], Table.prototype, "contextMenuSelection", void 0);
  1665. __decorate([
  1666. core_1.Output(),
  1667. __metadata("design:type", core_1.EventEmitter)
  1668. ], Table.prototype, "contextMenuSelectionChange", void 0);
  1669. __decorate([
  1670. core_1.Input(),
  1671. __metadata("design:type", String)
  1672. ], Table.prototype, "contextMenuSelectionMode", void 0);
  1673. __decorate([
  1674. core_1.Input(),
  1675. __metadata("design:type", String)
  1676. ], Table.prototype, "dataKey", void 0);
  1677. __decorate([
  1678. core_1.Input(),
  1679. __metadata("design:type", Boolean)
  1680. ], Table.prototype, "metaKeySelection", void 0);
  1681. __decorate([
  1682. core_1.Input(),
  1683. __metadata("design:type", Function)
  1684. ], Table.prototype, "rowTrackBy", void 0);
  1685. __decorate([
  1686. core_1.Input(),
  1687. __metadata("design:type", Boolean)
  1688. ], Table.prototype, "lazy", void 0);
  1689. __decorate([
  1690. core_1.Input(),
  1691. __metadata("design:type", Boolean)
  1692. ], Table.prototype, "lazyLoadOnInit", void 0);
  1693. __decorate([
  1694. core_1.Input(),
  1695. __metadata("design:type", String)
  1696. ], Table.prototype, "compareSelectionBy", void 0);
  1697. __decorate([
  1698. core_1.Input(),
  1699. __metadata("design:type", String)
  1700. ], Table.prototype, "csvSeparator", void 0);
  1701. __decorate([
  1702. core_1.Input(),
  1703. __metadata("design:type", String)
  1704. ], Table.prototype, "exportFilename", void 0);
  1705. __decorate([
  1706. core_1.Input(),
  1707. __metadata("design:type", Object)
  1708. ], Table.prototype, "filters", void 0);
  1709. __decorate([
  1710. core_1.Input(),
  1711. __metadata("design:type", Array)
  1712. ], Table.prototype, "globalFilterFields", void 0);
  1713. __decorate([
  1714. core_1.Input(),
  1715. __metadata("design:type", Number)
  1716. ], Table.prototype, "filterDelay", void 0);
  1717. __decorate([
  1718. core_1.Input(),
  1719. __metadata("design:type", Object)
  1720. ], Table.prototype, "expandedRowKeys", void 0);
  1721. __decorate([
  1722. core_1.Input(),
  1723. __metadata("design:type", Object)
  1724. ], Table.prototype, "editingRowKeys", void 0);
  1725. __decorate([
  1726. core_1.Input(),
  1727. __metadata("design:type", String)
  1728. ], Table.prototype, "rowExpandMode", void 0);
  1729. __decorate([
  1730. core_1.Input(),
  1731. __metadata("design:type", Boolean)
  1732. ], Table.prototype, "scrollable", void 0);
  1733. __decorate([
  1734. core_1.Input(),
  1735. __metadata("design:type", String)
  1736. ], Table.prototype, "scrollHeight", void 0);
  1737. __decorate([
  1738. core_1.Input(),
  1739. __metadata("design:type", Boolean)
  1740. ], Table.prototype, "virtualScroll", void 0);
  1741. __decorate([
  1742. core_1.Input(),
  1743. __metadata("design:type", Number)
  1744. ], Table.prototype, "virtualScrollDelay", void 0);
  1745. __decorate([
  1746. core_1.Input(),
  1747. __metadata("design:type", Number)
  1748. ], Table.prototype, "virtualRowHeight", void 0);
  1749. __decorate([
  1750. core_1.Input(),
  1751. __metadata("design:type", String)
  1752. ], Table.prototype, "frozenWidth", void 0);
  1753. __decorate([
  1754. core_1.Input(),
  1755. __metadata("design:type", Boolean)
  1756. ], Table.prototype, "responsive", void 0);
  1757. __decorate([
  1758. core_1.Input(),
  1759. __metadata("design:type", Object)
  1760. ], Table.prototype, "contextMenu", void 0);
  1761. __decorate([
  1762. core_1.Input(),
  1763. __metadata("design:type", Boolean)
  1764. ], Table.prototype, "resizableColumns", void 0);
  1765. __decorate([
  1766. core_1.Input(),
  1767. __metadata("design:type", String)
  1768. ], Table.prototype, "columnResizeMode", void 0);
  1769. __decorate([
  1770. core_1.Input(),
  1771. __metadata("design:type", Boolean)
  1772. ], Table.prototype, "reorderableColumns", void 0);
  1773. __decorate([
  1774. core_1.Input(),
  1775. __metadata("design:type", Boolean)
  1776. ], Table.prototype, "loading", void 0);
  1777. __decorate([
  1778. core_1.Input(),
  1779. __metadata("design:type", String)
  1780. ], Table.prototype, "loadingIcon", void 0);
  1781. __decorate([
  1782. core_1.Input(),
  1783. __metadata("design:type", Boolean)
  1784. ], Table.prototype, "showLoader", void 0);
  1785. __decorate([
  1786. core_1.Input(),
  1787. __metadata("design:type", Boolean)
  1788. ], Table.prototype, "rowHover", void 0);
  1789. __decorate([
  1790. core_1.Input(),
  1791. __metadata("design:type", Boolean)
  1792. ], Table.prototype, "customSort", void 0);
  1793. __decorate([
  1794. core_1.Input(),
  1795. __metadata("design:type", Boolean)
  1796. ], Table.prototype, "autoLayout", void 0);
  1797. __decorate([
  1798. core_1.Input(),
  1799. __metadata("design:type", Object)
  1800. ], Table.prototype, "exportFunction", void 0);
  1801. __decorate([
  1802. core_1.Input(),
  1803. __metadata("design:type", String)
  1804. ], Table.prototype, "stateKey", void 0);
  1805. __decorate([
  1806. core_1.Input(),
  1807. __metadata("design:type", String)
  1808. ], Table.prototype, "stateStorage", void 0);
  1809. __decorate([
  1810. core_1.Input(),
  1811. __metadata("design:type", String)
  1812. ], Table.prototype, "editMode", void 0);
  1813. __decorate([
  1814. core_1.Output(),
  1815. __metadata("design:type", core_1.EventEmitter)
  1816. ], Table.prototype, "onRowSelect", void 0);
  1817. __decorate([
  1818. core_1.Output(),
  1819. __metadata("design:type", core_1.EventEmitter)
  1820. ], Table.prototype, "onRowUnselect", void 0);
  1821. __decorate([
  1822. core_1.Output(),
  1823. __metadata("design:type", core_1.EventEmitter)
  1824. ], Table.prototype, "onPage", void 0);
  1825. __decorate([
  1826. core_1.Output(),
  1827. __metadata("design:type", core_1.EventEmitter)
  1828. ], Table.prototype, "onSort", void 0);
  1829. __decorate([
  1830. core_1.Output(),
  1831. __metadata("design:type", core_1.EventEmitter)
  1832. ], Table.prototype, "onFilter", void 0);
  1833. __decorate([
  1834. core_1.Output(),
  1835. __metadata("design:type", core_1.EventEmitter)
  1836. ], Table.prototype, "onLazyLoad", void 0);
  1837. __decorate([
  1838. core_1.Output(),
  1839. __metadata("design:type", core_1.EventEmitter)
  1840. ], Table.prototype, "onRowExpand", void 0);
  1841. __decorate([
  1842. core_1.Output(),
  1843. __metadata("design:type", core_1.EventEmitter)
  1844. ], Table.prototype, "onRowCollapse", void 0);
  1845. __decorate([
  1846. core_1.Output(),
  1847. __metadata("design:type", core_1.EventEmitter)
  1848. ], Table.prototype, "onContextMenuSelect", void 0);
  1849. __decorate([
  1850. core_1.Output(),
  1851. __metadata("design:type", core_1.EventEmitter)
  1852. ], Table.prototype, "onColResize", void 0);
  1853. __decorate([
  1854. core_1.Output(),
  1855. __metadata("design:type", core_1.EventEmitter)
  1856. ], Table.prototype, "onColReorder", void 0);
  1857. __decorate([
  1858. core_1.Output(),
  1859. __metadata("design:type", core_1.EventEmitter)
  1860. ], Table.prototype, "onRowReorder", void 0);
  1861. __decorate([
  1862. core_1.Output(),
  1863. __metadata("design:type", core_1.EventEmitter)
  1864. ], Table.prototype, "onEditInit", void 0);
  1865. __decorate([
  1866. core_1.Output(),
  1867. __metadata("design:type", core_1.EventEmitter)
  1868. ], Table.prototype, "onEditComplete", void 0);
  1869. __decorate([
  1870. core_1.Output(),
  1871. __metadata("design:type", core_1.EventEmitter)
  1872. ], Table.prototype, "onEditCancel", void 0);
  1873. __decorate([
  1874. core_1.Output(),
  1875. __metadata("design:type", core_1.EventEmitter)
  1876. ], Table.prototype, "onHeaderCheckboxToggle", void 0);
  1877. __decorate([
  1878. core_1.Output(),
  1879. __metadata("design:type", core_1.EventEmitter)
  1880. ], Table.prototype, "sortFunction", void 0);
  1881. __decorate([
  1882. core_1.Output(),
  1883. __metadata("design:type", core_1.EventEmitter)
  1884. ], Table.prototype, "firstChange", void 0);
  1885. __decorate([
  1886. core_1.Output(),
  1887. __metadata("design:type", core_1.EventEmitter)
  1888. ], Table.prototype, "rowsChange", void 0);
  1889. __decorate([
  1890. core_1.Output(),
  1891. __metadata("design:type", core_1.EventEmitter)
  1892. ], Table.prototype, "onStateSave", void 0);
  1893. __decorate([
  1894. core_1.Output(),
  1895. __metadata("design:type", core_1.EventEmitter)
  1896. ], Table.prototype, "onStateRestore", void 0);
  1897. __decorate([
  1898. core_1.ViewChild('container', { static: false }),
  1899. __metadata("design:type", core_1.ElementRef)
  1900. ], Table.prototype, "containerViewChild", void 0);
  1901. __decorate([
  1902. core_1.ViewChild('resizeHelper', { static: false }),
  1903. __metadata("design:type", core_1.ElementRef)
  1904. ], Table.prototype, "resizeHelperViewChild", void 0);
  1905. __decorate([
  1906. core_1.ViewChild('reorderIndicatorUp', { static: false }),
  1907. __metadata("design:type", core_1.ElementRef)
  1908. ], Table.prototype, "reorderIndicatorUpViewChild", void 0);
  1909. __decorate([
  1910. core_1.ViewChild('reorderIndicatorDown', { static: false }),
  1911. __metadata("design:type", core_1.ElementRef)
  1912. ], Table.prototype, "reorderIndicatorDownViewChild", void 0);
  1913. __decorate([
  1914. core_1.ViewChild('table', { static: false }),
  1915. __metadata("design:type", core_1.ElementRef)
  1916. ], Table.prototype, "tableViewChild", void 0);
  1917. __decorate([
  1918. core_1.ContentChildren(shared_1.PrimeTemplate),
  1919. __metadata("design:type", core_1.QueryList)
  1920. ], Table.prototype, "templates", void 0);
  1921. __decorate([
  1922. core_1.Input(),
  1923. __metadata("design:type", Array),
  1924. __metadata("design:paramtypes", [Array])
  1925. ], Table.prototype, "value", null);
  1926. __decorate([
  1927. core_1.Input(),
  1928. __metadata("design:type", Array),
  1929. __metadata("design:paramtypes", [Array])
  1930. ], Table.prototype, "columns", null);
  1931. __decorate([
  1932. core_1.Input(),
  1933. __metadata("design:type", Number),
  1934. __metadata("design:paramtypes", [Number])
  1935. ], Table.prototype, "first", null);
  1936. __decorate([
  1937. core_1.Input(),
  1938. __metadata("design:type", Number),
  1939. __metadata("design:paramtypes", [Number])
  1940. ], Table.prototype, "rows", null);
  1941. __decorate([
  1942. core_1.Input(),
  1943. __metadata("design:type", Number),
  1944. __metadata("design:paramtypes", [Number])
  1945. ], Table.prototype, "totalRecords", null);
  1946. __decorate([
  1947. core_1.Input(),
  1948. __metadata("design:type", String),
  1949. __metadata("design:paramtypes", [String])
  1950. ], Table.prototype, "sortField", null);
  1951. __decorate([
  1952. core_1.Input(),
  1953. __metadata("design:type", Number),
  1954. __metadata("design:paramtypes", [Number])
  1955. ], Table.prototype, "sortOrder", null);
  1956. __decorate([
  1957. core_1.Input(),
  1958. __metadata("design:type", Array),
  1959. __metadata("design:paramtypes", [Array])
  1960. ], Table.prototype, "multiSortMeta", null);
  1961. __decorate([
  1962. core_1.Input(),
  1963. __metadata("design:type", Object),
  1964. __metadata("design:paramtypes", [Object])
  1965. ], Table.prototype, "selection", null);
  1966. Table = __decorate([
  1967. core_1.Component({
  1968. selector: 'p-table',
  1969. template: "\n <div #container [ngStyle]=\"style\" [class]=\"styleClass\"\n [ngClass]=\"{'ui-table ui-widget': true, 'ui-table-responsive': responsive, 'ui-table-resizable': resizableColumns,\n 'ui-table-resizable-fit': (resizableColumns && columnResizeMode === 'fit'),\n 'ui-table-hoverable-rows': (rowHover||selectionMode), 'ui-table-auto-layout': autoLayout}\">\n <div class=\"ui-table-loading ui-widget-overlay\" *ngIf=\"loading && showLoader\"></div>\n <div class=\"ui-table-loading-content\" *ngIf=\"loading && showLoader\">\n <i [class]=\"'ui-table-loading-icon pi-spin ' + loadingIcon\"></i>\n </div>\n <div *ngIf=\"captionTemplate\" class=\"ui-table-caption ui-widget-header\">\n <ng-container *ngTemplateOutlet=\"captionTemplate\"></ng-container>\n </div>\n <p-paginator [rows]=\"rows\" [first]=\"first\" [totalRecords]=\"totalRecords\" [pageLinkSize]=\"pageLinks\" styleClass=\"ui-paginator-top\" [alwaysShow]=\"alwaysShowPaginator\"\n (onPageChange)=\"onPageChange($event)\" [rowsPerPageOptions]=\"rowsPerPageOptions\" *ngIf=\"paginator && (paginatorPosition === 'top' || paginatorPosition =='both')\"\n [templateLeft]=\"paginatorLeftTemplate\" [templateRight]=\"paginatorRightTemplate\" [dropdownAppendTo]=\"paginatorDropdownAppendTo\" [dropdownScrollHeight]=\"paginatorDropdownScrollHeight\"\n [currentPageReportTemplate]=\"currentPageReportTemplate\" [showCurrentPageReport]=\"showCurrentPageReport\"></p-paginator>\n \n <div class=\"ui-table-wrapper\" *ngIf=\"!scrollable\">\n <table #table [ngClass]=\"tableStyleClass\" [ngStyle]=\"tableStyle\">\n <ng-container *ngTemplateOutlet=\"colGroupTemplate; context {$implicit: columns}\"></ng-container>\n <thead class=\"ui-table-thead\">\n <ng-container *ngTemplateOutlet=\"headerTemplate; context: {$implicit: columns}\"></ng-container>\n </thead>\n <tbody class=\"ui-table-tbody\" [pTableBody]=\"columns\" [pTableBodyTemplate]=\"bodyTemplate\"></tbody>\n <tfoot *ngIf=\"footerTemplate\" class=\"ui-table-tfoot\">\n <ng-container *ngTemplateOutlet=\"footerTemplate; context {$implicit: columns}\"></ng-container>\n </tfoot>\n </table>\n </div>\n\n <div class=\"ui-table-scrollable-wrapper\" *ngIf=\"scrollable\">\n <div class=\"ui-table-scrollable-view ui-table-frozen-view\" *ngIf=\"frozenColumns||frozenBodyTemplate\" [pScrollableView]=\"frozenColumns\" [frozen]=\"true\" [ngStyle]=\"{width: frozenWidth}\" [scrollHeight]=\"scrollHeight\"></div>\n <div class=\"ui-table-scrollable-view\" [pScrollableView]=\"columns\" [frozen]=\"false\" [scrollHeight]=\"scrollHeight\" [ngStyle]=\"{left: frozenWidth, width: 'calc(100% - '+frozenWidth+')'}\"></div>\n </div>\n \n <p-paginator [rows]=\"rows\" [first]=\"first\" [totalRecords]=\"totalRecords\" [pageLinkSize]=\"pageLinks\" styleClass=\"ui-paginator-bottom\" [alwaysShow]=\"alwaysShowPaginator\"\n (onPageChange)=\"onPageChange($event)\" [rowsPerPageOptions]=\"rowsPerPageOptions\" *ngIf=\"paginator && (paginatorPosition === 'bottom' || paginatorPosition =='both')\"\n [templateLeft]=\"paginatorLeftTemplate\" [templateRight]=\"paginatorRightTemplate\" [dropdownAppendTo]=\"paginatorDropdownAppendTo\" [dropdownScrollHeight]=\"paginatorDropdownScrollHeight\"\n [currentPageReportTemplate]=\"currentPageReportTemplate\" [showCurrentPageReport]=\"showCurrentPageReport\"></p-paginator>\n \n <div *ngIf=\"summaryTemplate\" class=\"ui-table-summary ui-widget-header\">\n <ng-container *ngTemplateOutlet=\"summaryTemplate\"></ng-container>\n </div>\n\n <div #resizeHelper class=\"ui-column-resizer-helper ui-state-highlight\" style=\"display:none\" *ngIf=\"resizableColumns\"></div>\n\n <span #reorderIndicatorUp class=\"pi pi-arrow-down ui-table-reorder-indicator-up\" style=\"display:none\" *ngIf=\"reorderableColumns\"></span>\n <span #reorderIndicatorDown class=\"pi pi-arrow-up ui-table-reorder-indicator-down\" style=\"display:none\" *ngIf=\"reorderableColumns\"></span>\n </div>\n ",
  1970. providers: [TableService]
  1971. }),
  1972. __metadata("design:paramtypes", [core_1.ElementRef, core_1.NgZone, TableService, core_1.ChangeDetectorRef])
  1973. ], Table);
  1974. return Table;
  1975. }());
  1976. exports.Table = Table;
  1977. var TableBody = /** @class */ (function () {
  1978. function TableBody(dt) {
  1979. this.dt = dt;
  1980. }
  1981. __decorate([
  1982. core_1.Input("pTableBody"),
  1983. __metadata("design:type", Array)
  1984. ], TableBody.prototype, "columns", void 0);
  1985. __decorate([
  1986. core_1.Input("pTableBodyTemplate"),
  1987. __metadata("design:type", core_1.TemplateRef)
  1988. ], TableBody.prototype, "template", void 0);
  1989. __decorate([
  1990. core_1.Input(),
  1991. __metadata("design:type", Boolean)
  1992. ], TableBody.prototype, "frozen", void 0);
  1993. TableBody = __decorate([
  1994. core_1.Component({
  1995. selector: '[pTableBody]',
  1996. template: "\n <ng-container *ngIf=\"!dt.expandedRowTemplate\">\n <ng-template ngFor let-rowData let-rowIndex=\"index\" [ngForOf]=\"(dt.paginator && !dt.lazy) ? ((dt.filteredValue||dt.value) | slice:dt.first:(dt.first + dt.rows)) : (dt.filteredValue||dt.value)\" [ngForTrackBy]=\"dt.rowTrackBy\">\n <ng-container *ngTemplateOutlet=\"template; context: {$implicit: rowData, rowIndex: dt.paginator ? (dt.first + rowIndex) : rowIndex, columns: columns, editing: (dt.editMode === 'row' && dt.isRowEditing(rowData))}\"></ng-container>\n </ng-template>\n </ng-container>\n <ng-container *ngIf=\"dt.expandedRowTemplate\">\n <ng-template ngFor let-rowData let-rowIndex=\"index\" [ngForOf]=\"(dt.paginator && !dt.lazy) ? ((dt.filteredValue||dt.value) | slice:dt.first:(dt.first + dt.rows)) : (dt.filteredValue||dt.value)\" [ngForTrackBy]=\"dt.rowTrackBy\">\n <ng-container *ngTemplateOutlet=\"template; context: {$implicit: rowData, rowIndex: dt.paginator ? (dt.first + rowIndex) : rowIndex, columns: columns, expanded: dt.isRowExpanded(rowData), editing: (dt.editMode === 'row' && dt.isRowEditing(rowData))}\"></ng-container>\n <ng-container *ngIf=\"dt.isRowExpanded(rowData)\">\n <ng-container *ngTemplateOutlet=\"dt.expandedRowTemplate; context: {$implicit: rowData, rowIndex: dt.paginator ? (dt.first + rowIndex) : rowIndex, columns: columns}\"></ng-container>\n </ng-container>\n </ng-template>\n </ng-container>\n <ng-container *ngIf=\"dt.isEmpty()\">\n <ng-container *ngTemplateOutlet=\"dt.emptyMessageTemplate; context: {$implicit: columns, frozen: frozen}\"></ng-container>\n </ng-container>\n "
  1997. }),
  1998. __metadata("design:paramtypes", [Table])
  1999. ], TableBody);
  2000. return TableBody;
  2001. }());
  2002. exports.TableBody = TableBody;
  2003. var ScrollableView = /** @class */ (function () {
  2004. function ScrollableView(dt, el, zone) {
  2005. var _this = this;
  2006. this.dt = dt;
  2007. this.el = el;
  2008. this.zone = zone;
  2009. this.loadingArray = [];
  2010. this.subscription = this.dt.tableService.valueSource$.subscribe(function () {
  2011. _this.zone.runOutsideAngular(function () {
  2012. setTimeout(function () {
  2013. _this.alignScrollBar();
  2014. if (_this.scrollLoadingTableViewChild && _this.scrollLoadingTableViewChild.nativeElement) {
  2015. _this.scrollLoadingTableViewChild.nativeElement.style.display = 'none';
  2016. }
  2017. }, 50);
  2018. });
  2019. });
  2020. if (this.dt.virtualScroll) {
  2021. this.totalRecordsSubscription = this.dt.tableService.totalRecordsSource$.subscribe(function () {
  2022. _this.zone.runOutsideAngular(function () {
  2023. setTimeout(function () {
  2024. _this.setVirtualScrollerHeight();
  2025. }, 50);
  2026. });
  2027. });
  2028. }
  2029. this.loadingArray = Array(this.dt.rows).fill(1);
  2030. this.initialized = false;
  2031. }
  2032. Object.defineProperty(ScrollableView.prototype, "scrollHeight", {
  2033. get: function () {
  2034. return this._scrollHeight;
  2035. },
  2036. set: function (val) {
  2037. this._scrollHeight = val;
  2038. this.setScrollHeight();
  2039. },
  2040. enumerable: true,
  2041. configurable: true
  2042. });
  2043. ScrollableView.prototype.ngAfterViewChecked = function () {
  2044. if (!this.initialized && this.el.nativeElement.offsetParent) {
  2045. this.alignScrollBar();
  2046. this.setScrollHeight();
  2047. this.initialized = true;
  2048. }
  2049. };
  2050. ScrollableView.prototype.ngAfterViewInit = function () {
  2051. var _this = this;
  2052. if (!this.frozen) {
  2053. if (this.dt.frozenColumns || this.dt.frozenBodyTemplate) {
  2054. domhandler_1.DomHandler.addClass(this.el.nativeElement, 'ui-table-unfrozen-view');
  2055. }
  2056. var frozenView = this.el.nativeElement.previousElementSibling;
  2057. if (frozenView) {
  2058. this.frozenSiblingBody = domhandler_1.DomHandler.findSingle(frozenView, '.ui-table-scrollable-body');
  2059. }
  2060. }
  2061. else {
  2062. this.scrollBodyViewChild.nativeElement.style.paddingBottom = domhandler_1.DomHandler.calculateScrollbarWidth() + 'px';
  2063. var scrollableView = this.el.nativeElement.nextElementSibling;
  2064. if (scrollableView) {
  2065. this.scrollableSiblingBody = domhandler_1.DomHandler.findSingle(scrollableView, '.ui-table-scrollable-body');
  2066. }
  2067. }
  2068. this.bindEvents();
  2069. this.setScrollHeight();
  2070. this.alignScrollBar();
  2071. if (this.frozen) {
  2072. this.columnsSubscription = this.dt.tableService.columnsSource$.subscribe(function () {
  2073. _this.zone.runOutsideAngular(function () {
  2074. setTimeout(function () {
  2075. _this.setScrollHeight();
  2076. }, 50);
  2077. });
  2078. });
  2079. }
  2080. if (this.dt.virtualScroll) {
  2081. this.setVirtualScrollerHeight();
  2082. if (this.scrollLoadingTableViewChild && this.scrollLoadingTableViewChild.nativeElement) {
  2083. this.scrollLoadingTableViewChild.nativeElement.style.display = 'table';
  2084. }
  2085. }
  2086. };
  2087. ScrollableView.prototype.bindEvents = function () {
  2088. var _this = this;
  2089. this.zone.runOutsideAngular(function () {
  2090. var scrollBarWidth = domhandler_1.DomHandler.calculateScrollbarWidth();
  2091. if (_this.scrollHeaderViewChild && _this.scrollHeaderViewChild.nativeElement) {
  2092. _this.headerScrollListener = _this.onHeaderScroll.bind(_this);
  2093. _this.scrollHeaderViewChild.nativeElement.addEventListener('scroll', _this.headerScrollListener);
  2094. }
  2095. if (_this.scrollFooterViewChild && _this.scrollFooterViewChild.nativeElement) {
  2096. _this.footerScrollListener = _this.onFooterScroll.bind(_this);
  2097. _this.scrollFooterViewChild.nativeElement.addEventListener('scroll', _this.footerScrollListener);
  2098. }
  2099. if (!_this.frozen) {
  2100. _this.bodyScrollListener = _this.onBodyScroll.bind(_this);
  2101. _this.scrollBodyViewChild.nativeElement.addEventListener('scroll', _this.bodyScrollListener);
  2102. }
  2103. });
  2104. };
  2105. ScrollableView.prototype.unbindEvents = function () {
  2106. if (this.scrollHeaderViewChild && this.scrollHeaderViewChild.nativeElement) {
  2107. this.scrollHeaderViewChild.nativeElement.removeEventListener('scroll', this.headerScrollListener);
  2108. }
  2109. if (this.scrollFooterViewChild && this.scrollFooterViewChild.nativeElement) {
  2110. this.scrollFooterViewChild.nativeElement.removeEventListener('scroll', this.footerScrollListener);
  2111. }
  2112. this.scrollBodyViewChild.nativeElement.removeEventListener('scroll', this.bodyScrollListener);
  2113. };
  2114. ScrollableView.prototype.onHeaderScroll = function (event) {
  2115. var scrollLeft = this.scrollHeaderViewChild.nativeElement.scrollLeft;
  2116. this.scrollBodyViewChild.nativeElement.scrollLeft = scrollLeft;
  2117. if (this.scrollFooterViewChild && this.scrollFooterViewChild.nativeElement) {
  2118. this.scrollFooterViewChild.nativeElement.scrollLeft = scrollLeft;
  2119. }
  2120. this.preventBodyScrollPropagation = true;
  2121. };
  2122. ScrollableView.prototype.onFooterScroll = function (event) {
  2123. var scrollLeft = this.scrollFooterViewChild.nativeElement.scrollLeft;
  2124. this.scrollBodyViewChild.nativeElement.scrollLeft = scrollLeft;
  2125. if (this.scrollHeaderViewChild && this.scrollHeaderViewChild.nativeElement) {
  2126. this.scrollHeaderViewChild.nativeElement.scrollLeft = scrollLeft;
  2127. }
  2128. this.preventBodyScrollPropagation = true;
  2129. };
  2130. ScrollableView.prototype.onBodyScroll = function (event) {
  2131. var _this = this;
  2132. if (this.preventBodyScrollPropagation) {
  2133. this.preventBodyScrollPropagation = false;
  2134. return;
  2135. }
  2136. if (this.scrollHeaderViewChild && this.scrollHeaderViewChild.nativeElement) {
  2137. this.scrollHeaderBoxViewChild.nativeElement.style.marginLeft = -1 * this.scrollBodyViewChild.nativeElement.scrollLeft + 'px';
  2138. }
  2139. if (this.scrollFooterViewChild && this.scrollFooterViewChild.nativeElement) {
  2140. this.scrollFooterBoxViewChild.nativeElement.style.marginLeft = -1 * this.scrollBodyViewChild.nativeElement.scrollLeft + 'px';
  2141. }
  2142. if (this.frozenSiblingBody) {
  2143. this.frozenSiblingBody.scrollTop = this.scrollBodyViewChild.nativeElement.scrollTop;
  2144. }
  2145. if (this.dt.virtualScroll) {
  2146. var viewport = domhandler_1.DomHandler.getOuterHeight(this.scrollBodyViewChild.nativeElement);
  2147. var tableHeight = domhandler_1.DomHandler.getOuterHeight(this.scrollTableViewChild.nativeElement);
  2148. var pageHeight_1 = this.dt.virtualRowHeight * this.dt.rows;
  2149. var virtualTableHeight = domhandler_1.DomHandler.getOuterHeight(this.virtualScrollerViewChild.nativeElement);
  2150. var pageCount = (virtualTableHeight / pageHeight_1) || 1;
  2151. var scrollBodyTop = this.scrollTableViewChild.nativeElement.style.top || '0';
  2152. if ((this.scrollBodyViewChild.nativeElement.scrollTop + viewport > parseFloat(scrollBodyTop) + tableHeight) || (this.scrollBodyViewChild.nativeElement.scrollTop < parseFloat(scrollBodyTop))) {
  2153. if (this.scrollLoadingTableViewChild && this.scrollLoadingTableViewChild.nativeElement) {
  2154. this.scrollLoadingTableViewChild.nativeElement.style.display = 'table';
  2155. this.scrollLoadingTableViewChild.nativeElement.style.top = this.scrollBodyViewChild.nativeElement.scrollTop + 'px';
  2156. }
  2157. var page_1 = Math.floor((this.scrollBodyViewChild.nativeElement.scrollTop * pageCount) / (this.scrollBodyViewChild.nativeElement.scrollHeight)) + 1;
  2158. this.dt.handleVirtualScroll({
  2159. page: page_1,
  2160. callback: function () {
  2161. if (_this.scrollLoadingTableViewChild && _this.scrollLoadingTableViewChild.nativeElement) {
  2162. _this.scrollLoadingTableViewChild.nativeElement.style.display = 'none';
  2163. }
  2164. _this.scrollTableViewChild.nativeElement.style.top = ((page_1 - 1) * pageHeight_1) + 'px';
  2165. if (_this.frozenSiblingBody) {
  2166. _this.frozenSiblingBody.children[0].style.top = _this.scrollTableViewChild.nativeElement.style.top;
  2167. }
  2168. _this.dt.anchorRowIndex = null;
  2169. }
  2170. });
  2171. }
  2172. }
  2173. };
  2174. ScrollableView.prototype.setScrollHeight = function () {
  2175. if (this.scrollHeight && this.scrollBodyViewChild && this.scrollBodyViewChild.nativeElement) {
  2176. if (this.scrollHeight.indexOf('%') !== -1) {
  2177. var relativeHeight = void 0;
  2178. this.scrollBodyViewChild.nativeElement.style.visibility = 'hidden';
  2179. this.scrollBodyViewChild.nativeElement.style.height = '100px'; //temporary height to calculate static height
  2180. var containerHeight = domhandler_1.DomHandler.getOuterHeight(this.dt.el.nativeElement.children[0]);
  2181. if (this.scrollHeight.includes("calc")) {
  2182. var percentHeight = parseInt(this.scrollHeight.slice(this.scrollHeight.indexOf("(") + 1, this.scrollHeight.indexOf("%")));
  2183. var diffValue = parseInt(this.scrollHeight.slice(this.scrollHeight.indexOf("-") + 1, this.scrollHeight.indexOf(")")));
  2184. relativeHeight = (domhandler_1.DomHandler.getOuterHeight(this.dt.el.nativeElement.parentElement) * percentHeight / 100) - diffValue;
  2185. }
  2186. else {
  2187. relativeHeight = domhandler_1.DomHandler.getOuterHeight(this.dt.el.nativeElement.parentElement) * parseInt(this.scrollHeight) / 100;
  2188. }
  2189. var staticHeight = containerHeight - 100; //total height of headers, footers, paginators
  2190. var scrollBodyHeight = (relativeHeight - staticHeight);
  2191. if (this.frozen) {
  2192. scrollBodyHeight -= domhandler_1.DomHandler.calculateScrollbarWidth();
  2193. }
  2194. this.scrollBodyViewChild.nativeElement.style.height = 'auto';
  2195. this.scrollBodyViewChild.nativeElement.style.maxHeight = scrollBodyHeight + 'px';
  2196. this.scrollBodyViewChild.nativeElement.style.visibility = 'visible';
  2197. }
  2198. else {
  2199. if (this.frozen && this.scrollableSiblingBody && domhandler_1.DomHandler.getOuterWidth(this.scrollableSiblingBody) < domhandler_1.DomHandler.getOuterWidth(this.scrollableSiblingBody.children[0]))
  2200. this.scrollBodyViewChild.nativeElement.style.maxHeight = (parseInt(this.scrollHeight) - domhandler_1.DomHandler.calculateScrollbarWidth()) + 'px';
  2201. else
  2202. this.scrollBodyViewChild.nativeElement.style.maxHeight = this.scrollHeight;
  2203. }
  2204. }
  2205. };
  2206. ScrollableView.prototype.setVirtualScrollerHeight = function () {
  2207. if (this.virtualScrollerViewChild.nativeElement) {
  2208. this.virtualScrollerViewChild.nativeElement.style.height = this.dt.totalRecords * this.dt.virtualRowHeight + 'px';
  2209. }
  2210. };
  2211. ScrollableView.prototype.hasVerticalOverflow = function () {
  2212. return domhandler_1.DomHandler.getOuterHeight(this.scrollTableViewChild.nativeElement) > domhandler_1.DomHandler.getOuterHeight(this.scrollBodyViewChild.nativeElement);
  2213. };
  2214. ScrollableView.prototype.alignScrollBar = function () {
  2215. if (!this.frozen) {
  2216. var scrollBarWidth = this.hasVerticalOverflow() ? domhandler_1.DomHandler.calculateScrollbarWidth() : 0;
  2217. this.scrollHeaderBoxViewChild.nativeElement.style.marginRight = scrollBarWidth + 'px';
  2218. if (this.scrollFooterBoxViewChild && this.scrollFooterBoxViewChild.nativeElement) {
  2219. this.scrollFooterBoxViewChild.nativeElement.style.marginRight = scrollBarWidth + 'px';
  2220. }
  2221. }
  2222. this.initialized = false;
  2223. };
  2224. ScrollableView.prototype.ngOnDestroy = function () {
  2225. this.unbindEvents();
  2226. this.frozenSiblingBody = null;
  2227. if (this.subscription) {
  2228. this.subscription.unsubscribe();
  2229. }
  2230. if (this.totalRecordsSubscription) {
  2231. this.totalRecordsSubscription.unsubscribe();
  2232. }
  2233. if (this.columnsSubscription) {
  2234. this.columnsSubscription.unsubscribe();
  2235. }
  2236. this.initialized = false;
  2237. };
  2238. __decorate([
  2239. core_1.Input("pScrollableView"),
  2240. __metadata("design:type", Array)
  2241. ], ScrollableView.prototype, "columns", void 0);
  2242. __decorate([
  2243. core_1.Input(),
  2244. __metadata("design:type", Boolean)
  2245. ], ScrollableView.prototype, "frozen", void 0);
  2246. __decorate([
  2247. core_1.ViewChild('scrollHeader', { static: false }),
  2248. __metadata("design:type", core_1.ElementRef)
  2249. ], ScrollableView.prototype, "scrollHeaderViewChild", void 0);
  2250. __decorate([
  2251. core_1.ViewChild('scrollHeaderBox', { static: false }),
  2252. __metadata("design:type", core_1.ElementRef)
  2253. ], ScrollableView.prototype, "scrollHeaderBoxViewChild", void 0);
  2254. __decorate([
  2255. core_1.ViewChild('scrollBody', { static: false }),
  2256. __metadata("design:type", core_1.ElementRef)
  2257. ], ScrollableView.prototype, "scrollBodyViewChild", void 0);
  2258. __decorate([
  2259. core_1.ViewChild('scrollTable', { static: false }),
  2260. __metadata("design:type", core_1.ElementRef)
  2261. ], ScrollableView.prototype, "scrollTableViewChild", void 0);
  2262. __decorate([
  2263. core_1.ViewChild('loadingTable', { static: false }),
  2264. __metadata("design:type", core_1.ElementRef)
  2265. ], ScrollableView.prototype, "scrollLoadingTableViewChild", void 0);
  2266. __decorate([
  2267. core_1.ViewChild('scrollFooter', { static: false }),
  2268. __metadata("design:type", core_1.ElementRef)
  2269. ], ScrollableView.prototype, "scrollFooterViewChild", void 0);
  2270. __decorate([
  2271. core_1.ViewChild('scrollFooterBox', { static: false }),
  2272. __metadata("design:type", core_1.ElementRef)
  2273. ], ScrollableView.prototype, "scrollFooterBoxViewChild", void 0);
  2274. __decorate([
  2275. core_1.ViewChild('virtualScroller', { static: false }),
  2276. __metadata("design:type", core_1.ElementRef)
  2277. ], ScrollableView.prototype, "virtualScrollerViewChild", void 0);
  2278. __decorate([
  2279. core_1.Input(),
  2280. __metadata("design:type", String),
  2281. __metadata("design:paramtypes", [String])
  2282. ], ScrollableView.prototype, "scrollHeight", null);
  2283. ScrollableView = __decorate([
  2284. core_1.Component({
  2285. selector: '[pScrollableView]',
  2286. template: "\n <div #scrollHeader class=\"ui-table-scrollable-header ui-widget-header\">\n <div #scrollHeaderBox class=\"ui-table-scrollable-header-box\">\n <table class=\"ui-table-scrollable-header-table\" [ngClass]=\"dt.tableStyleClass\" [ngStyle]=\"dt.tableStyle\">\n <ng-container *ngTemplateOutlet=\"frozen ? dt.frozenColGroupTemplate||dt.colGroupTemplate : dt.colGroupTemplate; context {$implicit: columns}\"></ng-container>\n <thead class=\"ui-table-thead\">\n <ng-container *ngTemplateOutlet=\"frozen ? dt.frozenHeaderTemplate||dt.headerTemplate : dt.headerTemplate; context {$implicit: columns}\"></ng-container>\n </thead>\n <tbody class=\"ui-table-tbody\">\n <ng-template ngFor let-rowData let-rowIndex=\"index\" [ngForOf]=\"dt.frozenValue\" [ngForTrackBy]=\"dt.rowTrackBy\">\n <ng-container *ngTemplateOutlet=\"dt.frozenRowsTemplate; context: {$implicit: rowData, rowIndex: rowIndex, columns: columns}\"></ng-container>\n </ng-template>\n </tbody>\n </table>\n </div>\n </div>\n <div #scrollBody class=\"ui-table-scrollable-body\">\n <table #scrollTable [ngClass]=\"{'ui-table-scrollable-body-table': true, 'ui-table-virtual-table': dt.virtualScroll}\" [class]=\"dt.tableStyleClass\" [ngStyle]=\"dt.tableStyle\">\n <ng-container *ngTemplateOutlet=\"frozen ? dt.frozenColGroupTemplate||dt.colGroupTemplate : dt.colGroupTemplate; context {$implicit: columns}\"></ng-container>\n <tbody class=\"ui-table-tbody\" [pTableBody]=\"columns\" [pTableBodyTemplate]=\"frozen ? dt.frozenBodyTemplate||dt.bodyTemplate : dt.bodyTemplate\" [frozen]=\"frozen\"></tbody>\n </table>\n <table #loadingTable *ngIf=\"dt.virtualScroll && dt.loadingBodyTemplate != null\" [ngClass]=\"{'ui-table-scrollable-body-table ui-table-loading-virtual-table': true, 'ui-table-virtual-table': dt.virtualScroll}\">\n <tbody class=\"ui-table-tbody\">\n <ng-template ngFor [ngForOf]=\"loadingArray\">\n <ng-container *ngTemplateOutlet=\"dt.loadingBodyTemplate; context: {columns: columns}\"></ng-container>\n </ng-template>\n </tbody>\n </table>\n <div #virtualScroller class=\"ui-table-virtual-scroller\" *ngIf=\"dt.virtualScroll\"></div>\n </div>\n <div #scrollFooter *ngIf=\"dt.footerTemplate\" class=\"ui-table-scrollable-footer ui-widget-header\">\n <div #scrollFooterBox class=\"ui-table-scrollable-footer-box\">\n <table class=\"ui-table-scrollable-footer-table\" [ngClass]=\"dt.tableStyleClass\" [ngStyle]=\"dt.tableStyle\">\n <ng-container *ngTemplateOutlet=\"frozen ? dt.frozenColGroupTemplate||dt.colGroupTemplate : dt.colGroupTemplate; context {$implicit: columns}\"></ng-container>\n <tfoot class=\"ui-table-tfoot\">\n <ng-container *ngTemplateOutlet=\"frozen ? dt.frozenFooterTemplate||dt.footerTemplate : dt.footerTemplate; context {$implicit: columns}\"></ng-container>\n </tfoot>\n </table>\n </div>\n </div>\n "
  2287. }),
  2288. __metadata("design:paramtypes", [Table, core_1.ElementRef, core_1.NgZone])
  2289. ], ScrollableView);
  2290. return ScrollableView;
  2291. }());
  2292. exports.ScrollableView = ScrollableView;
  2293. var SortableColumn = /** @class */ (function () {
  2294. function SortableColumn(dt) {
  2295. var _this = this;
  2296. this.dt = dt;
  2297. if (this.isEnabled()) {
  2298. this.subscription = this.dt.tableService.sortSource$.subscribe(function (sortMeta) {
  2299. _this.updateSortState();
  2300. });
  2301. }
  2302. }
  2303. SortableColumn.prototype.ngOnInit = function () {
  2304. if (this.isEnabled()) {
  2305. this.updateSortState();
  2306. }
  2307. };
  2308. SortableColumn.prototype.updateSortState = function () {
  2309. this.sorted = this.dt.isSorted(this.field);
  2310. };
  2311. SortableColumn.prototype.onClick = function (event) {
  2312. if (this.isEnabled()) {
  2313. this.updateSortState();
  2314. this.dt.sort({
  2315. originalEvent: event,
  2316. field: this.field
  2317. });
  2318. domhandler_1.DomHandler.clearSelection();
  2319. }
  2320. };
  2321. SortableColumn.prototype.onEnterKey = function (event) {
  2322. this.onClick(event);
  2323. };
  2324. SortableColumn.prototype.isEnabled = function () {
  2325. return this.pSortableColumnDisabled !== true;
  2326. };
  2327. SortableColumn.prototype.ngOnDestroy = function () {
  2328. if (this.subscription) {
  2329. this.subscription.unsubscribe();
  2330. }
  2331. };
  2332. __decorate([
  2333. core_1.Input("pSortableColumn"),
  2334. __metadata("design:type", String)
  2335. ], SortableColumn.prototype, "field", void 0);
  2336. __decorate([
  2337. core_1.Input(),
  2338. __metadata("design:type", Boolean)
  2339. ], SortableColumn.prototype, "pSortableColumnDisabled", void 0);
  2340. __decorate([
  2341. core_1.HostListener('click', ['$event']),
  2342. __metadata("design:type", Function),
  2343. __metadata("design:paramtypes", [MouseEvent]),
  2344. __metadata("design:returntype", void 0)
  2345. ], SortableColumn.prototype, "onClick", null);
  2346. __decorate([
  2347. core_1.HostListener('keydown.enter', ['$event']),
  2348. __metadata("design:type", Function),
  2349. __metadata("design:paramtypes", [MouseEvent]),
  2350. __metadata("design:returntype", void 0)
  2351. ], SortableColumn.prototype, "onEnterKey", null);
  2352. SortableColumn = __decorate([
  2353. core_1.Directive({
  2354. selector: '[pSortableColumn]',
  2355. host: {
  2356. '[class.ui-sortable-column]': 'isEnabled()',
  2357. '[class.ui-state-highlight]': 'sorted',
  2358. '[attr.tabindex]': 'isEnabled() ? "0" : null'
  2359. }
  2360. }),
  2361. __metadata("design:paramtypes", [Table])
  2362. ], SortableColumn);
  2363. return SortableColumn;
  2364. }());
  2365. exports.SortableColumn = SortableColumn;
  2366. var SortIcon = /** @class */ (function () {
  2367. function SortIcon(dt) {
  2368. var _this = this;
  2369. this.dt = dt;
  2370. this.subscription = this.dt.tableService.sortSource$.subscribe(function (sortMeta) {
  2371. _this.updateSortState();
  2372. });
  2373. }
  2374. SortIcon.prototype.ngOnInit = function () {
  2375. this.updateSortState();
  2376. };
  2377. SortIcon.prototype.onClick = function (event) {
  2378. event.preventDefault();
  2379. };
  2380. SortIcon.prototype.updateSortState = function () {
  2381. if (this.dt.sortMode === 'single') {
  2382. this.sortOrder = this.dt.isSorted(this.field) ? this.dt.sortOrder : 0;
  2383. }
  2384. else if (this.dt.sortMode === 'multiple') {
  2385. var sortMeta = this.dt.getSortMeta(this.field);
  2386. this.sortOrder = sortMeta ? sortMeta.order : 0;
  2387. }
  2388. };
  2389. SortIcon.prototype.ngOnDestroy = function () {
  2390. if (this.subscription) {
  2391. this.subscription.unsubscribe();
  2392. }
  2393. };
  2394. __decorate([
  2395. core_1.Input(),
  2396. __metadata("design:type", String)
  2397. ], SortIcon.prototype, "field", void 0);
  2398. SortIcon = __decorate([
  2399. core_1.Component({
  2400. selector: 'p-sortIcon',
  2401. template: "\n <i class=\"ui-sortable-column-icon pi pi-fw\" [ngClass]=\"{'pi-sort-up': sortOrder === 1, 'pi-sort-down': sortOrder === -1, 'pi-sort': sortOrder === 0}\"></i>\n "
  2402. }),
  2403. __metadata("design:paramtypes", [Table])
  2404. ], SortIcon);
  2405. return SortIcon;
  2406. }());
  2407. exports.SortIcon = SortIcon;
  2408. var SelectableRow = /** @class */ (function () {
  2409. function SelectableRow(dt, tableService) {
  2410. var _this = this;
  2411. this.dt = dt;
  2412. this.tableService = tableService;
  2413. if (this.isEnabled()) {
  2414. this.subscription = this.dt.tableService.selectionSource$.subscribe(function () {
  2415. _this.selected = _this.dt.isSelected(_this.data);
  2416. });
  2417. }
  2418. }
  2419. SelectableRow.prototype.ngOnInit = function () {
  2420. if (this.isEnabled()) {
  2421. this.selected = this.dt.isSelected(this.data);
  2422. }
  2423. };
  2424. SelectableRow.prototype.onClick = function (event) {
  2425. if (this.isEnabled()) {
  2426. this.dt.handleRowClick({
  2427. originalEvent: event,
  2428. rowData: this.data,
  2429. rowIndex: this.index
  2430. });
  2431. }
  2432. };
  2433. SelectableRow.prototype.onTouchEnd = function (event) {
  2434. if (this.isEnabled()) {
  2435. this.dt.handleRowTouchEnd(event);
  2436. }
  2437. };
  2438. SelectableRow.prototype.onKeyDown = function (event) {
  2439. if (this.isEnabled()) {
  2440. var row = event.target;
  2441. switch (event.which) {
  2442. //down arrow
  2443. case 40:
  2444. var nextRow = this.findNextSelectableRow(row);
  2445. if (nextRow) {
  2446. nextRow.focus();
  2447. }
  2448. event.preventDefault();
  2449. break;
  2450. //up arrow
  2451. case 38:
  2452. var prevRow = this.findPrevSelectableRow(row);
  2453. if (prevRow) {
  2454. prevRow.focus();
  2455. }
  2456. event.preventDefault();
  2457. break;
  2458. //enter
  2459. case 13:
  2460. this.dt.handleRowClick({
  2461. originalEvent: event,
  2462. rowData: this.data,
  2463. rowIndex: this.index
  2464. });
  2465. break;
  2466. default:
  2467. //no op
  2468. break;
  2469. }
  2470. }
  2471. };
  2472. SelectableRow.prototype.findNextSelectableRow = function (row) {
  2473. var nextRow = row.nextElementSibling;
  2474. if (nextRow) {
  2475. if (domhandler_1.DomHandler.hasClass(nextRow, 'ui-selectable-row'))
  2476. return nextRow;
  2477. else
  2478. return this.findNextSelectableRow(nextRow);
  2479. }
  2480. else {
  2481. return null;
  2482. }
  2483. };
  2484. SelectableRow.prototype.findPrevSelectableRow = function (row) {
  2485. var prevRow = row.previousElementSibling;
  2486. if (prevRow) {
  2487. if (domhandler_1.DomHandler.hasClass(prevRow, 'ui-selectable-row'))
  2488. return prevRow;
  2489. else
  2490. return this.findPrevSelectableRow(prevRow);
  2491. }
  2492. else {
  2493. return null;
  2494. }
  2495. };
  2496. SelectableRow.prototype.isEnabled = function () {
  2497. return this.pSelectableRowDisabled !== true;
  2498. };
  2499. SelectableRow.prototype.ngOnDestroy = function () {
  2500. if (this.subscription) {
  2501. this.subscription.unsubscribe();
  2502. }
  2503. };
  2504. __decorate([
  2505. core_1.Input("pSelectableRow"),
  2506. __metadata("design:type", Object)
  2507. ], SelectableRow.prototype, "data", void 0);
  2508. __decorate([
  2509. core_1.Input("pSelectableRowIndex"),
  2510. __metadata("design:type", Number)
  2511. ], SelectableRow.prototype, "index", void 0);
  2512. __decorate([
  2513. core_1.Input(),
  2514. __metadata("design:type", Boolean)
  2515. ], SelectableRow.prototype, "pSelectableRowDisabled", void 0);
  2516. __decorate([
  2517. core_1.HostListener('click', ['$event']),
  2518. __metadata("design:type", Function),
  2519. __metadata("design:paramtypes", [Event]),
  2520. __metadata("design:returntype", void 0)
  2521. ], SelectableRow.prototype, "onClick", null);
  2522. __decorate([
  2523. core_1.HostListener('touchend', ['$event']),
  2524. __metadata("design:type", Function),
  2525. __metadata("design:paramtypes", [Event]),
  2526. __metadata("design:returntype", void 0)
  2527. ], SelectableRow.prototype, "onTouchEnd", null);
  2528. __decorate([
  2529. core_1.HostListener('keydown', ['$event']),
  2530. __metadata("design:type", Function),
  2531. __metadata("design:paramtypes", [KeyboardEvent]),
  2532. __metadata("design:returntype", void 0)
  2533. ], SelectableRow.prototype, "onKeyDown", null);
  2534. SelectableRow = __decorate([
  2535. core_1.Directive({
  2536. selector: '[pSelectableRow]',
  2537. host: {
  2538. '[class.ui-selectable-row]': 'isEnabled()',
  2539. '[class.ui-state-highlight]': 'selected',
  2540. '[attr.tabindex]': 'isEnabled() ? 0 : undefined',
  2541. }
  2542. }),
  2543. __metadata("design:paramtypes", [Table, TableService])
  2544. ], SelectableRow);
  2545. return SelectableRow;
  2546. }());
  2547. exports.SelectableRow = SelectableRow;
  2548. var SelectableRowDblClick = /** @class */ (function () {
  2549. function SelectableRowDblClick(dt, tableService) {
  2550. var _this = this;
  2551. this.dt = dt;
  2552. this.tableService = tableService;
  2553. if (this.isEnabled()) {
  2554. this.subscription = this.dt.tableService.selectionSource$.subscribe(function () {
  2555. _this.selected = _this.dt.isSelected(_this.data);
  2556. });
  2557. }
  2558. }
  2559. SelectableRowDblClick.prototype.ngOnInit = function () {
  2560. if (this.isEnabled()) {
  2561. this.selected = this.dt.isSelected(this.data);
  2562. }
  2563. };
  2564. SelectableRowDblClick.prototype.onClick = function (event) {
  2565. if (this.isEnabled()) {
  2566. this.dt.handleRowClick({
  2567. originalEvent: event,
  2568. rowData: this.data,
  2569. rowIndex: this.index
  2570. });
  2571. }
  2572. };
  2573. SelectableRowDblClick.prototype.isEnabled = function () {
  2574. return this.pSelectableRowDisabled !== true;
  2575. };
  2576. SelectableRowDblClick.prototype.ngOnDestroy = function () {
  2577. if (this.subscription) {
  2578. this.subscription.unsubscribe();
  2579. }
  2580. };
  2581. __decorate([
  2582. core_1.Input("pSelectableRowDblClick"),
  2583. __metadata("design:type", Object)
  2584. ], SelectableRowDblClick.prototype, "data", void 0);
  2585. __decorate([
  2586. core_1.Input("pSelectableRowIndex"),
  2587. __metadata("design:type", Number)
  2588. ], SelectableRowDblClick.prototype, "index", void 0);
  2589. __decorate([
  2590. core_1.Input(),
  2591. __metadata("design:type", Boolean)
  2592. ], SelectableRowDblClick.prototype, "pSelectableRowDisabled", void 0);
  2593. __decorate([
  2594. core_1.HostListener('dblclick', ['$event']),
  2595. __metadata("design:type", Function),
  2596. __metadata("design:paramtypes", [Event]),
  2597. __metadata("design:returntype", void 0)
  2598. ], SelectableRowDblClick.prototype, "onClick", null);
  2599. SelectableRowDblClick = __decorate([
  2600. core_1.Directive({
  2601. selector: '[pSelectableRowDblClick]',
  2602. host: {
  2603. '[class.ui-selectable-row]': 'isEnabled()',
  2604. '[class.ui-state-highlight]': 'selected'
  2605. }
  2606. }),
  2607. __metadata("design:paramtypes", [Table, TableService])
  2608. ], SelectableRowDblClick);
  2609. return SelectableRowDblClick;
  2610. }());
  2611. exports.SelectableRowDblClick = SelectableRowDblClick;
  2612. var ContextMenuRow = /** @class */ (function () {
  2613. function ContextMenuRow(dt, tableService) {
  2614. var _this = this;
  2615. this.dt = dt;
  2616. this.tableService = tableService;
  2617. if (this.isEnabled()) {
  2618. this.subscription = this.dt.tableService.contextMenuSource$.subscribe(function (data) {
  2619. _this.selected = _this.dt.equals(_this.data, data);
  2620. });
  2621. }
  2622. }
  2623. ContextMenuRow.prototype.onContextMenu = function (event) {
  2624. if (this.isEnabled()) {
  2625. this.dt.handleRowRightClick({
  2626. originalEvent: event,
  2627. rowData: this.data,
  2628. rowIndex: this.index
  2629. });
  2630. event.preventDefault();
  2631. }
  2632. };
  2633. ContextMenuRow.prototype.isEnabled = function () {
  2634. return this.pContextMenuRowDisabled !== true;
  2635. };
  2636. ContextMenuRow.prototype.ngOnDestroy = function () {
  2637. if (this.subscription) {
  2638. this.subscription.unsubscribe();
  2639. }
  2640. };
  2641. __decorate([
  2642. core_1.Input("pContextMenuRow"),
  2643. __metadata("design:type", Object)
  2644. ], ContextMenuRow.prototype, "data", void 0);
  2645. __decorate([
  2646. core_1.Input("pContextMenuRowIndex"),
  2647. __metadata("design:type", Number)
  2648. ], ContextMenuRow.prototype, "index", void 0);
  2649. __decorate([
  2650. core_1.Input(),
  2651. __metadata("design:type", Boolean)
  2652. ], ContextMenuRow.prototype, "pContextMenuRowDisabled", void 0);
  2653. __decorate([
  2654. core_1.HostListener('contextmenu', ['$event']),
  2655. __metadata("design:type", Function),
  2656. __metadata("design:paramtypes", [Event]),
  2657. __metadata("design:returntype", void 0)
  2658. ], ContextMenuRow.prototype, "onContextMenu", null);
  2659. ContextMenuRow = __decorate([
  2660. core_1.Directive({
  2661. selector: '[pContextMenuRow]',
  2662. host: {
  2663. '[class.ui-contextmenu-selected]': 'selected'
  2664. }
  2665. }),
  2666. __metadata("design:paramtypes", [Table, TableService])
  2667. ], ContextMenuRow);
  2668. return ContextMenuRow;
  2669. }());
  2670. exports.ContextMenuRow = ContextMenuRow;
  2671. var RowToggler = /** @class */ (function () {
  2672. function RowToggler(dt) {
  2673. this.dt = dt;
  2674. }
  2675. RowToggler.prototype.onClick = function (event) {
  2676. if (this.isEnabled()) {
  2677. this.dt.toggleRow(this.data, event);
  2678. event.preventDefault();
  2679. }
  2680. };
  2681. RowToggler.prototype.isEnabled = function () {
  2682. return this.pRowTogglerDisabled !== true;
  2683. };
  2684. __decorate([
  2685. core_1.Input('pRowToggler'),
  2686. __metadata("design:type", Object)
  2687. ], RowToggler.prototype, "data", void 0);
  2688. __decorate([
  2689. core_1.Input(),
  2690. __metadata("design:type", Boolean)
  2691. ], RowToggler.prototype, "pRowTogglerDisabled", void 0);
  2692. __decorate([
  2693. core_1.HostListener('click', ['$event']),
  2694. __metadata("design:type", Function),
  2695. __metadata("design:paramtypes", [Event]),
  2696. __metadata("design:returntype", void 0)
  2697. ], RowToggler.prototype, "onClick", null);
  2698. RowToggler = __decorate([
  2699. core_1.Directive({
  2700. selector: '[pRowToggler]'
  2701. }),
  2702. __metadata("design:paramtypes", [Table])
  2703. ], RowToggler);
  2704. return RowToggler;
  2705. }());
  2706. exports.RowToggler = RowToggler;
  2707. var ResizableColumn = /** @class */ (function () {
  2708. function ResizableColumn(dt, el, zone) {
  2709. this.dt = dt;
  2710. this.el = el;
  2711. this.zone = zone;
  2712. }
  2713. ResizableColumn.prototype.ngAfterViewInit = function () {
  2714. var _this = this;
  2715. if (this.isEnabled()) {
  2716. domhandler_1.DomHandler.addClass(this.el.nativeElement, 'ui-resizable-column');
  2717. this.resizer = document.createElement('span');
  2718. this.resizer.className = 'ui-column-resizer ui-clickable';
  2719. this.el.nativeElement.appendChild(this.resizer);
  2720. this.zone.runOutsideAngular(function () {
  2721. _this.resizerMouseDownListener = _this.onMouseDown.bind(_this);
  2722. _this.resizer.addEventListener('mousedown', _this.resizerMouseDownListener);
  2723. });
  2724. }
  2725. };
  2726. ResizableColumn.prototype.bindDocumentEvents = function () {
  2727. var _this = this;
  2728. this.zone.runOutsideAngular(function () {
  2729. _this.documentMouseMoveListener = _this.onDocumentMouseMove.bind(_this);
  2730. document.addEventListener('mousemove', _this.documentMouseMoveListener);
  2731. _this.documentMouseUpListener = _this.onDocumentMouseUp.bind(_this);
  2732. document.addEventListener('mouseup', _this.documentMouseUpListener);
  2733. });
  2734. };
  2735. ResizableColumn.prototype.unbindDocumentEvents = function () {
  2736. if (this.documentMouseMoveListener) {
  2737. document.removeEventListener('mousemove', this.documentMouseMoveListener);
  2738. this.documentMouseMoveListener = null;
  2739. }
  2740. if (this.documentMouseUpListener) {
  2741. document.removeEventListener('mouseup', this.documentMouseUpListener);
  2742. this.documentMouseUpListener = null;
  2743. }
  2744. };
  2745. ResizableColumn.prototype.onMouseDown = function (event) {
  2746. if (event.which === 1) {
  2747. this.dt.onColumnResizeBegin(event);
  2748. this.bindDocumentEvents();
  2749. }
  2750. };
  2751. ResizableColumn.prototype.onDocumentMouseMove = function (event) {
  2752. this.dt.onColumnResize(event);
  2753. };
  2754. ResizableColumn.prototype.onDocumentMouseUp = function (event) {
  2755. this.dt.onColumnResizeEnd(event, this.el.nativeElement);
  2756. this.unbindDocumentEvents();
  2757. };
  2758. ResizableColumn.prototype.isEnabled = function () {
  2759. return this.pResizableColumnDisabled !== true;
  2760. };
  2761. ResizableColumn.prototype.ngOnDestroy = function () {
  2762. if (this.resizerMouseDownListener) {
  2763. this.resizer.removeEventListener('mousedown', this.resizerMouseDownListener);
  2764. }
  2765. this.unbindDocumentEvents();
  2766. };
  2767. __decorate([
  2768. core_1.Input(),
  2769. __metadata("design:type", Boolean)
  2770. ], ResizableColumn.prototype, "pResizableColumnDisabled", void 0);
  2771. ResizableColumn = __decorate([
  2772. core_1.Directive({
  2773. selector: '[pResizableColumn]'
  2774. }),
  2775. __metadata("design:paramtypes", [Table, core_1.ElementRef, core_1.NgZone])
  2776. ], ResizableColumn);
  2777. return ResizableColumn;
  2778. }());
  2779. exports.ResizableColumn = ResizableColumn;
  2780. var ReorderableColumn = /** @class */ (function () {
  2781. function ReorderableColumn(dt, el, zone) {
  2782. this.dt = dt;
  2783. this.el = el;
  2784. this.zone = zone;
  2785. }
  2786. ReorderableColumn.prototype.ngAfterViewInit = function () {
  2787. if (this.isEnabled()) {
  2788. this.bindEvents();
  2789. }
  2790. };
  2791. ReorderableColumn.prototype.bindEvents = function () {
  2792. var _this = this;
  2793. this.zone.runOutsideAngular(function () {
  2794. _this.mouseDownListener = _this.onMouseDown.bind(_this);
  2795. _this.el.nativeElement.addEventListener('mousedown', _this.mouseDownListener);
  2796. _this.dragStartListener = _this.onDragStart.bind(_this);
  2797. _this.el.nativeElement.addEventListener('dragstart', _this.dragStartListener);
  2798. _this.dragOverListener = _this.onDragEnter.bind(_this);
  2799. _this.el.nativeElement.addEventListener('dragover', _this.dragOverListener);
  2800. _this.dragEnterListener = _this.onDragEnter.bind(_this);
  2801. _this.el.nativeElement.addEventListener('dragenter', _this.dragEnterListener);
  2802. _this.dragLeaveListener = _this.onDragLeave.bind(_this);
  2803. _this.el.nativeElement.addEventListener('dragleave', _this.dragLeaveListener);
  2804. });
  2805. };
  2806. ReorderableColumn.prototype.unbindEvents = function () {
  2807. if (this.mouseDownListener) {
  2808. document.removeEventListener('mousedown', this.mouseDownListener);
  2809. this.mouseDownListener = null;
  2810. }
  2811. if (this.dragOverListener) {
  2812. document.removeEventListener('dragover', this.dragOverListener);
  2813. this.dragOverListener = null;
  2814. }
  2815. if (this.dragEnterListener) {
  2816. document.removeEventListener('dragenter', this.dragEnterListener);
  2817. this.dragEnterListener = null;
  2818. }
  2819. if (this.dragEnterListener) {
  2820. document.removeEventListener('dragenter', this.dragEnterListener);
  2821. this.dragEnterListener = null;
  2822. }
  2823. if (this.dragLeaveListener) {
  2824. document.removeEventListener('dragleave', this.dragLeaveListener);
  2825. this.dragLeaveListener = null;
  2826. }
  2827. };
  2828. ReorderableColumn.prototype.onMouseDown = function (event) {
  2829. if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA' || domhandler_1.DomHandler.hasClass(event.target, 'ui-column-resizer'))
  2830. this.el.nativeElement.draggable = false;
  2831. else
  2832. this.el.nativeElement.draggable = true;
  2833. };
  2834. ReorderableColumn.prototype.onDragStart = function (event) {
  2835. this.dt.onColumnDragStart(event, this.el.nativeElement);
  2836. };
  2837. ReorderableColumn.prototype.onDragOver = function (event) {
  2838. event.preventDefault();
  2839. };
  2840. ReorderableColumn.prototype.onDragEnter = function (event) {
  2841. this.dt.onColumnDragEnter(event, this.el.nativeElement);
  2842. };
  2843. ReorderableColumn.prototype.onDragLeave = function (event) {
  2844. this.dt.onColumnDragLeave(event);
  2845. };
  2846. ReorderableColumn.prototype.onDrop = function (event) {
  2847. if (this.isEnabled()) {
  2848. this.dt.onColumnDrop(event, this.el.nativeElement);
  2849. }
  2850. };
  2851. ReorderableColumn.prototype.isEnabled = function () {
  2852. return this.pReorderableColumnDisabled !== true;
  2853. };
  2854. ReorderableColumn.prototype.ngOnDestroy = function () {
  2855. this.unbindEvents();
  2856. };
  2857. __decorate([
  2858. core_1.Input(),
  2859. __metadata("design:type", Boolean)
  2860. ], ReorderableColumn.prototype, "pReorderableColumnDisabled", void 0);
  2861. __decorate([
  2862. core_1.HostListener('drop', ['$event']),
  2863. __metadata("design:type", Function),
  2864. __metadata("design:paramtypes", [Object]),
  2865. __metadata("design:returntype", void 0)
  2866. ], ReorderableColumn.prototype, "onDrop", null);
  2867. ReorderableColumn = __decorate([
  2868. core_1.Directive({
  2869. selector: '[pReorderableColumn]'
  2870. }),
  2871. __metadata("design:paramtypes", [Table, core_1.ElementRef, core_1.NgZone])
  2872. ], ReorderableColumn);
  2873. return ReorderableColumn;
  2874. }());
  2875. exports.ReorderableColumn = ReorderableColumn;
  2876. var EditableColumn = /** @class */ (function () {
  2877. function EditableColumn(dt, el, zone) {
  2878. this.dt = dt;
  2879. this.el = el;
  2880. this.zone = zone;
  2881. }
  2882. EditableColumn.prototype.ngAfterViewInit = function () {
  2883. if (this.isEnabled()) {
  2884. domhandler_1.DomHandler.addClass(this.el.nativeElement, 'ui-editable-column');
  2885. }
  2886. };
  2887. EditableColumn.prototype.onClick = function (event) {
  2888. if (this.isEnabled()) {
  2889. this.dt.editingCellClick = true;
  2890. if (this.dt.editingCell) {
  2891. if (this.dt.editingCell !== this.el.nativeElement) {
  2892. if (!this.dt.isEditingCellValid()) {
  2893. return;
  2894. }
  2895. domhandler_1.DomHandler.removeClass(this.dt.editingCell, 'ui-editing-cell');
  2896. this.openCell();
  2897. }
  2898. }
  2899. else {
  2900. this.openCell();
  2901. }
  2902. }
  2903. };
  2904. EditableColumn.prototype.openCell = function () {
  2905. var _this = this;
  2906. this.dt.updateEditingCell(this.el.nativeElement, this.data, this.field);
  2907. domhandler_1.DomHandler.addClass(this.el.nativeElement, 'ui-editing-cell');
  2908. this.dt.onEditInit.emit({ field: this.field, data: this.data });
  2909. this.zone.runOutsideAngular(function () {
  2910. setTimeout(function () {
  2911. var focusCellSelector = _this.pFocusCellSelector || 'input, textarea, select';
  2912. var focusableElement = domhandler_1.DomHandler.findSingle(_this.el.nativeElement, focusCellSelector);
  2913. if (focusableElement) {
  2914. focusableElement.focus();
  2915. }
  2916. }, 50);
  2917. });
  2918. };
  2919. EditableColumn.prototype.closeEditingCell = function () {
  2920. domhandler_1.DomHandler.removeClass(this.dt.editingCell, 'ui-editing-cell');
  2921. this.dt.editingCell = null;
  2922. this.dt.editingCellData = null;
  2923. this.dt.editingCellField = null;
  2924. this.dt.unbindDocumentEditListener();
  2925. };
  2926. EditableColumn.prototype.onKeyDown = function (event) {
  2927. if (this.isEnabled()) {
  2928. //enter
  2929. if (event.keyCode == 13) {
  2930. if (this.dt.isEditingCellValid()) {
  2931. this.closeEditingCell();
  2932. this.dt.onEditComplete.emit({ field: this.field, data: this.data, originalEvent: event });
  2933. }
  2934. event.preventDefault();
  2935. }
  2936. //escape
  2937. else if (event.keyCode == 27) {
  2938. if (this.dt.isEditingCellValid()) {
  2939. this.closeEditingCell();
  2940. this.dt.onEditCancel.emit({ field: this.field, data: this.data, originalEvent: event });
  2941. }
  2942. event.preventDefault();
  2943. }
  2944. //tab
  2945. else if (event.keyCode == 9) {
  2946. this.dt.onEditComplete.emit({ field: this.field, data: this.data, originalEvent: event });
  2947. if (event.shiftKey)
  2948. this.moveToPreviousCell(event);
  2949. else
  2950. this.moveToNextCell(event);
  2951. }
  2952. }
  2953. };
  2954. EditableColumn.prototype.findCell = function (element) {
  2955. if (element) {
  2956. var cell = element;
  2957. while (cell && !domhandler_1.DomHandler.hasClass(cell, 'ui-editing-cell')) {
  2958. cell = cell.parentElement;
  2959. }
  2960. return cell;
  2961. }
  2962. else {
  2963. return null;
  2964. }
  2965. };
  2966. EditableColumn.prototype.moveToPreviousCell = function (event) {
  2967. var currentCell = this.findCell(event.target);
  2968. var row = currentCell.parentElement;
  2969. var targetCell = this.findPreviousEditableColumn(currentCell);
  2970. if (targetCell) {
  2971. domhandler_1.DomHandler.invokeElementMethod(event.target, 'blur');
  2972. domhandler_1.DomHandler.invokeElementMethod(targetCell, 'click');
  2973. event.preventDefault();
  2974. }
  2975. };
  2976. EditableColumn.prototype.moveToNextCell = function (event) {
  2977. var currentCell = this.findCell(event.target);
  2978. var row = currentCell.parentElement;
  2979. var targetCell = this.findNextEditableColumn(currentCell);
  2980. if (targetCell) {
  2981. domhandler_1.DomHandler.invokeElementMethod(event.target, 'blur');
  2982. domhandler_1.DomHandler.invokeElementMethod(targetCell, 'click');
  2983. event.preventDefault();
  2984. }
  2985. };
  2986. EditableColumn.prototype.findPreviousEditableColumn = function (cell) {
  2987. var prevCell = cell.previousElementSibling;
  2988. if (!prevCell) {
  2989. var previousRow = cell.parentElement.previousElementSibling;
  2990. if (previousRow) {
  2991. prevCell = previousRow.lastElementChild;
  2992. }
  2993. }
  2994. if (prevCell) {
  2995. if (domhandler_1.DomHandler.hasClass(prevCell, 'ui-editable-column'))
  2996. return prevCell;
  2997. else
  2998. return this.findPreviousEditableColumn(prevCell);
  2999. }
  3000. else {
  3001. return null;
  3002. }
  3003. };
  3004. EditableColumn.prototype.findNextEditableColumn = function (cell) {
  3005. var nextCell = cell.nextElementSibling;
  3006. if (!nextCell) {
  3007. var nextRow = cell.parentElement.nextElementSibling;
  3008. if (nextRow) {
  3009. nextCell = nextRow.firstElementChild;
  3010. }
  3011. }
  3012. if (nextCell) {
  3013. if (domhandler_1.DomHandler.hasClass(nextCell, 'ui-editable-column'))
  3014. return nextCell;
  3015. else
  3016. return this.findNextEditableColumn(nextCell);
  3017. }
  3018. else {
  3019. return null;
  3020. }
  3021. };
  3022. EditableColumn.prototype.isEnabled = function () {
  3023. return this.pEditableColumnDisabled !== true;
  3024. };
  3025. __decorate([
  3026. core_1.Input("pEditableColumn"),
  3027. __metadata("design:type", Object)
  3028. ], EditableColumn.prototype, "data", void 0);
  3029. __decorate([
  3030. core_1.Input("pEditableColumnField"),
  3031. __metadata("design:type", Object)
  3032. ], EditableColumn.prototype, "field", void 0);
  3033. __decorate([
  3034. core_1.Input(),
  3035. __metadata("design:type", Boolean)
  3036. ], EditableColumn.prototype, "pEditableColumnDisabled", void 0);
  3037. __decorate([
  3038. core_1.Input(),
  3039. __metadata("design:type", String)
  3040. ], EditableColumn.prototype, "pFocusCellSelector", void 0);
  3041. __decorate([
  3042. core_1.HostListener('click', ['$event']),
  3043. __metadata("design:type", Function),
  3044. __metadata("design:paramtypes", [MouseEvent]),
  3045. __metadata("design:returntype", void 0)
  3046. ], EditableColumn.prototype, "onClick", null);
  3047. __decorate([
  3048. core_1.HostListener('keydown', ['$event']),
  3049. __metadata("design:type", Function),
  3050. __metadata("design:paramtypes", [KeyboardEvent]),
  3051. __metadata("design:returntype", void 0)
  3052. ], EditableColumn.prototype, "onKeyDown", null);
  3053. EditableColumn = __decorate([
  3054. core_1.Directive({
  3055. selector: '[pEditableColumn]'
  3056. }),
  3057. __metadata("design:paramtypes", [Table, core_1.ElementRef, core_1.NgZone])
  3058. ], EditableColumn);
  3059. return EditableColumn;
  3060. }());
  3061. exports.EditableColumn = EditableColumn;
  3062. var EditableRow = /** @class */ (function () {
  3063. function EditableRow(el) {
  3064. this.el = el;
  3065. }
  3066. EditableRow.prototype.isEnabled = function () {
  3067. return this.pEditableRowDisabled !== true;
  3068. };
  3069. __decorate([
  3070. core_1.Input("pEditableRow"),
  3071. __metadata("design:type", Object)
  3072. ], EditableRow.prototype, "data", void 0);
  3073. __decorate([
  3074. core_1.Input(),
  3075. __metadata("design:type", Boolean)
  3076. ], EditableRow.prototype, "pEditableRowDisabled", void 0);
  3077. EditableRow = __decorate([
  3078. core_1.Directive({
  3079. selector: '[pEditableRow]'
  3080. }),
  3081. __metadata("design:paramtypes", [core_1.ElementRef])
  3082. ], EditableRow);
  3083. return EditableRow;
  3084. }());
  3085. exports.EditableRow = EditableRow;
  3086. var InitEditableRow = /** @class */ (function () {
  3087. function InitEditableRow(dt, editableRow) {
  3088. this.dt = dt;
  3089. this.editableRow = editableRow;
  3090. }
  3091. InitEditableRow.prototype.onClick = function (event) {
  3092. this.dt.initRowEdit(this.editableRow.data);
  3093. event.preventDefault();
  3094. };
  3095. __decorate([
  3096. core_1.HostListener('click', ['$event']),
  3097. __metadata("design:type", Function),
  3098. __metadata("design:paramtypes", [Event]),
  3099. __metadata("design:returntype", void 0)
  3100. ], InitEditableRow.prototype, "onClick", null);
  3101. InitEditableRow = __decorate([
  3102. core_1.Directive({
  3103. selector: '[pInitEditableRow]'
  3104. }),
  3105. __metadata("design:paramtypes", [Table, EditableRow])
  3106. ], InitEditableRow);
  3107. return InitEditableRow;
  3108. }());
  3109. exports.InitEditableRow = InitEditableRow;
  3110. var SaveEditableRow = /** @class */ (function () {
  3111. function SaveEditableRow(dt, editableRow) {
  3112. this.dt = dt;
  3113. this.editableRow = editableRow;
  3114. }
  3115. SaveEditableRow.prototype.onClick = function (event) {
  3116. this.dt.saveRowEdit(this.editableRow.data, this.editableRow.el.nativeElement);
  3117. event.preventDefault();
  3118. };
  3119. __decorate([
  3120. core_1.HostListener('click', ['$event']),
  3121. __metadata("design:type", Function),
  3122. __metadata("design:paramtypes", [Event]),
  3123. __metadata("design:returntype", void 0)
  3124. ], SaveEditableRow.prototype, "onClick", null);
  3125. SaveEditableRow = __decorate([
  3126. core_1.Directive({
  3127. selector: '[pSaveEditableRow]'
  3128. }),
  3129. __metadata("design:paramtypes", [Table, EditableRow])
  3130. ], SaveEditableRow);
  3131. return SaveEditableRow;
  3132. }());
  3133. exports.SaveEditableRow = SaveEditableRow;
  3134. var CancelEditableRow = /** @class */ (function () {
  3135. function CancelEditableRow(dt, editableRow) {
  3136. this.dt = dt;
  3137. this.editableRow = editableRow;
  3138. }
  3139. CancelEditableRow.prototype.onClick = function (event) {
  3140. this.dt.cancelRowEdit(this.editableRow.data);
  3141. event.preventDefault();
  3142. };
  3143. __decorate([
  3144. core_1.HostListener('click', ['$event']),
  3145. __metadata("design:type", Function),
  3146. __metadata("design:paramtypes", [Event]),
  3147. __metadata("design:returntype", void 0)
  3148. ], CancelEditableRow.prototype, "onClick", null);
  3149. CancelEditableRow = __decorate([
  3150. core_1.Directive({
  3151. selector: '[pCancelEditableRow]'
  3152. }),
  3153. __metadata("design:paramtypes", [Table, EditableRow])
  3154. ], CancelEditableRow);
  3155. return CancelEditableRow;
  3156. }());
  3157. exports.CancelEditableRow = CancelEditableRow;
  3158. var CellEditor = /** @class */ (function () {
  3159. function CellEditor(dt, editableColumn, editableRow) {
  3160. this.dt = dt;
  3161. this.editableColumn = editableColumn;
  3162. this.editableRow = editableRow;
  3163. }
  3164. CellEditor.prototype.ngAfterContentInit = function () {
  3165. var _this = this;
  3166. this.templates.forEach(function (item) {
  3167. switch (item.getType()) {
  3168. case 'input':
  3169. _this.inputTemplate = item.template;
  3170. break;
  3171. case 'output':
  3172. _this.outputTemplate = item.template;
  3173. break;
  3174. }
  3175. });
  3176. };
  3177. Object.defineProperty(CellEditor.prototype, "editing", {
  3178. get: function () {
  3179. return (this.dt.editingCell && this.editableColumn && this.dt.editingCell === this.editableColumn.el.nativeElement) ||
  3180. (this.editableRow && this.dt.editMode === 'row' && this.dt.isRowEditing(this.editableRow.data));
  3181. },
  3182. enumerable: true,
  3183. configurable: true
  3184. });
  3185. __decorate([
  3186. core_1.ContentChildren(shared_1.PrimeTemplate),
  3187. __metadata("design:type", core_1.QueryList)
  3188. ], CellEditor.prototype, "templates", void 0);
  3189. CellEditor = __decorate([
  3190. core_1.Component({
  3191. selector: 'p-cellEditor',
  3192. template: "\n <ng-container *ngIf=\"editing\">\n <ng-container *ngTemplateOutlet=\"inputTemplate\"></ng-container>\n </ng-container>\n <ng-container *ngIf=\"!editing\">\n <ng-container *ngTemplateOutlet=\"outputTemplate\"></ng-container>\n </ng-container>\n "
  3193. }),
  3194. __param(1, core_1.Optional()), __param(2, core_1.Optional()),
  3195. __metadata("design:paramtypes", [Table, EditableColumn, EditableRow])
  3196. ], CellEditor);
  3197. return CellEditor;
  3198. }());
  3199. exports.CellEditor = CellEditor;
  3200. var TableRadioButton = /** @class */ (function () {
  3201. function TableRadioButton(dt, tableService) {
  3202. var _this = this;
  3203. this.dt = dt;
  3204. this.tableService = tableService;
  3205. this.subscription = this.dt.tableService.selectionSource$.subscribe(function () {
  3206. _this.checked = _this.dt.isSelected(_this.value);
  3207. });
  3208. }
  3209. TableRadioButton.prototype.ngOnInit = function () {
  3210. this.checked = this.dt.isSelected(this.value);
  3211. };
  3212. TableRadioButton.prototype.onClick = function (event) {
  3213. if (!this.disabled) {
  3214. this.dt.toggleRowWithRadio({
  3215. originalEvent: event,
  3216. rowIndex: this.index
  3217. }, this.value);
  3218. }
  3219. domhandler_1.DomHandler.clearSelection();
  3220. };
  3221. TableRadioButton.prototype.onFocus = function () {
  3222. domhandler_1.DomHandler.addClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  3223. };
  3224. TableRadioButton.prototype.onBlur = function () {
  3225. domhandler_1.DomHandler.removeClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  3226. };
  3227. TableRadioButton.prototype.ngOnDestroy = function () {
  3228. if (this.subscription) {
  3229. this.subscription.unsubscribe();
  3230. }
  3231. };
  3232. __decorate([
  3233. core_1.Input(),
  3234. __metadata("design:type", Boolean)
  3235. ], TableRadioButton.prototype, "disabled", void 0);
  3236. __decorate([
  3237. core_1.Input(),
  3238. __metadata("design:type", Object)
  3239. ], TableRadioButton.prototype, "value", void 0);
  3240. __decorate([
  3241. core_1.Input(),
  3242. __metadata("design:type", Number)
  3243. ], TableRadioButton.prototype, "index", void 0);
  3244. __decorate([
  3245. core_1.ViewChild('box', { static: false }),
  3246. __metadata("design:type", core_1.ElementRef)
  3247. ], TableRadioButton.prototype, "boxViewChild", void 0);
  3248. TableRadioButton = __decorate([
  3249. core_1.Component({
  3250. selector: 'p-tableRadioButton',
  3251. template: "\n <div class=\"ui-radiobutton ui-widget\" (click)=\"onClick($event)\">\n <div class=\"ui-helper-hidden-accessible\">\n <input type=\"radio\" [checked]=\"checked\" (focus)=\"onFocus()\" (blur)=\"onBlur()\" [disabled]=\"disabled\">\n </div>\n <div #box [ngClass]=\"{'ui-radiobutton-box ui-widget ui-state-default':true,\n 'ui-state-active':checked, 'ui-state-disabled':disabled}\">\n <span class=\"ui-radiobutton-icon ui-clickable\" [ngClass]=\"{'pi pi-circle-on':checked}\"></span>\n </div>\n </div>\n "
  3252. }),
  3253. __metadata("design:paramtypes", [Table, TableService])
  3254. ], TableRadioButton);
  3255. return TableRadioButton;
  3256. }());
  3257. exports.TableRadioButton = TableRadioButton;
  3258. var TableCheckbox = /** @class */ (function () {
  3259. function TableCheckbox(dt, tableService) {
  3260. var _this = this;
  3261. this.dt = dt;
  3262. this.tableService = tableService;
  3263. this.subscription = this.dt.tableService.selectionSource$.subscribe(function () {
  3264. _this.checked = _this.dt.isSelected(_this.value);
  3265. });
  3266. }
  3267. TableCheckbox.prototype.ngOnInit = function () {
  3268. this.checked = this.dt.isSelected(this.value);
  3269. };
  3270. TableCheckbox.prototype.onClick = function (event) {
  3271. if (!this.disabled) {
  3272. this.dt.toggleRowWithCheckbox({
  3273. originalEvent: event,
  3274. rowIndex: this.index
  3275. }, this.value);
  3276. }
  3277. domhandler_1.DomHandler.clearSelection();
  3278. };
  3279. TableCheckbox.prototype.onFocus = function () {
  3280. domhandler_1.DomHandler.addClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  3281. };
  3282. TableCheckbox.prototype.onBlur = function () {
  3283. domhandler_1.DomHandler.removeClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  3284. };
  3285. TableCheckbox.prototype.ngOnDestroy = function () {
  3286. if (this.subscription) {
  3287. this.subscription.unsubscribe();
  3288. }
  3289. };
  3290. __decorate([
  3291. core_1.Input(),
  3292. __metadata("design:type", Boolean)
  3293. ], TableCheckbox.prototype, "disabled", void 0);
  3294. __decorate([
  3295. core_1.Input(),
  3296. __metadata("design:type", Object)
  3297. ], TableCheckbox.prototype, "value", void 0);
  3298. __decorate([
  3299. core_1.Input(),
  3300. __metadata("design:type", Number)
  3301. ], TableCheckbox.prototype, "index", void 0);
  3302. __decorate([
  3303. core_1.ViewChild('box', { static: false }),
  3304. __metadata("design:type", core_1.ElementRef)
  3305. ], TableCheckbox.prototype, "boxViewChild", void 0);
  3306. TableCheckbox = __decorate([
  3307. core_1.Component({
  3308. selector: 'p-tableCheckbox',
  3309. template: "\n <div class=\"ui-chkbox ui-widget\" (click)=\"onClick($event)\">\n <div class=\"ui-helper-hidden-accessible\">\n <input type=\"checkbox\" [checked]=\"checked\" (focus)=\"onFocus()\" (blur)=\"onBlur()\" [disabled]=\"disabled\">\n </div>\n <div #box [ngClass]=\"{'ui-chkbox-box ui-widget ui-state-default':true,\n 'ui-state-active':checked, 'ui-state-disabled':disabled}\">\n <span class=\"ui-chkbox-icon ui-clickable\" [ngClass]=\"{'pi pi-check':checked}\"></span>\n </div>\n </div>\n "
  3310. }),
  3311. __metadata("design:paramtypes", [Table, TableService])
  3312. ], TableCheckbox);
  3313. return TableCheckbox;
  3314. }());
  3315. exports.TableCheckbox = TableCheckbox;
  3316. var TableHeaderCheckbox = /** @class */ (function () {
  3317. function TableHeaderCheckbox(dt, tableService) {
  3318. var _this = this;
  3319. this.dt = dt;
  3320. this.tableService = tableService;
  3321. this.valueChangeSubscription = this.dt.tableService.valueSource$.subscribe(function () {
  3322. _this.checked = _this.updateCheckedState();
  3323. });
  3324. this.selectionChangeSubscription = this.dt.tableService.selectionSource$.subscribe(function () {
  3325. _this.checked = _this.updateCheckedState();
  3326. });
  3327. }
  3328. TableHeaderCheckbox.prototype.ngOnInit = function () {
  3329. this.checked = this.updateCheckedState();
  3330. };
  3331. TableHeaderCheckbox.prototype.onClick = function (event) {
  3332. if (!this.disabled) {
  3333. if (this.dt.value && this.dt.value.length > 0) {
  3334. this.dt.toggleRowsWithCheckbox(event, !this.checked);
  3335. }
  3336. }
  3337. domhandler_1.DomHandler.clearSelection();
  3338. };
  3339. TableHeaderCheckbox.prototype.onFocus = function () {
  3340. domhandler_1.DomHandler.addClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  3341. };
  3342. TableHeaderCheckbox.prototype.onBlur = function () {
  3343. domhandler_1.DomHandler.removeClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  3344. };
  3345. TableHeaderCheckbox.prototype.isDisabled = function () {
  3346. return this.disabled || !this.dt.value || !this.dt.value.length;
  3347. };
  3348. TableHeaderCheckbox.prototype.ngOnDestroy = function () {
  3349. if (this.selectionChangeSubscription) {
  3350. this.selectionChangeSubscription.unsubscribe();
  3351. }
  3352. if (this.valueChangeSubscription) {
  3353. this.valueChangeSubscription.unsubscribe();
  3354. }
  3355. };
  3356. TableHeaderCheckbox.prototype.updateCheckedState = function () {
  3357. if (this.dt.filteredValue) {
  3358. var val = this.dt.filteredValue;
  3359. return (val && val.length > 0 && this.dt.selection && this.dt.selection.length > 0 && this.isAllFilteredValuesChecked());
  3360. }
  3361. else {
  3362. var val = this.dt.value;
  3363. return (val && val.length > 0 && this.dt.selection && this.dt.selection.length > 0 && this.dt.selection.length === val.length);
  3364. }
  3365. };
  3366. TableHeaderCheckbox.prototype.isAllFilteredValuesChecked = function () {
  3367. if (!this.dt.filteredValue) {
  3368. return false;
  3369. }
  3370. else {
  3371. for (var _i = 0, _a = this.dt.filteredValue; _i < _a.length; _i++) {
  3372. var rowData = _a[_i];
  3373. if (!this.dt.isSelected(rowData)) {
  3374. return false;
  3375. }
  3376. }
  3377. return true;
  3378. }
  3379. };
  3380. __decorate([
  3381. core_1.ViewChild('box', { static: false }),
  3382. __metadata("design:type", core_1.ElementRef)
  3383. ], TableHeaderCheckbox.prototype, "boxViewChild", void 0);
  3384. __decorate([
  3385. core_1.Input(),
  3386. __metadata("design:type", Boolean)
  3387. ], TableHeaderCheckbox.prototype, "disabled", void 0);
  3388. TableHeaderCheckbox = __decorate([
  3389. core_1.Component({
  3390. selector: 'p-tableHeaderCheckbox',
  3391. template: "\n <div class=\"ui-chkbox ui-widget\" (click)=\"onClick($event)\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #cb type=\"checkbox\" [checked]=\"checked\" (focus)=\"onFocus()\" (blur)=\"onBlur()\" [disabled]=\"isDisabled()\">\n </div>\n <div #box [ngClass]=\"{'ui-chkbox-box ui-widget ui-state-default':true,\n 'ui-state-active':checked, 'ui-state-disabled': isDisabled()}\">\n <span class=\"ui-chkbox-icon ui-clickable\" [ngClass]=\"{'pi pi-check':checked}\"></span>\n </div>\n </div>\n "
  3392. }),
  3393. __metadata("design:paramtypes", [Table, TableService])
  3394. ], TableHeaderCheckbox);
  3395. return TableHeaderCheckbox;
  3396. }());
  3397. exports.TableHeaderCheckbox = TableHeaderCheckbox;
  3398. var ReorderableRowHandle = /** @class */ (function () {
  3399. function ReorderableRowHandle(el) {
  3400. this.el = el;
  3401. }
  3402. ReorderableRowHandle.prototype.ngAfterViewInit = function () {
  3403. domhandler_1.DomHandler.addClass(this.el.nativeElement, 'ui-table-reorderablerow-handle');
  3404. };
  3405. __decorate([
  3406. core_1.Input("pReorderableRowHandle"),
  3407. __metadata("design:type", Number)
  3408. ], ReorderableRowHandle.prototype, "index", void 0);
  3409. ReorderableRowHandle = __decorate([
  3410. core_1.Directive({
  3411. selector: '[pReorderableRowHandle]'
  3412. }),
  3413. __metadata("design:paramtypes", [core_1.ElementRef])
  3414. ], ReorderableRowHandle);
  3415. return ReorderableRowHandle;
  3416. }());
  3417. exports.ReorderableRowHandle = ReorderableRowHandle;
  3418. var ReorderableRow = /** @class */ (function () {
  3419. function ReorderableRow(dt, el, zone) {
  3420. this.dt = dt;
  3421. this.el = el;
  3422. this.zone = zone;
  3423. }
  3424. ReorderableRow.prototype.ngAfterViewInit = function () {
  3425. if (this.isEnabled()) {
  3426. this.el.nativeElement.droppable = true;
  3427. this.bindEvents();
  3428. }
  3429. };
  3430. ReorderableRow.prototype.bindEvents = function () {
  3431. var _this = this;
  3432. this.zone.runOutsideAngular(function () {
  3433. _this.mouseDownListener = _this.onMouseDown.bind(_this);
  3434. _this.el.nativeElement.addEventListener('mousedown', _this.mouseDownListener);
  3435. _this.dragStartListener = _this.onDragStart.bind(_this);
  3436. _this.el.nativeElement.addEventListener('dragstart', _this.dragStartListener);
  3437. _this.dragEndListener = _this.onDragEnd.bind(_this);
  3438. _this.el.nativeElement.addEventListener('dragend', _this.dragEndListener);
  3439. _this.dragOverListener = _this.onDragOver.bind(_this);
  3440. _this.el.nativeElement.addEventListener('dragover', _this.dragOverListener);
  3441. _this.dragLeaveListener = _this.onDragLeave.bind(_this);
  3442. _this.el.nativeElement.addEventListener('dragleave', _this.dragLeaveListener);
  3443. });
  3444. };
  3445. ReorderableRow.prototype.unbindEvents = function () {
  3446. if (this.mouseDownListener) {
  3447. document.removeEventListener('mousedown', this.mouseDownListener);
  3448. this.mouseDownListener = null;
  3449. }
  3450. if (this.dragStartListener) {
  3451. document.removeEventListener('dragstart', this.dragStartListener);
  3452. this.dragStartListener = null;
  3453. }
  3454. if (this.dragEndListener) {
  3455. document.removeEventListener('dragend', this.dragEndListener);
  3456. this.dragEndListener = null;
  3457. }
  3458. if (this.dragOverListener) {
  3459. document.removeEventListener('dragover', this.dragOverListener);
  3460. this.dragOverListener = null;
  3461. }
  3462. if (this.dragLeaveListener) {
  3463. document.removeEventListener('dragleave', this.dragLeaveListener);
  3464. this.dragLeaveListener = null;
  3465. }
  3466. };
  3467. ReorderableRow.prototype.onMouseDown = function (event) {
  3468. if (domhandler_1.DomHandler.hasClass(event.target, 'ui-table-reorderablerow-handle'))
  3469. this.el.nativeElement.draggable = true;
  3470. else
  3471. this.el.nativeElement.draggable = false;
  3472. };
  3473. ReorderableRow.prototype.onDragStart = function (event) {
  3474. this.dt.onRowDragStart(event, this.index);
  3475. };
  3476. ReorderableRow.prototype.onDragEnd = function (event) {
  3477. this.dt.onRowDragEnd(event);
  3478. this.el.nativeElement.draggable = false;
  3479. };
  3480. ReorderableRow.prototype.onDragOver = function (event) {
  3481. this.dt.onRowDragOver(event, this.index, this.el.nativeElement);
  3482. event.preventDefault();
  3483. };
  3484. ReorderableRow.prototype.onDragLeave = function (event) {
  3485. this.dt.onRowDragLeave(event, this.el.nativeElement);
  3486. };
  3487. ReorderableRow.prototype.isEnabled = function () {
  3488. return this.pReorderableRowDisabled !== true;
  3489. };
  3490. ReorderableRow.prototype.onDrop = function (event) {
  3491. if (this.isEnabled() && this.dt.rowDragging) {
  3492. this.dt.onRowDrop(event, this.el.nativeElement);
  3493. }
  3494. event.preventDefault();
  3495. };
  3496. __decorate([
  3497. core_1.Input("pReorderableRow"),
  3498. __metadata("design:type", Number)
  3499. ], ReorderableRow.prototype, "index", void 0);
  3500. __decorate([
  3501. core_1.Input(),
  3502. __metadata("design:type", Boolean)
  3503. ], ReorderableRow.prototype, "pReorderableRowDisabled", void 0);
  3504. __decorate([
  3505. core_1.HostListener('drop', ['$event']),
  3506. __metadata("design:type", Function),
  3507. __metadata("design:paramtypes", [Object]),
  3508. __metadata("design:returntype", void 0)
  3509. ], ReorderableRow.prototype, "onDrop", null);
  3510. ReorderableRow = __decorate([
  3511. core_1.Directive({
  3512. selector: '[pReorderableRow]'
  3513. }),
  3514. __metadata("design:paramtypes", [Table, core_1.ElementRef, core_1.NgZone])
  3515. ], ReorderableRow);
  3516. return ReorderableRow;
  3517. }());
  3518. exports.ReorderableRow = ReorderableRow;
  3519. var TableModule = /** @class */ (function () {
  3520. function TableModule() {
  3521. }
  3522. TableModule = __decorate([
  3523. core_1.NgModule({
  3524. imports: [common_1.CommonModule, paginator_1.PaginatorModule],
  3525. exports: [Table, shared_1.SharedModule, SortableColumn, SelectableRow, RowToggler, ContextMenuRow, ResizableColumn, ReorderableColumn, EditableColumn, CellEditor, SortIcon, TableRadioButton, TableCheckbox, TableHeaderCheckbox, ReorderableRowHandle, ReorderableRow, SelectableRowDblClick, EditableRow, InitEditableRow, SaveEditableRow, CancelEditableRow],
  3526. declarations: [Table, SortableColumn, SelectableRow, RowToggler, ContextMenuRow, ResizableColumn, ReorderableColumn, EditableColumn, CellEditor, TableBody, ScrollableView, SortIcon, TableRadioButton, TableCheckbox, TableHeaderCheckbox, ReorderableRowHandle, ReorderableRow, SelectableRowDblClick, EditableRow, InitEditableRow, SaveEditableRow, CancelEditableRow]
  3527. })
  3528. ], TableModule);
  3529. return TableModule;
  3530. }());
  3531. exports.TableModule = TableModule;
  3532. //# sourceMappingURL=table.js.map