treetable.js 124 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  15. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  16. 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;
  17. return c > 3 && r && Object.defineProperty(target, key, r), r;
  18. };
  19. var __metadata = (this && this.__metadata) || function (k, v) {
  20. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  21. };
  22. Object.defineProperty(exports, "__esModule", { value: true });
  23. var core_1 = require("@angular/core");
  24. var common_1 = require("@angular/common");
  25. var rxjs_1 = require("rxjs");
  26. var domhandler_1 = require("../dom/domhandler");
  27. var paginator_1 = require("../paginator/paginator");
  28. var shared_1 = require("../common/shared");
  29. var objectutils_1 = require("../utils/objectutils");
  30. var filterutils_1 = require("../utils/filterutils");
  31. var TreeTableService = /** @class */ (function () {
  32. function TreeTableService() {
  33. this.sortSource = new rxjs_1.Subject();
  34. this.selectionSource = new rxjs_1.Subject();
  35. this.contextMenuSource = new rxjs_1.Subject();
  36. this.uiUpdateSource = new rxjs_1.Subject();
  37. this.totalRecordsSource = new rxjs_1.Subject();
  38. this.sortSource$ = this.sortSource.asObservable();
  39. this.selectionSource$ = this.selectionSource.asObservable();
  40. this.contextMenuSource$ = this.contextMenuSource.asObservable();
  41. this.uiUpdateSource$ = this.uiUpdateSource.asObservable();
  42. this.totalRecordsSource$ = this.totalRecordsSource.asObservable();
  43. }
  44. TreeTableService.prototype.onSort = function (sortMeta) {
  45. this.sortSource.next(sortMeta);
  46. };
  47. TreeTableService.prototype.onSelectionChange = function () {
  48. this.selectionSource.next();
  49. };
  50. TreeTableService.prototype.onContextMenu = function (node) {
  51. this.contextMenuSource.next(node);
  52. };
  53. TreeTableService.prototype.onUIUpdate = function (value) {
  54. this.uiUpdateSource.next(value);
  55. };
  56. TreeTableService.prototype.onTotalRecordsChange = function (value) {
  57. this.totalRecordsSource.next(value);
  58. };
  59. TreeTableService = __decorate([
  60. core_1.Injectable()
  61. ], TreeTableService);
  62. return TreeTableService;
  63. }());
  64. exports.TreeTableService = TreeTableService;
  65. var TreeTable = /** @class */ (function () {
  66. function TreeTable(el, zone, tableService) {
  67. this.el = el;
  68. this.zone = zone;
  69. this.tableService = tableService;
  70. this.lazy = false;
  71. this.first = 0;
  72. this.pageLinks = 5;
  73. this.alwaysShowPaginator = true;
  74. this.paginatorPosition = 'bottom';
  75. this.defaultSortOrder = 1;
  76. this.sortMode = 'single';
  77. this.resetPageOnSort = true;
  78. this.selectionChange = new core_1.EventEmitter();
  79. this.contextMenuSelectionChange = new core_1.EventEmitter();
  80. this.contextMenuSelectionMode = "separate";
  81. this.compareSelectionBy = 'deepEquals';
  82. this.loadingIcon = 'pi pi-spinner';
  83. this.showLoader = true;
  84. this.virtualScrollDelay = 150;
  85. this.virtualRowHeight = 28;
  86. this.columnResizeMode = 'fit';
  87. this.rowTrackBy = function (index, item) { return item; };
  88. this.filters = {};
  89. this.filterDelay = 300;
  90. this.filterMode = 'lenient';
  91. this.onFilter = new core_1.EventEmitter();
  92. this.onNodeExpand = new core_1.EventEmitter();
  93. this.onNodeCollapse = new core_1.EventEmitter();
  94. this.onPage = new core_1.EventEmitter();
  95. this.onSort = new core_1.EventEmitter();
  96. this.onLazyLoad = new core_1.EventEmitter();
  97. this.sortFunction = new core_1.EventEmitter();
  98. this.onColResize = new core_1.EventEmitter();
  99. this.onColReorder = new core_1.EventEmitter();
  100. this.onNodeSelect = new core_1.EventEmitter();
  101. this.onNodeUnselect = new core_1.EventEmitter();
  102. this.onContextMenuSelect = new core_1.EventEmitter();
  103. this.onHeaderCheckboxToggle = new core_1.EventEmitter();
  104. this.onEditInit = new core_1.EventEmitter();
  105. this.onEditComplete = new core_1.EventEmitter();
  106. this.onEditCancel = new core_1.EventEmitter();
  107. this._value = [];
  108. this._totalRecords = 0;
  109. this._sortOrder = 1;
  110. this.selectionKeys = {};
  111. }
  112. TreeTable.prototype.ngOnInit = function () {
  113. if (this.lazy) {
  114. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  115. }
  116. this.initialized = true;
  117. };
  118. TreeTable.prototype.ngAfterContentInit = function () {
  119. var _this = this;
  120. this.templates.forEach(function (item) {
  121. switch (item.getType()) {
  122. case 'caption':
  123. _this.captionTemplate = item.template;
  124. break;
  125. case 'header':
  126. _this.headerTemplate = item.template;
  127. break;
  128. case 'body':
  129. _this.bodyTemplate = item.template;
  130. break;
  131. case 'loadingbody':
  132. _this.loadingBodyTemplate = item.template;
  133. break;
  134. case 'footer':
  135. _this.footerTemplate = item.template;
  136. break;
  137. case 'summary':
  138. _this.summaryTemplate = item.template;
  139. break;
  140. case 'colgroup':
  141. _this.colGroupTemplate = item.template;
  142. break;
  143. case 'emptymessage':
  144. _this.emptyMessageTemplate = item.template;
  145. break;
  146. case 'paginatorleft':
  147. _this.paginatorLeftTemplate = item.template;
  148. break;
  149. case 'paginatorright':
  150. _this.paginatorRightTemplate = item.template;
  151. break;
  152. case 'frozenheader':
  153. _this.frozenHeaderTemplate = item.template;
  154. break;
  155. case 'frozenbody':
  156. _this.frozenBodyTemplate = item.template;
  157. break;
  158. case 'frozenfooter':
  159. _this.frozenFooterTemplate = item.template;
  160. break;
  161. case 'frozencolgroup':
  162. _this.frozenColGroupTemplate = item.template;
  163. break;
  164. }
  165. });
  166. };
  167. Object.defineProperty(TreeTable.prototype, "value", {
  168. get: function () {
  169. return this._value;
  170. },
  171. set: function (val) {
  172. this._value = val;
  173. if (!this.lazy) {
  174. this.totalRecords = (this._value ? this._value.length : 0);
  175. if (this.sortMode == 'single' && this.sortField)
  176. this.sortSingle();
  177. else if (this.sortMode == 'multiple' && this.multiSortMeta)
  178. this.sortMultiple();
  179. else if (this.hasFilter()) //sort already filters
  180. this._filter();
  181. }
  182. if (this.virtualScroll && this.virtualScrollCallback) {
  183. this.virtualScrollCallback();
  184. }
  185. this.updateSerializedValue();
  186. this.tableService.onUIUpdate(this.value);
  187. },
  188. enumerable: true,
  189. configurable: true
  190. });
  191. TreeTable.prototype.updateSerializedValue = function () {
  192. this.serializedValue = [];
  193. if (this.paginator)
  194. this.serializePageNodes();
  195. else
  196. this.serializeNodes(null, this.filteredNodes || this.value, 0, true);
  197. };
  198. TreeTable.prototype.serializeNodes = function (parent, nodes, level, visible) {
  199. if (nodes && nodes.length) {
  200. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  201. var node = nodes_1[_i];
  202. node.parent = parent;
  203. var rowNode = {
  204. node: node,
  205. parent: parent,
  206. level: level,
  207. visible: visible && (parent ? parent.expanded : true)
  208. };
  209. this.serializedValue.push(rowNode);
  210. if (rowNode.visible && node.expanded) {
  211. this.serializeNodes(node, node.children, level + 1, rowNode.visible);
  212. }
  213. }
  214. }
  215. };
  216. TreeTable.prototype.serializePageNodes = function () {
  217. var data = this.filteredNodes || this.value;
  218. this.serializedValue = [];
  219. if (data && data.length) {
  220. var first = this.lazy ? 0 : this.first;
  221. for (var i = first; i < (first + this.rows); i++) {
  222. var node = data[i];
  223. if (node) {
  224. this.serializedValue.push({
  225. node: node,
  226. parent: null,
  227. level: 0,
  228. visible: true
  229. });
  230. this.serializeNodes(node, node.children, 1, true);
  231. }
  232. }
  233. }
  234. };
  235. Object.defineProperty(TreeTable.prototype, "totalRecords", {
  236. get: function () {
  237. return this._totalRecords;
  238. },
  239. set: function (val) {
  240. this._totalRecords = val;
  241. this.tableService.onTotalRecordsChange(this._totalRecords);
  242. },
  243. enumerable: true,
  244. configurable: true
  245. });
  246. Object.defineProperty(TreeTable.prototype, "sortField", {
  247. get: function () {
  248. return this._sortField;
  249. },
  250. set: function (val) {
  251. this._sortField = val;
  252. //avoid triggering lazy load prior to lazy initialization at onInit
  253. if (!this.lazy || this.initialized) {
  254. if (this.sortMode === 'single') {
  255. this.sortSingle();
  256. }
  257. }
  258. },
  259. enumerable: true,
  260. configurable: true
  261. });
  262. Object.defineProperty(TreeTable.prototype, "sortOrder", {
  263. get: function () {
  264. return this._sortOrder;
  265. },
  266. set: function (val) {
  267. this._sortOrder = val;
  268. //avoid triggering lazy load prior to lazy initialization at onInit
  269. if (!this.lazy || this.initialized) {
  270. if (this.sortMode === 'single') {
  271. this.sortSingle();
  272. }
  273. }
  274. },
  275. enumerable: true,
  276. configurable: true
  277. });
  278. Object.defineProperty(TreeTable.prototype, "multiSortMeta", {
  279. get: function () {
  280. return this._multiSortMeta;
  281. },
  282. set: function (val) {
  283. this._multiSortMeta = val;
  284. if (this.sortMode === 'multiple') {
  285. this.sortMultiple();
  286. }
  287. },
  288. enumerable: true,
  289. configurable: true
  290. });
  291. Object.defineProperty(TreeTable.prototype, "selection", {
  292. get: function () {
  293. return this._selection;
  294. },
  295. set: function (val) {
  296. this._selection = val;
  297. if (!this.preventSelectionSetterPropagation) {
  298. this.updateSelectionKeys();
  299. this.tableService.onSelectionChange();
  300. }
  301. this.preventSelectionSetterPropagation = false;
  302. },
  303. enumerable: true,
  304. configurable: true
  305. });
  306. TreeTable.prototype.updateSelectionKeys = function () {
  307. if (this.dataKey && this._selection) {
  308. this.selectionKeys = {};
  309. if (Array.isArray(this._selection)) {
  310. for (var _i = 0, _a = this._selection; _i < _a.length; _i++) {
  311. var node = _a[_i];
  312. this.selectionKeys[String(objectutils_1.ObjectUtils.resolveFieldData(node.data, this.dataKey))] = 1;
  313. }
  314. }
  315. else {
  316. this.selectionKeys[String(objectutils_1.ObjectUtils.resolveFieldData(this._selection.data, this.dataKey))] = 1;
  317. }
  318. }
  319. };
  320. TreeTable.prototype.onPageChange = function (event) {
  321. this.first = event.first;
  322. this.rows = event.rows;
  323. if (this.lazy)
  324. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  325. else
  326. this.serializePageNodes();
  327. this.onPage.emit({
  328. first: this.first,
  329. rows: this.rows
  330. });
  331. this.tableService.onUIUpdate(this.value);
  332. };
  333. TreeTable.prototype.sort = function (event) {
  334. var originalEvent = event.originalEvent;
  335. if (this.sortMode === 'single') {
  336. this._sortOrder = (this.sortField === event.field) ? this.sortOrder * -1 : this.defaultSortOrder;
  337. this._sortField = event.field;
  338. this.sortSingle();
  339. }
  340. if (this.sortMode === 'multiple') {
  341. var metaKey = originalEvent.metaKey || originalEvent.ctrlKey;
  342. var sortMeta = this.getSortMeta(event.field);
  343. if (sortMeta) {
  344. if (!metaKey) {
  345. this._multiSortMeta = [{ field: event.field, order: sortMeta.order * -1 }];
  346. }
  347. else {
  348. sortMeta.order = sortMeta.order * -1;
  349. }
  350. }
  351. else {
  352. if (!metaKey || !this.multiSortMeta) {
  353. this._multiSortMeta = [];
  354. }
  355. this.multiSortMeta.push({ field: event.field, order: this.defaultSortOrder });
  356. }
  357. this.sortMultiple();
  358. }
  359. };
  360. TreeTable.prototype.sortSingle = function () {
  361. if (this.sortField && this.sortOrder) {
  362. if (this.resetPageOnSort) {
  363. this.first = 0;
  364. }
  365. if (this.lazy) {
  366. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  367. }
  368. else if (this.value) {
  369. this.sortNodes(this.value);
  370. if (this.hasFilter()) {
  371. this._filter();
  372. }
  373. }
  374. var sortMeta = {
  375. field: this.sortField,
  376. order: this.sortOrder
  377. };
  378. this.onSort.emit(sortMeta);
  379. this.tableService.onSort(sortMeta);
  380. this.updateSerializedValue();
  381. }
  382. };
  383. TreeTable.prototype.sortNodes = function (nodes) {
  384. var _this = this;
  385. if (!nodes || nodes.length === 0) {
  386. return;
  387. }
  388. if (this.customSort) {
  389. this.sortFunction.emit({
  390. data: nodes,
  391. mode: this.sortMode,
  392. field: this.sortField,
  393. order: this.sortOrder
  394. });
  395. }
  396. else {
  397. nodes.sort(function (node1, node2) {
  398. var value1 = objectutils_1.ObjectUtils.resolveFieldData(node1.data, _this.sortField);
  399. var value2 = objectutils_1.ObjectUtils.resolveFieldData(node2.data, _this.sortField);
  400. var result = null;
  401. if (value1 == null && value2 != null)
  402. result = -1;
  403. else if (value1 != null && value2 == null)
  404. result = 1;
  405. else if (value1 == null && value2 == null)
  406. result = 0;
  407. else if (typeof value1 === 'string' && typeof value2 === 'string')
  408. result = value1.localeCompare(value2, undefined, { numeric: true });
  409. else
  410. result = (value1 < value2) ? -1 : (value1 > value2) ? 1 : 0;
  411. return (_this.sortOrder * result);
  412. });
  413. }
  414. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  415. var node = nodes_2[_i];
  416. this.sortNodes(node.children);
  417. }
  418. };
  419. TreeTable.prototype.sortMultiple = function () {
  420. if (this.multiSortMeta) {
  421. if (this.lazy) {
  422. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  423. }
  424. else if (this.value) {
  425. this.sortMultipleNodes(this.value);
  426. if (this.hasFilter()) {
  427. this._filter();
  428. }
  429. }
  430. this.onSort.emit({
  431. multisortmeta: this.multiSortMeta
  432. });
  433. this.tableService.onSort(this.multiSortMeta);
  434. this.updateSerializedValue();
  435. }
  436. };
  437. TreeTable.prototype.sortMultipleNodes = function (nodes) {
  438. var _this = this;
  439. if (!nodes || nodes.length === 0) {
  440. return;
  441. }
  442. if (this.customSort) {
  443. this.sortFunction.emit({
  444. data: this.value,
  445. mode: this.sortMode,
  446. multiSortMeta: this.multiSortMeta
  447. });
  448. }
  449. else {
  450. this.value.sort(function (node1, node2) {
  451. return _this.multisortField(node1, node2, _this.multiSortMeta, 0);
  452. });
  453. }
  454. for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
  455. var node = nodes_3[_i];
  456. this.sortMultipleNodes(node.children);
  457. }
  458. };
  459. TreeTable.prototype.multisortField = function (node1, node2, multiSortMeta, index) {
  460. var value1 = objectutils_1.ObjectUtils.resolveFieldData(node1.data, multiSortMeta[index].field);
  461. var value2 = objectutils_1.ObjectUtils.resolveFieldData(node2.data, multiSortMeta[index].field);
  462. var result = null;
  463. if (value1 == null && value2 != null)
  464. result = -1;
  465. else if (value1 != null && value2 == null)
  466. result = 1;
  467. else if (value1 == null && value2 == null)
  468. result = 0;
  469. if (typeof value1 == 'string' || value1 instanceof String) {
  470. if (value1.localeCompare && (value1 != value2)) {
  471. return (multiSortMeta[index].order * value1.localeCompare(value2, undefined, { numeric: true }));
  472. }
  473. }
  474. else {
  475. result = (value1 < value2) ? -1 : 1;
  476. }
  477. if (value1 == value2) {
  478. return (multiSortMeta.length - 1) > (index) ? (this.multisortField(node1, node2, multiSortMeta, index + 1)) : 0;
  479. }
  480. return (multiSortMeta[index].order * result);
  481. };
  482. TreeTable.prototype.getSortMeta = function (field) {
  483. if (this.multiSortMeta && this.multiSortMeta.length) {
  484. for (var i = 0; i < this.multiSortMeta.length; i++) {
  485. if (this.multiSortMeta[i].field === field) {
  486. return this.multiSortMeta[i];
  487. }
  488. }
  489. }
  490. return null;
  491. };
  492. TreeTable.prototype.isSorted = function (field) {
  493. if (this.sortMode === 'single') {
  494. return (this.sortField && this.sortField === field);
  495. }
  496. else if (this.sortMode === 'multiple') {
  497. var sorted = false;
  498. if (this.multiSortMeta) {
  499. for (var i = 0; i < this.multiSortMeta.length; i++) {
  500. if (this.multiSortMeta[i].field == field) {
  501. sorted = true;
  502. break;
  503. }
  504. }
  505. }
  506. return sorted;
  507. }
  508. };
  509. TreeTable.prototype.createLazyLoadMetadata = function () {
  510. return {
  511. first: this.first,
  512. rows: this.virtualScroll ? this.rows * 2 : this.rows,
  513. sortField: this.sortField,
  514. sortOrder: this.sortOrder,
  515. filters: this.filters,
  516. globalFilter: this.filters && this.filters['global'] ? this.filters['global'].value : null,
  517. multiSortMeta: this.multiSortMeta
  518. };
  519. };
  520. TreeTable.prototype.handleVirtualScroll = function (event) {
  521. var _this = this;
  522. this.first = (event.page - 1) * this.rows;
  523. this.virtualScrollCallback = event.callback;
  524. this.zone.run(function () {
  525. if (_this.virtualScrollTimer) {
  526. clearTimeout(_this.virtualScrollTimer);
  527. }
  528. _this.virtualScrollTimer = setTimeout(function () {
  529. _this.onLazyLoad.emit(_this.createLazyLoadMetadata());
  530. }, _this.virtualScrollDelay);
  531. });
  532. };
  533. TreeTable.prototype.isEmpty = function () {
  534. var data = this.filteredNodes || this.value;
  535. return data == null || data.length == 0;
  536. };
  537. TreeTable.prototype.getBlockableElement = function () {
  538. return this.el.nativeElement.children[0];
  539. };
  540. TreeTable.prototype.onColumnResizeBegin = function (event) {
  541. var containerLeft = domhandler_1.DomHandler.getOffset(this.containerViewChild.nativeElement).left;
  542. this.lastResizerHelperX = (event.pageX - containerLeft + this.containerViewChild.nativeElement.scrollLeft);
  543. event.preventDefault();
  544. };
  545. TreeTable.prototype.onColumnResize = function (event) {
  546. var containerLeft = domhandler_1.DomHandler.getOffset(this.containerViewChild.nativeElement).left;
  547. domhandler_1.DomHandler.addClass(this.containerViewChild.nativeElement, 'ui-unselectable-text');
  548. this.resizeHelperViewChild.nativeElement.style.height = this.containerViewChild.nativeElement.offsetHeight + 'px';
  549. this.resizeHelperViewChild.nativeElement.style.top = 0 + 'px';
  550. this.resizeHelperViewChild.nativeElement.style.left = (event.pageX - containerLeft + this.containerViewChild.nativeElement.scrollLeft) + 'px';
  551. this.resizeHelperViewChild.nativeElement.style.display = 'block';
  552. };
  553. TreeTable.prototype.onColumnResizeEnd = function (event, column) {
  554. var delta = this.resizeHelperViewChild.nativeElement.offsetLeft - this.lastResizerHelperX;
  555. var columnWidth = column.offsetWidth;
  556. var newColumnWidth = columnWidth + delta;
  557. var minWidth = column.style.minWidth || 15;
  558. if (columnWidth + delta > parseInt(minWidth)) {
  559. if (this.columnResizeMode === 'fit') {
  560. var nextColumn = column.nextElementSibling;
  561. while (!nextColumn.offsetParent) {
  562. nextColumn = nextColumn.nextElementSibling;
  563. }
  564. if (nextColumn) {
  565. var nextColumnWidth = nextColumn.offsetWidth - delta;
  566. var nextColumnMinWidth = nextColumn.style.minWidth || 15;
  567. if (newColumnWidth > 15 && nextColumnWidth > parseInt(nextColumnMinWidth)) {
  568. if (this.scrollable) {
  569. var scrollableView = this.findParentScrollableView(column);
  570. var scrollableBodyTable = domhandler_1.DomHandler.findSingle(scrollableView, 'table.ui-treetable-scrollable-body-table');
  571. var scrollableHeaderTable = domhandler_1.DomHandler.findSingle(scrollableView, 'table.ui-treetable-scrollable-header-table');
  572. var scrollableFooterTable = domhandler_1.DomHandler.findSingle(scrollableView, 'table.ui-treetable-scrollable-footer-table');
  573. var resizeColumnIndex = domhandler_1.DomHandler.index(column);
  574. this.resizeColGroup(scrollableHeaderTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
  575. this.resizeColGroup(scrollableBodyTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
  576. this.resizeColGroup(scrollableFooterTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
  577. }
  578. else {
  579. column.style.width = newColumnWidth + 'px';
  580. if (nextColumn) {
  581. nextColumn.style.width = nextColumnWidth + 'px';
  582. }
  583. }
  584. }
  585. }
  586. }
  587. else if (this.columnResizeMode === 'expand') {
  588. if (this.scrollable) {
  589. var scrollableView = this.findParentScrollableView(column);
  590. var scrollableBodyTable = domhandler_1.DomHandler.findSingle(scrollableView, 'table.ui-treetable-scrollable-body-table');
  591. var scrollableHeaderTable = domhandler_1.DomHandler.findSingle(scrollableView, 'table.ui-treetable-scrollable-header-table');
  592. var scrollableFooterTable = domhandler_1.DomHandler.findSingle(scrollableView, 'table.ui-treetable-scrollable-footer-table');
  593. scrollableBodyTable.style.width = scrollableBodyTable.offsetWidth + delta + 'px';
  594. scrollableHeaderTable.style.width = scrollableHeaderTable.offsetWidth + delta + 'px';
  595. if (scrollableFooterTable) {
  596. scrollableFooterTable.style.width = scrollableHeaderTable.offsetWidth + delta + 'px';
  597. }
  598. var resizeColumnIndex = domhandler_1.DomHandler.index(column);
  599. this.resizeColGroup(scrollableHeaderTable, resizeColumnIndex, newColumnWidth, null);
  600. this.resizeColGroup(scrollableBodyTable, resizeColumnIndex, newColumnWidth, null);
  601. this.resizeColGroup(scrollableFooterTable, resizeColumnIndex, newColumnWidth, null);
  602. }
  603. else {
  604. this.tableViewChild.nativeElement.style.width = this.tableViewChild.nativeElement.offsetWidth + delta + 'px';
  605. column.style.width = newColumnWidth + 'px';
  606. var containerWidth = this.tableViewChild.nativeElement.style.width;
  607. this.containerViewChild.nativeElement.style.width = containerWidth + 'px';
  608. }
  609. }
  610. this.onColResize.emit({
  611. element: column,
  612. delta: delta
  613. });
  614. }
  615. this.resizeHelperViewChild.nativeElement.style.display = 'none';
  616. domhandler_1.DomHandler.removeClass(this.containerViewChild.nativeElement, 'ui-unselectable-text');
  617. };
  618. TreeTable.prototype.findParentScrollableView = function (column) {
  619. if (column) {
  620. var parent_1 = column.parentElement;
  621. while (parent_1 && !domhandler_1.DomHandler.hasClass(parent_1, 'ui-treetable-scrollable-view')) {
  622. parent_1 = parent_1.parentElement;
  623. }
  624. return parent_1;
  625. }
  626. else {
  627. return null;
  628. }
  629. };
  630. TreeTable.prototype.resizeColGroup = function (table, resizeColumnIndex, newColumnWidth, nextColumnWidth) {
  631. if (table) {
  632. var colGroup = table.children[0].nodeName === 'COLGROUP' ? table.children[0] : null;
  633. if (colGroup) {
  634. var col = colGroup.children[resizeColumnIndex];
  635. var nextCol = col.nextElementSibling;
  636. col.style.width = newColumnWidth + 'px';
  637. if (nextCol && nextColumnWidth) {
  638. nextCol.style.width = nextColumnWidth + 'px';
  639. }
  640. }
  641. else {
  642. throw "Scrollable tables require a colgroup to support resizable columns";
  643. }
  644. }
  645. };
  646. TreeTable.prototype.onColumnDragStart = function (event, columnElement) {
  647. this.reorderIconWidth = domhandler_1.DomHandler.getHiddenElementOuterWidth(this.reorderIndicatorUpViewChild.nativeElement);
  648. this.reorderIconHeight = domhandler_1.DomHandler.getHiddenElementOuterHeight(this.reorderIndicatorDownViewChild.nativeElement);
  649. this.draggedColumn = columnElement;
  650. event.dataTransfer.setData('text', 'b'); // For firefox
  651. };
  652. TreeTable.prototype.onColumnDragEnter = function (event, dropHeader) {
  653. if (this.reorderableColumns && this.draggedColumn && dropHeader) {
  654. event.preventDefault();
  655. var containerOffset = domhandler_1.DomHandler.getOffset(this.containerViewChild.nativeElement);
  656. var dropHeaderOffset = domhandler_1.DomHandler.getOffset(dropHeader);
  657. if (this.draggedColumn != dropHeader) {
  658. var targetLeft = dropHeaderOffset.left - containerOffset.left;
  659. var targetTop = containerOffset.top - dropHeaderOffset.top;
  660. var columnCenter = dropHeaderOffset.left + dropHeader.offsetWidth / 2;
  661. this.reorderIndicatorUpViewChild.nativeElement.style.top = dropHeaderOffset.top - containerOffset.top - (this.reorderIconHeight - 1) + 'px';
  662. this.reorderIndicatorDownViewChild.nativeElement.style.top = dropHeaderOffset.top - containerOffset.top + dropHeader.offsetHeight + 'px';
  663. if (event.pageX > columnCenter) {
  664. this.reorderIndicatorUpViewChild.nativeElement.style.left = (targetLeft + dropHeader.offsetWidth - Math.ceil(this.reorderIconWidth / 2)) + 'px';
  665. this.reorderIndicatorDownViewChild.nativeElement.style.left = (targetLeft + dropHeader.offsetWidth - Math.ceil(this.reorderIconWidth / 2)) + 'px';
  666. this.dropPosition = 1;
  667. }
  668. else {
  669. this.reorderIndicatorUpViewChild.nativeElement.style.left = (targetLeft - Math.ceil(this.reorderIconWidth / 2)) + 'px';
  670. this.reorderIndicatorDownViewChild.nativeElement.style.left = (targetLeft - Math.ceil(this.reorderIconWidth / 2)) + 'px';
  671. this.dropPosition = -1;
  672. }
  673. this.reorderIndicatorUpViewChild.nativeElement.style.display = 'block';
  674. this.reorderIndicatorDownViewChild.nativeElement.style.display = 'block';
  675. }
  676. else {
  677. event.dataTransfer.dropEffect = 'none';
  678. }
  679. }
  680. };
  681. TreeTable.prototype.onColumnDragLeave = function (event) {
  682. if (this.reorderableColumns && this.draggedColumn) {
  683. event.preventDefault();
  684. this.reorderIndicatorUpViewChild.nativeElement.style.display = 'none';
  685. this.reorderIndicatorDownViewChild.nativeElement.style.display = 'none';
  686. }
  687. };
  688. TreeTable.prototype.onColumnDrop = function (event, dropColumn) {
  689. event.preventDefault();
  690. if (this.draggedColumn) {
  691. var dragIndex = domhandler_1.DomHandler.indexWithinGroup(this.draggedColumn, 'ttreorderablecolumn');
  692. var dropIndex = domhandler_1.DomHandler.indexWithinGroup(dropColumn, 'ttreorderablecolumn');
  693. var allowDrop = (dragIndex != dropIndex);
  694. if (allowDrop && ((dropIndex - dragIndex == 1 && this.dropPosition === -1) || (dragIndex - dropIndex == 1 && this.dropPosition === 1))) {
  695. allowDrop = false;
  696. }
  697. if (allowDrop && ((dropIndex < dragIndex && this.dropPosition === 1))) {
  698. dropIndex = dropIndex + 1;
  699. }
  700. if (allowDrop && ((dropIndex > dragIndex && this.dropPosition === -1))) {
  701. dropIndex = dropIndex - 1;
  702. }
  703. if (allowDrop) {
  704. objectutils_1.ObjectUtils.reorderArray(this.columns, dragIndex, dropIndex);
  705. this.onColReorder.emit({
  706. dragIndex: dragIndex,
  707. dropIndex: dropIndex,
  708. columns: this.columns
  709. });
  710. }
  711. this.reorderIndicatorUpViewChild.nativeElement.style.display = 'none';
  712. this.reorderIndicatorDownViewChild.nativeElement.style.display = 'none';
  713. this.draggedColumn.draggable = false;
  714. this.draggedColumn = null;
  715. this.dropPosition = null;
  716. }
  717. };
  718. TreeTable.prototype.handleRowClick = function (event) {
  719. var targetNode = event.originalEvent.target.nodeName;
  720. if (targetNode == 'INPUT' || targetNode == 'BUTTON' || targetNode == 'A' || (domhandler_1.DomHandler.hasClass(event.originalEvent.target, 'ui-clickable'))) {
  721. return;
  722. }
  723. if (this.selectionMode) {
  724. this.preventSelectionSetterPropagation = true;
  725. var rowNode = event.rowNode;
  726. var selected = this.isSelected(rowNode.node);
  727. var metaSelection = this.rowTouched ? false : this.metaKeySelection;
  728. var dataKeyValue = this.dataKey ? String(objectutils_1.ObjectUtils.resolveFieldData(rowNode.node.data, this.dataKey)) : null;
  729. if (metaSelection) {
  730. var metaKey = event.originalEvent.metaKey || event.originalEvent.ctrlKey;
  731. if (selected && metaKey) {
  732. if (this.isSingleSelectionMode()) {
  733. this._selection = null;
  734. this.selectionKeys = {};
  735. this.selectionChange.emit(null);
  736. }
  737. else {
  738. var selectionIndex_1 = this.findIndexInSelection(rowNode.node);
  739. this._selection = this.selection.filter(function (val, i) { return i != selectionIndex_1; });
  740. this.selectionChange.emit(this.selection);
  741. if (dataKeyValue) {
  742. delete this.selectionKeys[dataKeyValue];
  743. }
  744. }
  745. this.onNodeUnselect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row' });
  746. }
  747. else {
  748. if (this.isSingleSelectionMode()) {
  749. this._selection = rowNode.node;
  750. this.selectionChange.emit(rowNode.node);
  751. if (dataKeyValue) {
  752. this.selectionKeys = {};
  753. this.selectionKeys[dataKeyValue] = 1;
  754. }
  755. }
  756. else if (this.isMultipleSelectionMode()) {
  757. if (metaKey) {
  758. this._selection = this.selection || [];
  759. }
  760. else {
  761. this._selection = [];
  762. this.selectionKeys = {};
  763. }
  764. this._selection = this.selection.concat([rowNode.node]);
  765. this.selectionChange.emit(this.selection);
  766. if (dataKeyValue) {
  767. this.selectionKeys[dataKeyValue] = 1;
  768. }
  769. }
  770. this.onNodeSelect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row', index: event.rowIndex });
  771. }
  772. }
  773. else {
  774. if (this.selectionMode === 'single') {
  775. if (selected) {
  776. this._selection = null;
  777. this.selectionKeys = {};
  778. this.selectionChange.emit(this.selection);
  779. this.onNodeUnselect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row' });
  780. }
  781. else {
  782. this._selection = rowNode.node;
  783. this.selectionChange.emit(this.selection);
  784. this.onNodeSelect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row', index: event.rowIndex });
  785. if (dataKeyValue) {
  786. this.selectionKeys = {};
  787. this.selectionKeys[dataKeyValue] = 1;
  788. }
  789. }
  790. }
  791. else if (this.selectionMode === 'multiple') {
  792. if (selected) {
  793. var selectionIndex_2 = this.findIndexInSelection(rowNode.node);
  794. this._selection = this.selection.filter(function (val, i) { return i != selectionIndex_2; });
  795. this.selectionChange.emit(this.selection);
  796. this.onNodeUnselect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row' });
  797. if (dataKeyValue) {
  798. delete this.selectionKeys[dataKeyValue];
  799. }
  800. }
  801. else {
  802. this._selection = this.selection ? this.selection.concat([rowNode.node]) : [rowNode.node];
  803. this.selectionChange.emit(this.selection);
  804. this.onNodeSelect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row', index: event.rowIndex });
  805. if (dataKeyValue) {
  806. this.selectionKeys[dataKeyValue] = 1;
  807. }
  808. }
  809. }
  810. }
  811. this.tableService.onSelectionChange();
  812. }
  813. this.rowTouched = false;
  814. };
  815. TreeTable.prototype.handleRowTouchEnd = function (event) {
  816. this.rowTouched = true;
  817. };
  818. TreeTable.prototype.handleRowRightClick = function (event) {
  819. if (this.contextMenu) {
  820. var node = event.rowNode.node;
  821. if (this.contextMenuSelectionMode === 'separate') {
  822. this.contextMenuSelection = node;
  823. this.contextMenuSelectionChange.emit(node);
  824. this.onContextMenuSelect.emit({ originalEvent: event.originalEvent, node: node });
  825. this.contextMenu.show(event.originalEvent);
  826. this.tableService.onContextMenu(node);
  827. }
  828. else if (this.contextMenuSelectionMode === 'joint') {
  829. this.preventSelectionSetterPropagation = true;
  830. var selected = this.isSelected(node);
  831. var dataKeyValue = this.dataKey ? String(objectutils_1.ObjectUtils.resolveFieldData(node.data, this.dataKey)) : null;
  832. if (!selected) {
  833. if (this.isSingleSelectionMode()) {
  834. this.selection = node;
  835. this.selectionChange.emit(node);
  836. }
  837. else if (this.isMultipleSelectionMode()) {
  838. this.selection = [node];
  839. this.selectionChange.emit(this.selection);
  840. }
  841. if (dataKeyValue) {
  842. this.selectionKeys[dataKeyValue] = 1;
  843. }
  844. }
  845. this.contextMenu.show(event.originalEvent);
  846. this.onContextMenuSelect.emit({ originalEvent: event.originalEvent, node: node });
  847. }
  848. }
  849. };
  850. TreeTable.prototype.toggleNodeWithCheckbox = function (event) {
  851. this.selection = this.selection || [];
  852. this.preventSelectionSetterPropagation = true;
  853. var node = event.rowNode.node;
  854. var selected = this.isSelected(node);
  855. if (selected) {
  856. this.propagateSelectionDown(node, false);
  857. if (event.rowNode.parent) {
  858. this.propagateSelectionUp(node.parent, false);
  859. }
  860. this.selectionChange.emit(this.selection);
  861. this.onNodeUnselect.emit({ originalEvent: event, node: node });
  862. }
  863. else {
  864. this.propagateSelectionDown(node, true);
  865. if (event.rowNode.parent) {
  866. this.propagateSelectionUp(node.parent, true);
  867. }
  868. this.selectionChange.emit(this.selection);
  869. this.onNodeSelect.emit({ originalEvent: event, node: node });
  870. }
  871. this.tableService.onSelectionChange();
  872. };
  873. TreeTable.prototype.toggleNodesWithCheckbox = function (event, check) {
  874. var data = this.filteredNodes || this.value;
  875. this._selection = check && data ? data.slice() : [];
  876. if (check) {
  877. if (data && data.length) {
  878. for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
  879. var node = data_1[_i];
  880. this.propagateSelectionDown(node, true);
  881. }
  882. }
  883. }
  884. else {
  885. this._selection = [];
  886. this.selectionKeys = {};
  887. }
  888. this.preventSelectionSetterPropagation = true;
  889. this.selectionChange.emit(this._selection);
  890. this.tableService.onSelectionChange();
  891. this.onHeaderCheckboxToggle.emit({ originalEvent: event, checked: check });
  892. };
  893. TreeTable.prototype.propagateSelectionUp = function (node, select) {
  894. if (node.children && node.children.length) {
  895. var selectedChildCount = 0;
  896. var childPartialSelected = false;
  897. var dataKeyValue = this.dataKey ? String(objectutils_1.ObjectUtils.resolveFieldData(node.data, this.dataKey)) : null;
  898. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  899. var child = _a[_i];
  900. if (this.isSelected(child))
  901. selectedChildCount++;
  902. else if (child.partialSelected)
  903. childPartialSelected = true;
  904. }
  905. if (select && selectedChildCount == node.children.length) {
  906. this._selection = (this.selection || []).concat([node]);
  907. node.partialSelected = false;
  908. if (dataKeyValue) {
  909. this.selectionKeys[dataKeyValue] = 1;
  910. }
  911. }
  912. else {
  913. if (!select) {
  914. var index_1 = this.findIndexInSelection(node);
  915. if (index_1 >= 0) {
  916. this._selection = this.selection.filter(function (val, i) { return i != index_1; });
  917. if (dataKeyValue) {
  918. delete this.selectionKeys[dataKeyValue];
  919. }
  920. }
  921. }
  922. if (childPartialSelected || selectedChildCount > 0 && selectedChildCount != node.children.length)
  923. node.partialSelected = true;
  924. else
  925. node.partialSelected = false;
  926. }
  927. }
  928. var parent = node.parent;
  929. if (parent) {
  930. this.propagateSelectionUp(parent, select);
  931. }
  932. };
  933. TreeTable.prototype.propagateSelectionDown = function (node, select) {
  934. var index = this.findIndexInSelection(node);
  935. var dataKeyValue = this.dataKey ? String(objectutils_1.ObjectUtils.resolveFieldData(node.data, this.dataKey)) : null;
  936. if (select && index == -1) {
  937. this._selection = (this.selection || []).concat([node]);
  938. if (dataKeyValue) {
  939. this.selectionKeys[dataKeyValue] = 1;
  940. }
  941. }
  942. else if (!select && index > -1) {
  943. this._selection = this.selection.filter(function (val, i) { return i != index; });
  944. if (dataKeyValue) {
  945. delete this.selectionKeys[dataKeyValue];
  946. }
  947. }
  948. node.partialSelected = false;
  949. if (node.children && node.children.length) {
  950. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  951. var child = _a[_i];
  952. this.propagateSelectionDown(child, select);
  953. }
  954. }
  955. };
  956. TreeTable.prototype.isSelected = function (node) {
  957. if (node && this.selection) {
  958. if (this.dataKey) {
  959. return this.selectionKeys[objectutils_1.ObjectUtils.resolveFieldData(node.data, this.dataKey)] !== undefined;
  960. }
  961. else {
  962. if (this.selection instanceof Array)
  963. return this.findIndexInSelection(node) > -1;
  964. else
  965. return this.equals(node, this.selection);
  966. }
  967. }
  968. return false;
  969. };
  970. TreeTable.prototype.findIndexInSelection = function (node) {
  971. var index = -1;
  972. if (this.selection && this.selection.length) {
  973. for (var i = 0; i < this.selection.length; i++) {
  974. if (this.equals(node, this.selection[i])) {
  975. index = i;
  976. break;
  977. }
  978. }
  979. }
  980. return index;
  981. };
  982. TreeTable.prototype.isSingleSelectionMode = function () {
  983. return this.selectionMode === 'single';
  984. };
  985. TreeTable.prototype.isMultipleSelectionMode = function () {
  986. return this.selectionMode === 'multiple';
  987. };
  988. TreeTable.prototype.equals = function (node1, node2) {
  989. return this.compareSelectionBy === 'equals' ? (node1 === node2) : objectutils_1.ObjectUtils.equals(node1.data, node2.data, this.dataKey);
  990. };
  991. TreeTable.prototype.filter = function (value, field, matchMode) {
  992. var _this = this;
  993. if (this.filterTimeout) {
  994. clearTimeout(this.filterTimeout);
  995. }
  996. if (!this.isFilterBlank(value)) {
  997. this.filters[field] = { value: value, matchMode: matchMode };
  998. }
  999. else if (this.filters[field]) {
  1000. delete this.filters[field];
  1001. }
  1002. this.filterTimeout = setTimeout(function () {
  1003. _this._filter();
  1004. _this.filterTimeout = null;
  1005. }, this.filterDelay);
  1006. };
  1007. TreeTable.prototype.filterGlobal = function (value, matchMode) {
  1008. this.filter(value, 'global', matchMode);
  1009. };
  1010. TreeTable.prototype.isFilterBlank = function (filter) {
  1011. if (filter !== null && filter !== undefined) {
  1012. if ((typeof filter === 'string' && filter.trim().length == 0) || (filter instanceof Array && filter.length == 0))
  1013. return true;
  1014. else
  1015. return false;
  1016. }
  1017. return true;
  1018. };
  1019. TreeTable.prototype._filter = function () {
  1020. if (this.lazy) {
  1021. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  1022. }
  1023. else {
  1024. if (!this.value) {
  1025. return;
  1026. }
  1027. if (!this.hasFilter()) {
  1028. this.filteredNodes = null;
  1029. if (this.paginator) {
  1030. this.totalRecords = this.value ? this.value.length : 0;
  1031. }
  1032. }
  1033. else {
  1034. var globalFilterFieldsArray = void 0;
  1035. if (this.filters['global']) {
  1036. if (!this.columns && !this.globalFilterFields)
  1037. throw new Error('Global filtering requires dynamic columns or globalFilterFields to be defined.');
  1038. else
  1039. globalFilterFieldsArray = this.globalFilterFields || this.columns;
  1040. }
  1041. this.filteredNodes = [];
  1042. var isStrictMode = this.filterMode === 'strict';
  1043. var isValueChanged = false;
  1044. for (var _i = 0, _a = this.value; _i < _a.length; _i++) {
  1045. var node = _a[_i];
  1046. var copyNode = __assign({}, node);
  1047. var localMatch = true;
  1048. var globalMatch = false;
  1049. var paramsWithoutNode = void 0;
  1050. for (var prop in this.filters) {
  1051. if (this.filters.hasOwnProperty(prop) && prop !== 'global') {
  1052. var filterMeta = this.filters[prop];
  1053. var filterField = prop;
  1054. var filterValue = filterMeta.value;
  1055. var filterMatchMode = filterMeta.matchMode || 'startsWith';
  1056. var filterConstraint = filterutils_1.FilterUtils[filterMatchMode];
  1057. paramsWithoutNode = { filterField: filterField, filterValue: filterValue, filterConstraint: filterConstraint, isStrictMode: isStrictMode };
  1058. if ((isStrictMode && !(this.findFilteredNodes(copyNode, paramsWithoutNode) || this.isFilterMatched(copyNode, paramsWithoutNode))) ||
  1059. (!isStrictMode && !(this.isFilterMatched(copyNode, paramsWithoutNode) || this.findFilteredNodes(copyNode, paramsWithoutNode)))) {
  1060. localMatch = false;
  1061. }
  1062. if (!localMatch) {
  1063. break;
  1064. }
  1065. }
  1066. }
  1067. if (this.filters['global'] && !globalMatch && globalFilterFieldsArray) {
  1068. for (var j = 0; j < globalFilterFieldsArray.length; j++) {
  1069. var copyNodeForGlobal = __assign({}, copyNode);
  1070. var filterField = globalFilterFieldsArray[j].field || globalFilterFieldsArray[j];
  1071. var filterValue = this.filters['global'].value;
  1072. var filterConstraint = filterutils_1.FilterUtils[this.filters['global'].matchMode];
  1073. paramsWithoutNode = { filterField: filterField, filterValue: filterValue, filterConstraint: filterConstraint, isStrictMode: isStrictMode };
  1074. if ((isStrictMode && (this.findFilteredNodes(copyNodeForGlobal, paramsWithoutNode) || this.isFilterMatched(copyNodeForGlobal, paramsWithoutNode))) ||
  1075. (!isStrictMode && (this.isFilterMatched(copyNodeForGlobal, paramsWithoutNode) || this.findFilteredNodes(copyNodeForGlobal, paramsWithoutNode)))) {
  1076. globalMatch = true;
  1077. copyNode = copyNodeForGlobal;
  1078. }
  1079. }
  1080. }
  1081. var matches = localMatch;
  1082. if (this.filters['global']) {
  1083. matches = localMatch && globalMatch;
  1084. }
  1085. if (matches) {
  1086. this.filteredNodes.push(copyNode);
  1087. }
  1088. isValueChanged = isValueChanged || !localMatch || globalMatch || (localMatch && this.filteredNodes.length > 0) || (!globalMatch && this.filteredNodes.length === 0);
  1089. }
  1090. if (!isValueChanged) {
  1091. this.filteredNodes = null;
  1092. }
  1093. if (this.paginator) {
  1094. this.totalRecords = this.filteredNodes ? this.filteredNodes.length : this.value ? this.value.length : 0;
  1095. }
  1096. }
  1097. }
  1098. this.first = 0;
  1099. var filteredValue = this.filteredNodes || this.value;
  1100. this.onFilter.emit({
  1101. filters: this.filters,
  1102. filteredValue: filteredValue
  1103. });
  1104. this.tableService.onUIUpdate(filteredValue);
  1105. this.updateSerializedValue();
  1106. };
  1107. TreeTable.prototype.findFilteredNodes = function (node, paramsWithoutNode) {
  1108. if (node) {
  1109. var matched = false;
  1110. if (node.children) {
  1111. var childNodes = node.children.slice();
  1112. node.children = [];
  1113. for (var _i = 0, childNodes_1 = childNodes; _i < childNodes_1.length; _i++) {
  1114. var childNode = childNodes_1[_i];
  1115. var copyChildNode = __assign({}, childNode);
  1116. if (this.isFilterMatched(copyChildNode, paramsWithoutNode)) {
  1117. matched = true;
  1118. node.children.push(copyChildNode);
  1119. }
  1120. }
  1121. }
  1122. if (matched) {
  1123. return true;
  1124. }
  1125. }
  1126. };
  1127. TreeTable.prototype.isFilterMatched = function (node, _a) {
  1128. var filterField = _a.filterField, filterValue = _a.filterValue, filterConstraint = _a.filterConstraint, isStrictMode = _a.isStrictMode;
  1129. var matched = false;
  1130. var dataFieldValue = objectutils_1.ObjectUtils.resolveFieldData(node.data, filterField);
  1131. if (filterConstraint(dataFieldValue, filterValue)) {
  1132. matched = true;
  1133. }
  1134. if (!matched || (isStrictMode && !this.isNodeLeaf(node))) {
  1135. matched = this.findFilteredNodes(node, { filterField: filterField, filterValue: filterValue, filterConstraint: filterConstraint, isStrictMode: isStrictMode }) || matched;
  1136. }
  1137. return matched;
  1138. };
  1139. TreeTable.prototype.isNodeLeaf = function (node) {
  1140. return node.leaf === false ? false : !(node.children && node.children.length);
  1141. };
  1142. TreeTable.prototype.hasFilter = function () {
  1143. var empty = true;
  1144. for (var prop in this.filters) {
  1145. if (this.filters.hasOwnProperty(prop)) {
  1146. empty = false;
  1147. break;
  1148. }
  1149. }
  1150. return !empty;
  1151. };
  1152. TreeTable.prototype.reset = function () {
  1153. this._sortField = null;
  1154. this._sortOrder = 1;
  1155. this._multiSortMeta = null;
  1156. this.tableService.onSort(null);
  1157. this.filteredNodes = null;
  1158. this.filters = {};
  1159. this.first = 0;
  1160. if (this.lazy) {
  1161. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  1162. }
  1163. else {
  1164. this.totalRecords = (this._value ? this._value.length : 0);
  1165. }
  1166. };
  1167. TreeTable.prototype.updateEditingCell = function (cell) {
  1168. this.editingCell = cell;
  1169. this.bindDocumentEditListener();
  1170. };
  1171. TreeTable.prototype.isEditingCellValid = function () {
  1172. return (this.editingCell && domhandler_1.DomHandler.find(this.editingCell, '.ng-invalid.ng-dirty').length === 0);
  1173. };
  1174. TreeTable.prototype.bindDocumentEditListener = function () {
  1175. var _this = this;
  1176. if (!this.documentEditListener) {
  1177. this.documentEditListener = function (event) {
  1178. if (_this.editingCell && !_this.editingCellClick && _this.isEditingCellValid()) {
  1179. domhandler_1.DomHandler.removeClass(_this.editingCell, 'ui-editing-cell');
  1180. _this.editingCell = null;
  1181. _this.unbindDocumentEditListener();
  1182. }
  1183. _this.editingCellClick = false;
  1184. };
  1185. document.addEventListener('click', this.documentEditListener);
  1186. }
  1187. };
  1188. TreeTable.prototype.unbindDocumentEditListener = function () {
  1189. if (this.documentEditListener) {
  1190. document.removeEventListener('click', this.documentEditListener);
  1191. this.documentEditListener = null;
  1192. }
  1193. };
  1194. TreeTable.prototype.ngOnDestroy = function () {
  1195. this.unbindDocumentEditListener();
  1196. this.editingCell = null;
  1197. this.initialized = null;
  1198. };
  1199. __decorate([
  1200. core_1.Input(),
  1201. __metadata("design:type", Array)
  1202. ], TreeTable.prototype, "columns", void 0);
  1203. __decorate([
  1204. core_1.Input(),
  1205. __metadata("design:type", Object)
  1206. ], TreeTable.prototype, "style", void 0);
  1207. __decorate([
  1208. core_1.Input(),
  1209. __metadata("design:type", String)
  1210. ], TreeTable.prototype, "styleClass", void 0);
  1211. __decorate([
  1212. core_1.Input(),
  1213. __metadata("design:type", Boolean)
  1214. ], TreeTable.prototype, "autoLayout", void 0);
  1215. __decorate([
  1216. core_1.Input(),
  1217. __metadata("design:type", Boolean)
  1218. ], TreeTable.prototype, "lazy", void 0);
  1219. __decorate([
  1220. core_1.Input(),
  1221. __metadata("design:type", Boolean)
  1222. ], TreeTable.prototype, "paginator", void 0);
  1223. __decorate([
  1224. core_1.Input(),
  1225. __metadata("design:type", Number)
  1226. ], TreeTable.prototype, "rows", void 0);
  1227. __decorate([
  1228. core_1.Input(),
  1229. __metadata("design:type", Number)
  1230. ], TreeTable.prototype, "first", void 0);
  1231. __decorate([
  1232. core_1.Input(),
  1233. __metadata("design:type", Number)
  1234. ], TreeTable.prototype, "pageLinks", void 0);
  1235. __decorate([
  1236. core_1.Input(),
  1237. __metadata("design:type", Array)
  1238. ], TreeTable.prototype, "rowsPerPageOptions", void 0);
  1239. __decorate([
  1240. core_1.Input(),
  1241. __metadata("design:type", Boolean)
  1242. ], TreeTable.prototype, "alwaysShowPaginator", void 0);
  1243. __decorate([
  1244. core_1.Input(),
  1245. __metadata("design:type", String)
  1246. ], TreeTable.prototype, "paginatorPosition", void 0);
  1247. __decorate([
  1248. core_1.Input(),
  1249. __metadata("design:type", Object)
  1250. ], TreeTable.prototype, "paginatorDropdownAppendTo", void 0);
  1251. __decorate([
  1252. core_1.Input(),
  1253. __metadata("design:type", Number)
  1254. ], TreeTable.prototype, "defaultSortOrder", void 0);
  1255. __decorate([
  1256. core_1.Input(),
  1257. __metadata("design:type", String)
  1258. ], TreeTable.prototype, "sortMode", void 0);
  1259. __decorate([
  1260. core_1.Input(),
  1261. __metadata("design:type", Boolean)
  1262. ], TreeTable.prototype, "resetPageOnSort", void 0);
  1263. __decorate([
  1264. core_1.Input(),
  1265. __metadata("design:type", Boolean)
  1266. ], TreeTable.prototype, "customSort", void 0);
  1267. __decorate([
  1268. core_1.Input(),
  1269. __metadata("design:type", String)
  1270. ], TreeTable.prototype, "selectionMode", void 0);
  1271. __decorate([
  1272. core_1.Output(),
  1273. __metadata("design:type", core_1.EventEmitter)
  1274. ], TreeTable.prototype, "selectionChange", void 0);
  1275. __decorate([
  1276. core_1.Input(),
  1277. __metadata("design:type", Object)
  1278. ], TreeTable.prototype, "contextMenuSelection", void 0);
  1279. __decorate([
  1280. core_1.Output(),
  1281. __metadata("design:type", core_1.EventEmitter)
  1282. ], TreeTable.prototype, "contextMenuSelectionChange", void 0);
  1283. __decorate([
  1284. core_1.Input(),
  1285. __metadata("design:type", String)
  1286. ], TreeTable.prototype, "contextMenuSelectionMode", void 0);
  1287. __decorate([
  1288. core_1.Input(),
  1289. __metadata("design:type", String)
  1290. ], TreeTable.prototype, "dataKey", void 0);
  1291. __decorate([
  1292. core_1.Input(),
  1293. __metadata("design:type", Boolean)
  1294. ], TreeTable.prototype, "metaKeySelection", void 0);
  1295. __decorate([
  1296. core_1.Input(),
  1297. __metadata("design:type", String)
  1298. ], TreeTable.prototype, "compareSelectionBy", void 0);
  1299. __decorate([
  1300. core_1.Input(),
  1301. __metadata("design:type", Boolean)
  1302. ], TreeTable.prototype, "rowHover", void 0);
  1303. __decorate([
  1304. core_1.Input(),
  1305. __metadata("design:type", Boolean)
  1306. ], TreeTable.prototype, "loading", void 0);
  1307. __decorate([
  1308. core_1.Input(),
  1309. __metadata("design:type", String)
  1310. ], TreeTable.prototype, "loadingIcon", void 0);
  1311. __decorate([
  1312. core_1.Input(),
  1313. __metadata("design:type", Boolean)
  1314. ], TreeTable.prototype, "showLoader", void 0);
  1315. __decorate([
  1316. core_1.Input(),
  1317. __metadata("design:type", Boolean)
  1318. ], TreeTable.prototype, "scrollable", void 0);
  1319. __decorate([
  1320. core_1.Input(),
  1321. __metadata("design:type", String)
  1322. ], TreeTable.prototype, "scrollHeight", void 0);
  1323. __decorate([
  1324. core_1.Input(),
  1325. __metadata("design:type", Boolean)
  1326. ], TreeTable.prototype, "virtualScroll", void 0);
  1327. __decorate([
  1328. core_1.Input(),
  1329. __metadata("design:type", Number)
  1330. ], TreeTable.prototype, "virtualScrollDelay", void 0);
  1331. __decorate([
  1332. core_1.Input(),
  1333. __metadata("design:type", Number)
  1334. ], TreeTable.prototype, "virtualRowHeight", void 0);
  1335. __decorate([
  1336. core_1.Input(),
  1337. __metadata("design:type", String)
  1338. ], TreeTable.prototype, "frozenWidth", void 0);
  1339. __decorate([
  1340. core_1.Input(),
  1341. __metadata("design:type", Array)
  1342. ], TreeTable.prototype, "frozenColumns", void 0);
  1343. __decorate([
  1344. core_1.Input(),
  1345. __metadata("design:type", Boolean)
  1346. ], TreeTable.prototype, "resizableColumns", void 0);
  1347. __decorate([
  1348. core_1.Input(),
  1349. __metadata("design:type", String)
  1350. ], TreeTable.prototype, "columnResizeMode", void 0);
  1351. __decorate([
  1352. core_1.Input(),
  1353. __metadata("design:type", Boolean)
  1354. ], TreeTable.prototype, "reorderableColumns", void 0);
  1355. __decorate([
  1356. core_1.Input(),
  1357. __metadata("design:type", Object)
  1358. ], TreeTable.prototype, "contextMenu", void 0);
  1359. __decorate([
  1360. core_1.Input(),
  1361. __metadata("design:type", Function)
  1362. ], TreeTable.prototype, "rowTrackBy", void 0);
  1363. __decorate([
  1364. core_1.Input(),
  1365. __metadata("design:type", Object)
  1366. ], TreeTable.prototype, "filters", void 0);
  1367. __decorate([
  1368. core_1.Input(),
  1369. __metadata("design:type", Array)
  1370. ], TreeTable.prototype, "globalFilterFields", void 0);
  1371. __decorate([
  1372. core_1.Input(),
  1373. __metadata("design:type", Number)
  1374. ], TreeTable.prototype, "filterDelay", void 0);
  1375. __decorate([
  1376. core_1.Input(),
  1377. __metadata("design:type", String)
  1378. ], TreeTable.prototype, "filterMode", void 0);
  1379. __decorate([
  1380. core_1.Output(),
  1381. __metadata("design:type", core_1.EventEmitter)
  1382. ], TreeTable.prototype, "onFilter", void 0);
  1383. __decorate([
  1384. core_1.Output(),
  1385. __metadata("design:type", core_1.EventEmitter)
  1386. ], TreeTable.prototype, "onNodeExpand", void 0);
  1387. __decorate([
  1388. core_1.Output(),
  1389. __metadata("design:type", core_1.EventEmitter)
  1390. ], TreeTable.prototype, "onNodeCollapse", void 0);
  1391. __decorate([
  1392. core_1.Output(),
  1393. __metadata("design:type", core_1.EventEmitter)
  1394. ], TreeTable.prototype, "onPage", void 0);
  1395. __decorate([
  1396. core_1.Output(),
  1397. __metadata("design:type", core_1.EventEmitter)
  1398. ], TreeTable.prototype, "onSort", void 0);
  1399. __decorate([
  1400. core_1.Output(),
  1401. __metadata("design:type", core_1.EventEmitter)
  1402. ], TreeTable.prototype, "onLazyLoad", void 0);
  1403. __decorate([
  1404. core_1.Output(),
  1405. __metadata("design:type", core_1.EventEmitter)
  1406. ], TreeTable.prototype, "sortFunction", void 0);
  1407. __decorate([
  1408. core_1.Output(),
  1409. __metadata("design:type", core_1.EventEmitter)
  1410. ], TreeTable.prototype, "onColResize", void 0);
  1411. __decorate([
  1412. core_1.Output(),
  1413. __metadata("design:type", core_1.EventEmitter)
  1414. ], TreeTable.prototype, "onColReorder", void 0);
  1415. __decorate([
  1416. core_1.Output(),
  1417. __metadata("design:type", core_1.EventEmitter)
  1418. ], TreeTable.prototype, "onNodeSelect", void 0);
  1419. __decorate([
  1420. core_1.Output(),
  1421. __metadata("design:type", core_1.EventEmitter)
  1422. ], TreeTable.prototype, "onNodeUnselect", void 0);
  1423. __decorate([
  1424. core_1.Output(),
  1425. __metadata("design:type", core_1.EventEmitter)
  1426. ], TreeTable.prototype, "onContextMenuSelect", void 0);
  1427. __decorate([
  1428. core_1.Output(),
  1429. __metadata("design:type", core_1.EventEmitter)
  1430. ], TreeTable.prototype, "onHeaderCheckboxToggle", void 0);
  1431. __decorate([
  1432. core_1.Output(),
  1433. __metadata("design:type", core_1.EventEmitter)
  1434. ], TreeTable.prototype, "onEditInit", void 0);
  1435. __decorate([
  1436. core_1.Output(),
  1437. __metadata("design:type", core_1.EventEmitter)
  1438. ], TreeTable.prototype, "onEditComplete", void 0);
  1439. __decorate([
  1440. core_1.Output(),
  1441. __metadata("design:type", core_1.EventEmitter)
  1442. ], TreeTable.prototype, "onEditCancel", void 0);
  1443. __decorate([
  1444. core_1.ViewChild('container', { static: false }),
  1445. __metadata("design:type", core_1.ElementRef)
  1446. ], TreeTable.prototype, "containerViewChild", void 0);
  1447. __decorate([
  1448. core_1.ViewChild('resizeHelper', { static: false }),
  1449. __metadata("design:type", core_1.ElementRef)
  1450. ], TreeTable.prototype, "resizeHelperViewChild", void 0);
  1451. __decorate([
  1452. core_1.ViewChild('reorderIndicatorUp', { static: false }),
  1453. __metadata("design:type", core_1.ElementRef)
  1454. ], TreeTable.prototype, "reorderIndicatorUpViewChild", void 0);
  1455. __decorate([
  1456. core_1.ViewChild('reorderIndicatorDown', { static: false }),
  1457. __metadata("design:type", core_1.ElementRef)
  1458. ], TreeTable.prototype, "reorderIndicatorDownViewChild", void 0);
  1459. __decorate([
  1460. core_1.ViewChild('table', { static: false }),
  1461. __metadata("design:type", core_1.ElementRef)
  1462. ], TreeTable.prototype, "tableViewChild", void 0);
  1463. __decorate([
  1464. core_1.ContentChildren(shared_1.PrimeTemplate),
  1465. __metadata("design:type", core_1.QueryList)
  1466. ], TreeTable.prototype, "templates", void 0);
  1467. __decorate([
  1468. core_1.Input(),
  1469. __metadata("design:type", Array),
  1470. __metadata("design:paramtypes", [Array])
  1471. ], TreeTable.prototype, "value", null);
  1472. __decorate([
  1473. core_1.Input(),
  1474. __metadata("design:type", Number),
  1475. __metadata("design:paramtypes", [Number])
  1476. ], TreeTable.prototype, "totalRecords", null);
  1477. __decorate([
  1478. core_1.Input(),
  1479. __metadata("design:type", String),
  1480. __metadata("design:paramtypes", [String])
  1481. ], TreeTable.prototype, "sortField", null);
  1482. __decorate([
  1483. core_1.Input(),
  1484. __metadata("design:type", Number),
  1485. __metadata("design:paramtypes", [Number])
  1486. ], TreeTable.prototype, "sortOrder", null);
  1487. __decorate([
  1488. core_1.Input(),
  1489. __metadata("design:type", Array),
  1490. __metadata("design:paramtypes", [Array])
  1491. ], TreeTable.prototype, "multiSortMeta", null);
  1492. __decorate([
  1493. core_1.Input(),
  1494. __metadata("design:type", Object),
  1495. __metadata("design:paramtypes", [Object])
  1496. ], TreeTable.prototype, "selection", null);
  1497. TreeTable = __decorate([
  1498. core_1.Component({
  1499. selector: 'p-treeTable',
  1500. template: "\n <div #container [ngStyle]=\"style\" [class]=\"styleClass\"\n [ngClass]=\"{'ui-treetable ui-widget': true, 'ui-treetable-auto-layout': autoLayout, 'ui-treetable-hoverable-rows': (rowHover||(selectionMode === 'single' || selectionMode === 'multiple')),\n 'ui-treetable-resizable': resizableColumns, 'ui-treetable-resizable-fit': (resizableColumns && columnResizeMode === 'fit')}\">\n <div class=\"ui-treetable-loading ui-widget-overlay\" *ngIf=\"loading && showLoader\"></div>\n <div class=\"ui-treetable-loading-content\" *ngIf=\"loading && showLoader\">\n <i [class]=\"'ui-treetable-loading-icon pi-spin ' + loadingIcon\"></i>\n </div>\n <div *ngIf=\"captionTemplate\" class=\"ui-treetable-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\"></p-paginator>\n \n <div class=\"ui-treetable-wrapper\" *ngIf=\"!scrollable\">\n <table #table class=\"ui-treetable-table\">\n <ng-container *ngTemplateOutlet=\"colGroupTemplate; context {$implicit: columns}\"></ng-container>\n <thead class=\"ui-treetable-thead\">\n <ng-container *ngTemplateOutlet=\"headerTemplate; context: {$implicit: columns}\"></ng-container>\n </thead>\n <tfoot class=\"ui-treetable-tfoot\">\n <ng-container *ngTemplateOutlet=\"footerTemplate; context {$implicit: columns}\"></ng-container>\n </tfoot>\n <tbody class=\"ui-treetable-tbody\" [pTreeTableBody]=\"columns\" [pTreeTableBodyTemplate]=\"bodyTemplate\"></tbody>\n </table>\n </div>\n\n <div class=\"ui-treetable-scrollable-wrapper\" *ngIf=\"scrollable\">\n <div class=\"ui-treetable-scrollable-view ui-treetable-frozen-view\" *ngIf=\"frozenColumns||frozenBodyTemplate\" [ttScrollableView]=\"frozenColumns\" [frozen]=\"true\" [ngStyle]=\"{width: frozenWidth}\" [scrollHeight]=\"scrollHeight\"></div>\n <div class=\"ui-treetable-scrollable-view\" [ttScrollableView]=\"columns\" [frozen]=\"false\" [scrollHeight]=\"scrollHeight\"></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\"></p-paginator>\n <div *ngIf=\"summaryTemplate\" class=\"ui-treetable-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\" *ngIf=\"reorderableColumns\"></span>\n <span #reorderIndicatorDown class=\"pi pi-arrow-up ui-table-reorder-indicator-down\" *ngIf=\"reorderableColumns\"></span>\n </div>\n ",
  1501. providers: [TreeTableService]
  1502. }),
  1503. __metadata("design:paramtypes", [core_1.ElementRef, core_1.NgZone, TreeTableService])
  1504. ], TreeTable);
  1505. return TreeTable;
  1506. }());
  1507. exports.TreeTable = TreeTable;
  1508. var TTBody = /** @class */ (function () {
  1509. function TTBody(tt) {
  1510. this.tt = tt;
  1511. }
  1512. __decorate([
  1513. core_1.Input("pTreeTableBody"),
  1514. __metadata("design:type", Array)
  1515. ], TTBody.prototype, "columns", void 0);
  1516. __decorate([
  1517. core_1.Input("pTreeTableBodyTemplate"),
  1518. __metadata("design:type", core_1.TemplateRef)
  1519. ], TTBody.prototype, "template", void 0);
  1520. TTBody = __decorate([
  1521. core_1.Component({
  1522. selector: '[pTreeTableBody]',
  1523. template: "\n <ng-template ngFor let-serializedNode let-rowIndex=\"index\" [ngForOf]=\"tt.serializedValue\" [ngForTrackBy]=\"tt.rowTrackBy\">\n <ng-container *ngIf=\"serializedNode.visible\">\n <ng-container *ngTemplateOutlet=\"template; context: {$implicit: serializedNode, node: serializedNode.node, rowData: serializedNode.node.data, columns: columns}\"></ng-container>\n </ng-container>\n </ng-template>\n <ng-container *ngIf=\"tt.isEmpty()\">\n <ng-container *ngTemplateOutlet=\"tt.emptyMessageTemplate; context: {$implicit: columns}\"></ng-container>\n </ng-container>\n "
  1524. }),
  1525. __metadata("design:paramtypes", [TreeTable])
  1526. ], TTBody);
  1527. return TTBody;
  1528. }());
  1529. exports.TTBody = TTBody;
  1530. var TTScrollableView = /** @class */ (function () {
  1531. function TTScrollableView(tt, el, zone) {
  1532. var _this = this;
  1533. this.tt = tt;
  1534. this.el = el;
  1535. this.zone = zone;
  1536. this.loadingArray = [];
  1537. this.subscription = this.tt.tableService.uiUpdateSource$.subscribe(function () {
  1538. _this.zone.runOutsideAngular(function () {
  1539. setTimeout(function () {
  1540. _this.alignScrollBar();
  1541. _this.initialized = true;
  1542. if (_this.scrollLoadingTableViewChild && _this.scrollLoadingTableViewChild.nativeElement) {
  1543. _this.scrollLoadingTableViewChild.nativeElement.style.display = 'none';
  1544. }
  1545. }, 50);
  1546. });
  1547. });
  1548. if (this.tt.virtualScroll) {
  1549. this.totalRecordsSubscription = this.tt.tableService.totalRecordsSource$.subscribe(function () {
  1550. _this.zone.runOutsideAngular(function () {
  1551. setTimeout(function () {
  1552. _this.setVirtualScrollerHeight();
  1553. }, 50);
  1554. });
  1555. });
  1556. }
  1557. this.loadingArray = Array(this.tt.rows).fill(1);
  1558. this.initialized = false;
  1559. }
  1560. Object.defineProperty(TTScrollableView.prototype, "scrollHeight", {
  1561. get: function () {
  1562. return this._scrollHeight;
  1563. },
  1564. set: function (val) {
  1565. this._scrollHeight = val;
  1566. this.setScrollHeight();
  1567. },
  1568. enumerable: true,
  1569. configurable: true
  1570. });
  1571. TTScrollableView.prototype.ngAfterViewChecked = function () {
  1572. if (!this.initialized && this.el.nativeElement.offsetParent) {
  1573. this.alignScrollBar();
  1574. this.initialized = true;
  1575. }
  1576. };
  1577. TTScrollableView.prototype.ngAfterViewInit = function () {
  1578. this.bindEvents();
  1579. this.setScrollHeight();
  1580. this.alignScrollBar();
  1581. if (!this.frozen) {
  1582. if (this.tt.frozenColumns || this.tt.frozenBodyTemplate) {
  1583. domhandler_1.DomHandler.addClass(this.el.nativeElement, 'ui-treetable-unfrozen-view');
  1584. }
  1585. if (this.tt.frozenWidth) {
  1586. this.el.nativeElement.style.left = this.tt.frozenWidth;
  1587. this.el.nativeElement.style.width = 'calc(100% - ' + this.tt.frozenWidth + ')';
  1588. }
  1589. var frozenView = this.el.nativeElement.previousElementSibling;
  1590. if (frozenView) {
  1591. this.frozenSiblingBody = domhandler_1.DomHandler.findSingle(frozenView, '.ui-treetable-scrollable-body');
  1592. }
  1593. }
  1594. else {
  1595. this.scrollBodyViewChild.nativeElement.style.paddingBottom = domhandler_1.DomHandler.calculateScrollbarWidth() + 'px';
  1596. }
  1597. if (this.tt.virtualScroll) {
  1598. this.setVirtualScrollerHeight();
  1599. if (this.scrollLoadingTableViewChild && this.scrollLoadingTableViewChild.nativeElement) {
  1600. this.scrollLoadingTableViewChild.nativeElement.style.display = 'table';
  1601. }
  1602. }
  1603. };
  1604. TTScrollableView.prototype.bindEvents = function () {
  1605. var _this = this;
  1606. this.zone.runOutsideAngular(function () {
  1607. var scrollBarWidth = domhandler_1.DomHandler.calculateScrollbarWidth();
  1608. if (_this.scrollHeaderViewChild && _this.scrollHeaderViewChild.nativeElement) {
  1609. _this.headerScrollListener = _this.onHeaderScroll.bind(_this);
  1610. _this.scrollHeaderBoxViewChild.nativeElement.addEventListener('scroll', _this.headerScrollListener);
  1611. }
  1612. if (_this.scrollFooterViewChild && _this.scrollFooterViewChild.nativeElement) {
  1613. _this.footerScrollListener = _this.onFooterScroll.bind(_this);
  1614. _this.scrollFooterViewChild.nativeElement.addEventListener('scroll', _this.footerScrollListener);
  1615. }
  1616. if (!_this.frozen) {
  1617. _this.bodyScrollListener = _this.onBodyScroll.bind(_this);
  1618. _this.scrollBodyViewChild.nativeElement.addEventListener('scroll', _this.bodyScrollListener);
  1619. }
  1620. });
  1621. };
  1622. TTScrollableView.prototype.unbindEvents = function () {
  1623. if (this.scrollHeaderViewChild && this.scrollHeaderViewChild.nativeElement) {
  1624. this.scrollHeaderBoxViewChild.nativeElement.removeEventListener('scroll', this.headerScrollListener);
  1625. }
  1626. if (this.scrollFooterViewChild && this.scrollFooterViewChild.nativeElement) {
  1627. this.scrollFooterViewChild.nativeElement.removeEventListener('scroll', this.footerScrollListener);
  1628. }
  1629. this.scrollBodyViewChild.nativeElement.addEventListener('scroll', this.bodyScrollListener);
  1630. };
  1631. TTScrollableView.prototype.onHeaderScroll = function (event) {
  1632. this.scrollHeaderViewChild.nativeElement.scrollLeft = 0;
  1633. };
  1634. TTScrollableView.prototype.onFooterScroll = function (event) {
  1635. this.scrollFooterViewChild.nativeElement.scrollLeft = 0;
  1636. };
  1637. TTScrollableView.prototype.onBodyScroll = function (event) {
  1638. var _this = this;
  1639. if (this.scrollHeaderViewChild && this.scrollHeaderViewChild.nativeElement) {
  1640. this.scrollHeaderBoxViewChild.nativeElement.style.marginLeft = -1 * this.scrollBodyViewChild.nativeElement.scrollLeft + 'px';
  1641. }
  1642. if (this.scrollFooterViewChild && this.scrollFooterViewChild.nativeElement) {
  1643. this.scrollFooterBoxViewChild.nativeElement.style.marginLeft = -1 * this.scrollBodyViewChild.nativeElement.scrollLeft + 'px';
  1644. }
  1645. if (this.frozenSiblingBody) {
  1646. this.frozenSiblingBody.scrollTop = this.scrollBodyViewChild.nativeElement.scrollTop;
  1647. }
  1648. if (this.tt.virtualScroll) {
  1649. var viewport = domhandler_1.DomHandler.getOuterHeight(this.scrollBodyViewChild.nativeElement);
  1650. var tableHeight = domhandler_1.DomHandler.getOuterHeight(this.scrollTableViewChild.nativeElement);
  1651. var pageHeight_1 = this.tt.virtualRowHeight * this.tt.rows;
  1652. var virtualTableHeight = domhandler_1.DomHandler.getOuterHeight(this.virtualScrollerViewChild.nativeElement);
  1653. var pageCount = (virtualTableHeight / pageHeight_1) || 1;
  1654. var scrollBodyTop = this.scrollTableViewChild.nativeElement.style.top || '0';
  1655. if ((this.scrollBodyViewChild.nativeElement.scrollTop + viewport > parseFloat(scrollBodyTop) + tableHeight) || (this.scrollBodyViewChild.nativeElement.scrollTop < parseFloat(scrollBodyTop))) {
  1656. if (this.scrollLoadingTableViewChild && this.scrollLoadingTableViewChild.nativeElement) {
  1657. this.scrollLoadingTableViewChild.nativeElement.style.display = 'table';
  1658. this.scrollLoadingTableViewChild.nativeElement.style.top = this.scrollBodyViewChild.nativeElement.scrollTop + 'px';
  1659. }
  1660. var page_1 = Math.floor((this.scrollBodyViewChild.nativeElement.scrollTop * pageCount) / (this.scrollBodyViewChild.nativeElement.scrollHeight)) + 1;
  1661. this.tt.handleVirtualScroll({
  1662. page: page_1,
  1663. callback: function () {
  1664. if (_this.scrollLoadingTableViewChild && _this.scrollLoadingTableViewChild.nativeElement) {
  1665. _this.scrollLoadingTableViewChild.nativeElement.style.display = 'none';
  1666. }
  1667. _this.scrollTableViewChild.nativeElement.style.top = ((page_1 - 1) * pageHeight_1) + 'px';
  1668. if (_this.frozenSiblingBody) {
  1669. _this.frozenSiblingBody.children[0].style.top = _this.scrollTableViewChild.nativeElement.style.top;
  1670. }
  1671. }
  1672. });
  1673. }
  1674. }
  1675. };
  1676. TTScrollableView.prototype.setScrollHeight = function () {
  1677. if (this.scrollHeight && this.scrollBodyViewChild && this.scrollBodyViewChild.nativeElement) {
  1678. if (this.scrollHeight.indexOf('%') !== -1) {
  1679. var relativeHeight = void 0;
  1680. this.scrollBodyViewChild.nativeElement.style.visibility = 'hidden';
  1681. this.scrollBodyViewChild.nativeElement.style.height = '100px'; //temporary height to calculate static height
  1682. var containerHeight = domhandler_1.DomHandler.getOuterHeight(this.tt.el.nativeElement.children[0]);
  1683. if (this.scrollHeight.includes("calc")) {
  1684. var percentHeight = parseInt(this.scrollHeight.slice(this.scrollHeight.indexOf("(") + 1, this.scrollHeight.indexOf("%")));
  1685. var diffValue = parseInt(this.scrollHeight.slice(this.scrollHeight.indexOf("-") + 1, this.scrollHeight.indexOf(")")));
  1686. relativeHeight = (domhandler_1.DomHandler.getOuterHeight(this.tt.el.nativeElement.parentElement) * percentHeight / 100) - diffValue;
  1687. }
  1688. else {
  1689. relativeHeight = domhandler_1.DomHandler.getOuterHeight(this.tt.el.nativeElement.parentElement) * parseInt(this.scrollHeight) / 100;
  1690. }
  1691. var staticHeight = containerHeight - 100; //total height of headers, footers, paginators
  1692. var scrollBodyHeight = (relativeHeight - staticHeight);
  1693. if (this.frozen) {
  1694. scrollBodyHeight -= domhandler_1.DomHandler.calculateScrollbarWidth();
  1695. }
  1696. this.scrollBodyViewChild.nativeElement.style.height = 'auto';
  1697. this.scrollBodyViewChild.nativeElement.style.maxHeight = scrollBodyHeight + 'px';
  1698. this.scrollBodyViewChild.nativeElement.style.visibility = 'visible';
  1699. }
  1700. else {
  1701. if (this.frozen)
  1702. this.scrollBodyViewChild.nativeElement.style.maxHeight = (parseInt(this.scrollHeight) - domhandler_1.DomHandler.calculateScrollbarWidth()) + 'px';
  1703. else
  1704. this.scrollBodyViewChild.nativeElement.style.maxHeight = this.scrollHeight;
  1705. }
  1706. }
  1707. };
  1708. TTScrollableView.prototype.setVirtualScrollerHeight = function () {
  1709. if (this.virtualScrollerViewChild.nativeElement) {
  1710. this.virtualScrollerViewChild.nativeElement.style.height = this.tt.totalRecords * this.tt.virtualRowHeight + 'px';
  1711. }
  1712. };
  1713. TTScrollableView.prototype.hasVerticalOverflow = function () {
  1714. return domhandler_1.DomHandler.getOuterHeight(this.scrollTableViewChild.nativeElement) > domhandler_1.DomHandler.getOuterHeight(this.scrollBodyViewChild.nativeElement);
  1715. };
  1716. TTScrollableView.prototype.alignScrollBar = function () {
  1717. if (!this.frozen) {
  1718. var scrollBarWidth = this.hasVerticalOverflow() ? domhandler_1.DomHandler.calculateScrollbarWidth() : 0;
  1719. this.scrollHeaderBoxViewChild.nativeElement.style.marginRight = scrollBarWidth + 'px';
  1720. if (this.scrollFooterBoxViewChild && this.scrollFooterBoxViewChild.nativeElement) {
  1721. this.scrollFooterBoxViewChild.nativeElement.style.marginRight = scrollBarWidth + 'px';
  1722. }
  1723. }
  1724. this.initialized = false;
  1725. };
  1726. TTScrollableView.prototype.ngOnDestroy = function () {
  1727. this.unbindEvents();
  1728. this.frozenSiblingBody = null;
  1729. if (this.subscription) {
  1730. this.subscription.unsubscribe();
  1731. }
  1732. if (this.totalRecordsSubscription) {
  1733. this.totalRecordsSubscription.unsubscribe();
  1734. }
  1735. this.initialized = false;
  1736. };
  1737. __decorate([
  1738. core_1.Input("ttScrollableView"),
  1739. __metadata("design:type", Array)
  1740. ], TTScrollableView.prototype, "columns", void 0);
  1741. __decorate([
  1742. core_1.Input(),
  1743. __metadata("design:type", Boolean)
  1744. ], TTScrollableView.prototype, "frozen", void 0);
  1745. __decorate([
  1746. core_1.ViewChild('scrollHeader', { static: false }),
  1747. __metadata("design:type", core_1.ElementRef)
  1748. ], TTScrollableView.prototype, "scrollHeaderViewChild", void 0);
  1749. __decorate([
  1750. core_1.ViewChild('scrollHeaderBox', { static: false }),
  1751. __metadata("design:type", core_1.ElementRef)
  1752. ], TTScrollableView.prototype, "scrollHeaderBoxViewChild", void 0);
  1753. __decorate([
  1754. core_1.ViewChild('scrollBody', { static: false }),
  1755. __metadata("design:type", core_1.ElementRef)
  1756. ], TTScrollableView.prototype, "scrollBodyViewChild", void 0);
  1757. __decorate([
  1758. core_1.ViewChild('scrollTable', { static: false }),
  1759. __metadata("design:type", core_1.ElementRef)
  1760. ], TTScrollableView.prototype, "scrollTableViewChild", void 0);
  1761. __decorate([
  1762. core_1.ViewChild('loadingTable', { static: false }),
  1763. __metadata("design:type", core_1.ElementRef)
  1764. ], TTScrollableView.prototype, "scrollLoadingTableViewChild", void 0);
  1765. __decorate([
  1766. core_1.ViewChild('scrollFooter', { static: false }),
  1767. __metadata("design:type", core_1.ElementRef)
  1768. ], TTScrollableView.prototype, "scrollFooterViewChild", void 0);
  1769. __decorate([
  1770. core_1.ViewChild('scrollFooterBox', { static: false }),
  1771. __metadata("design:type", core_1.ElementRef)
  1772. ], TTScrollableView.prototype, "scrollFooterBoxViewChild", void 0);
  1773. __decorate([
  1774. core_1.ViewChild('virtualScroller', { static: false }),
  1775. __metadata("design:type", core_1.ElementRef)
  1776. ], TTScrollableView.prototype, "virtualScrollerViewChild", void 0);
  1777. __decorate([
  1778. core_1.Input(),
  1779. __metadata("design:type", String),
  1780. __metadata("design:paramtypes", [String])
  1781. ], TTScrollableView.prototype, "scrollHeight", null);
  1782. TTScrollableView = __decorate([
  1783. core_1.Component({
  1784. selector: '[ttScrollableView]',
  1785. template: "\n <div #scrollHeader class=\"ui-treetable-scrollable-header ui-widget-header\">\n <div #scrollHeaderBox class=\"ui-treetable-scrollable-header-box\">\n <table class=\"ui-treetable-scrollable-header-table\">\n <ng-container *ngTemplateOutlet=\"frozen ? tt.frozenColGroupTemplate||tt.colGroupTemplate : tt.colGroupTemplate; context {$implicit: columns}\"></ng-container>\n <thead class=\"ui-treetable-thead\">\n <ng-container *ngTemplateOutlet=\"frozen ? tt.frozenHeaderTemplate||tt.headerTemplate : tt.headerTemplate; context {$implicit: columns}\"></ng-container>\n </thead>\n </table>\n </div>\n </div>\n <div #scrollBody class=\"ui-treetable-scrollable-body\">\n <table #scrollTable [ngClass]=\"{'ui-treetable-scrollable-body-table': true, 'ui-treetable-virtual-table': tt.virtualScroll}\">\n <ng-container *ngTemplateOutlet=\"frozen ? tt.frozenColGroupTemplate||tt.colGroupTemplate : tt.colGroupTemplate; context {$implicit: columns}\"></ng-container>\n <tbody class=\"ui-treetable-tbody\" [pTreeTableBody]=\"columns\" [pTreeTableBodyTemplate]=\"frozen ? tt.frozenBodyTemplate||tt.bodyTemplate : tt.bodyTemplate\"></tbody>\n </table>\n <table #loadingTable *ngIf=\"tt.virtualScroll && tt.loadingBodyTemplate != null\" [ngClass]=\"{'ui-treetable-scrollable-body-table ui-treetable-loading-virtual-table': true, 'ui-treetable-virtual-table': tt.virtualScroll}\">\n <tbody class=\"ui-treetable-tbody\">\n <ng-template ngFor [ngForOf]=\"loadingArray\">\n <ng-container *ngTemplateOutlet=\"tt.loadingBodyTemplate; context: {columns: columns}\"></ng-container>\n </ng-template>\n </tbody>\n </table>\n <div #virtualScroller class=\"ui-treetable-virtual-scroller\" *ngIf=\"tt.virtualScroll\"></div>\n </div>\n <div #scrollFooter *ngIf=\"tt.footerTemplate\" class=\"ui-treetable-scrollable-footer ui-widget-header\">\n <div #scrollFooterBox class=\"ui-treetable-scrollable-footer-box\">\n <table class=\"ui-treetable-scrollable-footer-table\">\n <ng-container *ngTemplateOutlet=\"frozen ? tt.frozenColGroupTemplate||tt.colGroupTemplate : tt.colGroupTemplate; context {$implicit: columns}\"></ng-container>\n <tfoot class=\"ui-treetable-tfoot\">\n <ng-container *ngTemplateOutlet=\"frozen ? tt.frozenFooterTemplate||tt.footerTemplate : tt.footerTemplate; context {$implicit: columns}\"></ng-container>\n </tfoot>\n </table>\n </div>\n </div>\n "
  1786. }),
  1787. __metadata("design:paramtypes", [TreeTable, core_1.ElementRef, core_1.NgZone])
  1788. ], TTScrollableView);
  1789. return TTScrollableView;
  1790. }());
  1791. exports.TTScrollableView = TTScrollableView;
  1792. var TTSortableColumn = /** @class */ (function () {
  1793. function TTSortableColumn(tt) {
  1794. var _this = this;
  1795. this.tt = tt;
  1796. if (this.isEnabled()) {
  1797. this.subscription = this.tt.tableService.sortSource$.subscribe(function (sortMeta) {
  1798. _this.updateSortState();
  1799. });
  1800. }
  1801. }
  1802. TTSortableColumn.prototype.ngOnInit = function () {
  1803. if (this.isEnabled()) {
  1804. this.updateSortState();
  1805. }
  1806. };
  1807. TTSortableColumn.prototype.updateSortState = function () {
  1808. this.sorted = this.tt.isSorted(this.field);
  1809. };
  1810. TTSortableColumn.prototype.onClick = function (event) {
  1811. if (this.isEnabled()) {
  1812. this.updateSortState();
  1813. this.tt.sort({
  1814. originalEvent: event,
  1815. field: this.field
  1816. });
  1817. domhandler_1.DomHandler.clearSelection();
  1818. }
  1819. };
  1820. TTSortableColumn.prototype.onEnterKey = function (event) {
  1821. this.onClick(event);
  1822. };
  1823. TTSortableColumn.prototype.isEnabled = function () {
  1824. return this.ttSortableColumnDisabled !== true;
  1825. };
  1826. TTSortableColumn.prototype.ngOnDestroy = function () {
  1827. if (this.subscription) {
  1828. this.subscription.unsubscribe();
  1829. }
  1830. };
  1831. __decorate([
  1832. core_1.Input("ttSortableColumn"),
  1833. __metadata("design:type", String)
  1834. ], TTSortableColumn.prototype, "field", void 0);
  1835. __decorate([
  1836. core_1.Input(),
  1837. __metadata("design:type", Boolean)
  1838. ], TTSortableColumn.prototype, "ttSortableColumnDisabled", void 0);
  1839. __decorate([
  1840. core_1.HostListener('click', ['$event']),
  1841. __metadata("design:type", Function),
  1842. __metadata("design:paramtypes", [MouseEvent]),
  1843. __metadata("design:returntype", void 0)
  1844. ], TTSortableColumn.prototype, "onClick", null);
  1845. __decorate([
  1846. core_1.HostListener('keydown.enter', ['$event']),
  1847. __metadata("design:type", Function),
  1848. __metadata("design:paramtypes", [MouseEvent]),
  1849. __metadata("design:returntype", void 0)
  1850. ], TTSortableColumn.prototype, "onEnterKey", null);
  1851. TTSortableColumn = __decorate([
  1852. core_1.Directive({
  1853. selector: '[ttSortableColumn]',
  1854. host: {
  1855. '[class.ui-sortable-column]': 'isEnabled()',
  1856. '[class.ui-state-highlight]': 'sorted',
  1857. '[attr.tabindex]': 'isEnabled() ? "0" : null'
  1858. }
  1859. }),
  1860. __metadata("design:paramtypes", [TreeTable])
  1861. ], TTSortableColumn);
  1862. return TTSortableColumn;
  1863. }());
  1864. exports.TTSortableColumn = TTSortableColumn;
  1865. var TTSortIcon = /** @class */ (function () {
  1866. function TTSortIcon(tt) {
  1867. var _this = this;
  1868. this.tt = tt;
  1869. this.subscription = this.tt.tableService.sortSource$.subscribe(function (sortMeta) {
  1870. _this.updateSortState();
  1871. });
  1872. }
  1873. TTSortIcon.prototype.ngOnInit = function () {
  1874. this.updateSortState();
  1875. };
  1876. TTSortIcon.prototype.onClick = function (event) {
  1877. event.preventDefault();
  1878. };
  1879. TTSortIcon.prototype.updateSortState = function () {
  1880. if (this.tt.sortMode === 'single') {
  1881. this.sortOrder = this.tt.isSorted(this.field) ? this.tt.sortOrder : 0;
  1882. }
  1883. else if (this.tt.sortMode === 'multiple') {
  1884. var sortMeta = this.tt.getSortMeta(this.field);
  1885. this.sortOrder = sortMeta ? sortMeta.order : 0;
  1886. }
  1887. };
  1888. TTSortIcon.prototype.ngOnDestroy = function () {
  1889. if (this.subscription) {
  1890. this.subscription.unsubscribe();
  1891. }
  1892. };
  1893. __decorate([
  1894. core_1.Input(),
  1895. __metadata("design:type", String)
  1896. ], TTSortIcon.prototype, "field", void 0);
  1897. __decorate([
  1898. core_1.Input(),
  1899. __metadata("design:type", String)
  1900. ], TTSortIcon.prototype, "ariaLabelDesc", void 0);
  1901. __decorate([
  1902. core_1.Input(),
  1903. __metadata("design:type", String)
  1904. ], TTSortIcon.prototype, "ariaLabelAsc", void 0);
  1905. TTSortIcon = __decorate([
  1906. core_1.Component({
  1907. selector: 'p-treeTableSortIcon',
  1908. 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 "
  1909. }),
  1910. __metadata("design:paramtypes", [TreeTable])
  1911. ], TTSortIcon);
  1912. return TTSortIcon;
  1913. }());
  1914. exports.TTSortIcon = TTSortIcon;
  1915. var TTResizableColumn = /** @class */ (function () {
  1916. function TTResizableColumn(tt, el, zone) {
  1917. this.tt = tt;
  1918. this.el = el;
  1919. this.zone = zone;
  1920. }
  1921. TTResizableColumn.prototype.ngAfterViewInit = function () {
  1922. var _this = this;
  1923. if (this.isEnabled()) {
  1924. domhandler_1.DomHandler.addClass(this.el.nativeElement, 'ui-resizable-column');
  1925. this.resizer = document.createElement('span');
  1926. this.resizer.className = 'ui-column-resizer ui-clickable';
  1927. this.el.nativeElement.appendChild(this.resizer);
  1928. this.zone.runOutsideAngular(function () {
  1929. _this.resizerMouseDownListener = _this.onMouseDown.bind(_this);
  1930. _this.resizer.addEventListener('mousedown', _this.resizerMouseDownListener);
  1931. });
  1932. }
  1933. };
  1934. TTResizableColumn.prototype.bindDocumentEvents = function () {
  1935. var _this = this;
  1936. this.zone.runOutsideAngular(function () {
  1937. _this.documentMouseMoveListener = _this.onDocumentMouseMove.bind(_this);
  1938. document.addEventListener('mousemove', _this.documentMouseMoveListener);
  1939. _this.documentMouseUpListener = _this.onDocumentMouseUp.bind(_this);
  1940. document.addEventListener('mouseup', _this.documentMouseUpListener);
  1941. });
  1942. };
  1943. TTResizableColumn.prototype.unbindDocumentEvents = function () {
  1944. if (this.documentMouseMoveListener) {
  1945. document.removeEventListener('mousemove', this.documentMouseMoveListener);
  1946. this.documentMouseMoveListener = null;
  1947. }
  1948. if (this.documentMouseUpListener) {
  1949. document.removeEventListener('mouseup', this.documentMouseUpListener);
  1950. this.documentMouseUpListener = null;
  1951. }
  1952. };
  1953. TTResizableColumn.prototype.onMouseDown = function (event) {
  1954. this.tt.onColumnResizeBegin(event);
  1955. this.bindDocumentEvents();
  1956. };
  1957. TTResizableColumn.prototype.onDocumentMouseMove = function (event) {
  1958. this.tt.onColumnResize(event);
  1959. };
  1960. TTResizableColumn.prototype.onDocumentMouseUp = function (event) {
  1961. this.tt.onColumnResizeEnd(event, this.el.nativeElement);
  1962. this.unbindDocumentEvents();
  1963. };
  1964. TTResizableColumn.prototype.isEnabled = function () {
  1965. return this.ttResizableColumnDisabled !== true;
  1966. };
  1967. TTResizableColumn.prototype.ngOnDestroy = function () {
  1968. if (this.resizerMouseDownListener) {
  1969. this.resizer.removeEventListener('mousedown', this.resizerMouseDownListener);
  1970. }
  1971. this.unbindDocumentEvents();
  1972. };
  1973. __decorate([
  1974. core_1.Input(),
  1975. __metadata("design:type", Boolean)
  1976. ], TTResizableColumn.prototype, "ttResizableColumnDisabled", void 0);
  1977. TTResizableColumn = __decorate([
  1978. core_1.Directive({
  1979. selector: '[ttResizableColumn]'
  1980. }),
  1981. __metadata("design:paramtypes", [TreeTable, core_1.ElementRef, core_1.NgZone])
  1982. ], TTResizableColumn);
  1983. return TTResizableColumn;
  1984. }());
  1985. exports.TTResizableColumn = TTResizableColumn;
  1986. var TTReorderableColumn = /** @class */ (function () {
  1987. function TTReorderableColumn(tt, el, zone) {
  1988. this.tt = tt;
  1989. this.el = el;
  1990. this.zone = zone;
  1991. }
  1992. TTReorderableColumn.prototype.ngAfterViewInit = function () {
  1993. if (this.isEnabled()) {
  1994. this.bindEvents();
  1995. }
  1996. };
  1997. TTReorderableColumn.prototype.bindEvents = function () {
  1998. var _this = this;
  1999. this.zone.runOutsideAngular(function () {
  2000. _this.mouseDownListener = _this.onMouseDown.bind(_this);
  2001. _this.el.nativeElement.addEventListener('mousedown', _this.mouseDownListener);
  2002. _this.dragStartListener = _this.onDragStart.bind(_this);
  2003. _this.el.nativeElement.addEventListener('dragstart', _this.dragStartListener);
  2004. _this.dragOverListener = _this.onDragEnter.bind(_this);
  2005. _this.el.nativeElement.addEventListener('dragover', _this.dragOverListener);
  2006. _this.dragEnterListener = _this.onDragEnter.bind(_this);
  2007. _this.el.nativeElement.addEventListener('dragenter', _this.dragEnterListener);
  2008. _this.dragLeaveListener = _this.onDragLeave.bind(_this);
  2009. _this.el.nativeElement.addEventListener('dragleave', _this.dragLeaveListener);
  2010. });
  2011. };
  2012. TTReorderableColumn.prototype.unbindEvents = function () {
  2013. if (this.mouseDownListener) {
  2014. document.removeEventListener('mousedown', this.mouseDownListener);
  2015. this.mouseDownListener = null;
  2016. }
  2017. if (this.dragOverListener) {
  2018. document.removeEventListener('dragover', this.dragOverListener);
  2019. this.dragOverListener = null;
  2020. }
  2021. if (this.dragEnterListener) {
  2022. document.removeEventListener('dragenter', this.dragEnterListener);
  2023. this.dragEnterListener = null;
  2024. }
  2025. if (this.dragEnterListener) {
  2026. document.removeEventListener('dragenter', this.dragEnterListener);
  2027. this.dragEnterListener = null;
  2028. }
  2029. if (this.dragLeaveListener) {
  2030. document.removeEventListener('dragleave', this.dragLeaveListener);
  2031. this.dragLeaveListener = null;
  2032. }
  2033. };
  2034. TTReorderableColumn.prototype.onMouseDown = function (event) {
  2035. if (event.target.nodeName === 'INPUT' || domhandler_1.DomHandler.hasClass(event.target, 'ui-column-resizer'))
  2036. this.el.nativeElement.draggable = false;
  2037. else
  2038. this.el.nativeElement.draggable = true;
  2039. };
  2040. TTReorderableColumn.prototype.onDragStart = function (event) {
  2041. this.tt.onColumnDragStart(event, this.el.nativeElement);
  2042. };
  2043. TTReorderableColumn.prototype.onDragOver = function (event) {
  2044. event.preventDefault();
  2045. };
  2046. TTReorderableColumn.prototype.onDragEnter = function (event) {
  2047. this.tt.onColumnDragEnter(event, this.el.nativeElement);
  2048. };
  2049. TTReorderableColumn.prototype.onDragLeave = function (event) {
  2050. this.tt.onColumnDragLeave(event);
  2051. };
  2052. TTReorderableColumn.prototype.onDrop = function (event) {
  2053. if (this.isEnabled()) {
  2054. this.tt.onColumnDrop(event, this.el.nativeElement);
  2055. }
  2056. };
  2057. TTReorderableColumn.prototype.isEnabled = function () {
  2058. return this.ttReorderableColumnDisabled !== true;
  2059. };
  2060. TTReorderableColumn.prototype.ngOnDestroy = function () {
  2061. this.unbindEvents();
  2062. };
  2063. __decorate([
  2064. core_1.Input(),
  2065. __metadata("design:type", Boolean)
  2066. ], TTReorderableColumn.prototype, "ttReorderableColumnDisabled", void 0);
  2067. __decorate([
  2068. core_1.HostListener('drop', ['$event']),
  2069. __metadata("design:type", Function),
  2070. __metadata("design:paramtypes", [Object]),
  2071. __metadata("design:returntype", void 0)
  2072. ], TTReorderableColumn.prototype, "onDrop", null);
  2073. TTReorderableColumn = __decorate([
  2074. core_1.Directive({
  2075. selector: '[ttReorderableColumn]'
  2076. }),
  2077. __metadata("design:paramtypes", [TreeTable, core_1.ElementRef, core_1.NgZone])
  2078. ], TTReorderableColumn);
  2079. return TTReorderableColumn;
  2080. }());
  2081. exports.TTReorderableColumn = TTReorderableColumn;
  2082. var TTSelectableRow = /** @class */ (function () {
  2083. function TTSelectableRow(tt, tableService) {
  2084. var _this = this;
  2085. this.tt = tt;
  2086. this.tableService = tableService;
  2087. if (this.isEnabled()) {
  2088. this.subscription = this.tt.tableService.selectionSource$.subscribe(function () {
  2089. _this.selected = _this.tt.isSelected(_this.rowNode.node);
  2090. });
  2091. }
  2092. }
  2093. TTSelectableRow.prototype.ngOnInit = function () {
  2094. if (this.isEnabled()) {
  2095. this.selected = this.tt.isSelected(this.rowNode.node);
  2096. }
  2097. };
  2098. TTSelectableRow.prototype.onClick = function (event) {
  2099. if (this.isEnabled()) {
  2100. this.tt.handleRowClick({
  2101. originalEvent: event,
  2102. rowNode: this.rowNode
  2103. });
  2104. }
  2105. };
  2106. TTSelectableRow.prototype.onEnterKey = function (event) {
  2107. this.onClick(event);
  2108. };
  2109. TTSelectableRow.prototype.onTouchEnd = function (event) {
  2110. if (this.isEnabled()) {
  2111. this.tt.handleRowTouchEnd(event);
  2112. }
  2113. };
  2114. TTSelectableRow.prototype.isEnabled = function () {
  2115. return this.ttSelectableRowDisabled !== true;
  2116. };
  2117. TTSelectableRow.prototype.ngOnDestroy = function () {
  2118. if (this.subscription) {
  2119. this.subscription.unsubscribe();
  2120. }
  2121. };
  2122. __decorate([
  2123. core_1.Input("ttSelectableRow"),
  2124. __metadata("design:type", Object)
  2125. ], TTSelectableRow.prototype, "rowNode", void 0);
  2126. __decorate([
  2127. core_1.Input(),
  2128. __metadata("design:type", Boolean)
  2129. ], TTSelectableRow.prototype, "ttSelectableRowDisabled", void 0);
  2130. __decorate([
  2131. core_1.HostListener('click', ['$event']),
  2132. __metadata("design:type", Function),
  2133. __metadata("design:paramtypes", [Event]),
  2134. __metadata("design:returntype", void 0)
  2135. ], TTSelectableRow.prototype, "onClick", null);
  2136. __decorate([
  2137. core_1.HostListener('keydown.enter', ['$event']),
  2138. __metadata("design:type", Function),
  2139. __metadata("design:paramtypes", [Event]),
  2140. __metadata("design:returntype", void 0)
  2141. ], TTSelectableRow.prototype, "onEnterKey", null);
  2142. __decorate([
  2143. core_1.HostListener('touchend', ['$event']),
  2144. __metadata("design:type", Function),
  2145. __metadata("design:paramtypes", [Event]),
  2146. __metadata("design:returntype", void 0)
  2147. ], TTSelectableRow.prototype, "onTouchEnd", null);
  2148. TTSelectableRow = __decorate([
  2149. core_1.Directive({
  2150. selector: '[ttSelectableRow]',
  2151. host: {
  2152. '[class.ui-state-highlight]': 'selected'
  2153. }
  2154. }),
  2155. __metadata("design:paramtypes", [TreeTable, TreeTableService])
  2156. ], TTSelectableRow);
  2157. return TTSelectableRow;
  2158. }());
  2159. exports.TTSelectableRow = TTSelectableRow;
  2160. var TTSelectableRowDblClick = /** @class */ (function () {
  2161. function TTSelectableRowDblClick(tt, tableService) {
  2162. var _this = this;
  2163. this.tt = tt;
  2164. this.tableService = tableService;
  2165. if (this.isEnabled()) {
  2166. this.subscription = this.tt.tableService.selectionSource$.subscribe(function () {
  2167. _this.selected = _this.tt.isSelected(_this.rowNode.node);
  2168. });
  2169. }
  2170. }
  2171. TTSelectableRowDblClick.prototype.ngOnInit = function () {
  2172. if (this.isEnabled()) {
  2173. this.selected = this.tt.isSelected(this.rowNode.node);
  2174. }
  2175. };
  2176. TTSelectableRowDblClick.prototype.onClick = function (event) {
  2177. if (this.isEnabled()) {
  2178. this.tt.handleRowClick({
  2179. originalEvent: event,
  2180. rowNode: this.rowNode
  2181. });
  2182. }
  2183. };
  2184. TTSelectableRowDblClick.prototype.isEnabled = function () {
  2185. return this.ttSelectableRowDisabled !== true;
  2186. };
  2187. TTSelectableRowDblClick.prototype.ngOnDestroy = function () {
  2188. if (this.subscription) {
  2189. this.subscription.unsubscribe();
  2190. }
  2191. };
  2192. __decorate([
  2193. core_1.Input("ttSelectableRowDblClick"),
  2194. __metadata("design:type", Object)
  2195. ], TTSelectableRowDblClick.prototype, "rowNode", void 0);
  2196. __decorate([
  2197. core_1.Input(),
  2198. __metadata("design:type", Boolean)
  2199. ], TTSelectableRowDblClick.prototype, "ttSelectableRowDisabled", void 0);
  2200. __decorate([
  2201. core_1.HostListener('dblclick', ['$event']),
  2202. __metadata("design:type", Function),
  2203. __metadata("design:paramtypes", [Event]),
  2204. __metadata("design:returntype", void 0)
  2205. ], TTSelectableRowDblClick.prototype, "onClick", null);
  2206. TTSelectableRowDblClick = __decorate([
  2207. core_1.Directive({
  2208. selector: '[ttSelectableRowDblClick]',
  2209. host: {
  2210. '[class.ui-state-highlight]': 'selected'
  2211. }
  2212. }),
  2213. __metadata("design:paramtypes", [TreeTable, TreeTableService])
  2214. ], TTSelectableRowDblClick);
  2215. return TTSelectableRowDblClick;
  2216. }());
  2217. exports.TTSelectableRowDblClick = TTSelectableRowDblClick;
  2218. var TTContextMenuRow = /** @class */ (function () {
  2219. function TTContextMenuRow(tt, tableService) {
  2220. var _this = this;
  2221. this.tt = tt;
  2222. this.tableService = tableService;
  2223. if (this.isEnabled()) {
  2224. this.subscription = this.tt.tableService.contextMenuSource$.subscribe(function (node) {
  2225. _this.selected = _this.tt.equals(_this.rowNode.node, node);
  2226. });
  2227. }
  2228. }
  2229. TTContextMenuRow.prototype.onContextMenu = function (event) {
  2230. if (this.isEnabled()) {
  2231. this.tt.handleRowRightClick({
  2232. originalEvent: event,
  2233. rowNode: this.rowNode
  2234. });
  2235. event.preventDefault();
  2236. }
  2237. };
  2238. TTContextMenuRow.prototype.isEnabled = function () {
  2239. return this.ttContextMenuRowDisabled !== true;
  2240. };
  2241. TTContextMenuRow.prototype.ngOnDestroy = function () {
  2242. if (this.subscription) {
  2243. this.subscription.unsubscribe();
  2244. }
  2245. };
  2246. __decorate([
  2247. core_1.Input("ttContextMenuRow"),
  2248. __metadata("design:type", Object)
  2249. ], TTContextMenuRow.prototype, "rowNode", void 0);
  2250. __decorate([
  2251. core_1.Input(),
  2252. __metadata("design:type", Boolean)
  2253. ], TTContextMenuRow.prototype, "ttContextMenuRowDisabled", void 0);
  2254. __decorate([
  2255. core_1.HostListener('contextmenu', ['$event']),
  2256. __metadata("design:type", Function),
  2257. __metadata("design:paramtypes", [Event]),
  2258. __metadata("design:returntype", void 0)
  2259. ], TTContextMenuRow.prototype, "onContextMenu", null);
  2260. TTContextMenuRow = __decorate([
  2261. core_1.Directive({
  2262. selector: '[ttContextMenuRow]',
  2263. host: {
  2264. '[class.ui-contextmenu-selected]': 'selected'
  2265. }
  2266. }),
  2267. __metadata("design:paramtypes", [TreeTable, TreeTableService])
  2268. ], TTContextMenuRow);
  2269. return TTContextMenuRow;
  2270. }());
  2271. exports.TTContextMenuRow = TTContextMenuRow;
  2272. var TTCheckbox = /** @class */ (function () {
  2273. function TTCheckbox(tt, tableService) {
  2274. var _this = this;
  2275. this.tt = tt;
  2276. this.tableService = tableService;
  2277. this.subscription = this.tt.tableService.selectionSource$.subscribe(function () {
  2278. _this.checked = _this.tt.isSelected(_this.rowNode.node);
  2279. });
  2280. }
  2281. TTCheckbox.prototype.ngOnInit = function () {
  2282. this.checked = this.tt.isSelected(this.rowNode.node);
  2283. };
  2284. TTCheckbox.prototype.onClick = function (event) {
  2285. if (!this.disabled) {
  2286. this.tt.toggleNodeWithCheckbox({
  2287. originalEvent: event,
  2288. rowNode: this.rowNode
  2289. });
  2290. }
  2291. domhandler_1.DomHandler.clearSelection();
  2292. };
  2293. TTCheckbox.prototype.onFocus = function () {
  2294. domhandler_1.DomHandler.addClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  2295. };
  2296. TTCheckbox.prototype.onBlur = function () {
  2297. domhandler_1.DomHandler.removeClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  2298. };
  2299. TTCheckbox.prototype.ngOnDestroy = function () {
  2300. if (this.subscription) {
  2301. this.subscription.unsubscribe();
  2302. }
  2303. };
  2304. __decorate([
  2305. core_1.Input(),
  2306. __metadata("design:type", Boolean)
  2307. ], TTCheckbox.prototype, "disabled", void 0);
  2308. __decorate([
  2309. core_1.Input("value"),
  2310. __metadata("design:type", Object)
  2311. ], TTCheckbox.prototype, "rowNode", void 0);
  2312. __decorate([
  2313. core_1.ViewChild('box', { static: false }),
  2314. __metadata("design:type", core_1.ElementRef)
  2315. ], TTCheckbox.prototype, "boxViewChild", void 0);
  2316. TTCheckbox = __decorate([
  2317. core_1.Component({
  2318. selector: 'p-treeTableCheckbox',
  2319. template: "\n <div class=\"ui-chkbox ui-treetable-chkbox ui-widget\" (click)=\"onClick($event)\">\n <div class=\"ui-helper-hidden-accessible\">\n <input type=\"checkbox\" [checked]=\"checked\" (focus)=\"onFocus()\" (blur)=\"onBlur()\">\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 pi\" [ngClass]=\"{'pi-check':checked, 'pi-minus': rowNode.node.partialSelected}\"></span>\n </div>\n </div>\n "
  2320. }),
  2321. __metadata("design:paramtypes", [TreeTable, TreeTableService])
  2322. ], TTCheckbox);
  2323. return TTCheckbox;
  2324. }());
  2325. exports.TTCheckbox = TTCheckbox;
  2326. var TTHeaderCheckbox = /** @class */ (function () {
  2327. function TTHeaderCheckbox(tt, tableService) {
  2328. var _this = this;
  2329. this.tt = tt;
  2330. this.tableService = tableService;
  2331. this.valueChangeSubscription = this.tt.tableService.uiUpdateSource$.subscribe(function () {
  2332. _this.checked = _this.updateCheckedState();
  2333. });
  2334. this.selectionChangeSubscription = this.tt.tableService.selectionSource$.subscribe(function () {
  2335. _this.checked = _this.updateCheckedState();
  2336. });
  2337. }
  2338. TTHeaderCheckbox.prototype.ngOnInit = function () {
  2339. this.checked = this.updateCheckedState();
  2340. };
  2341. TTHeaderCheckbox.prototype.onClick = function (event, checked) {
  2342. if (this.tt.value && this.tt.value.length > 0) {
  2343. this.tt.toggleNodesWithCheckbox(event, !checked);
  2344. }
  2345. domhandler_1.DomHandler.clearSelection();
  2346. };
  2347. TTHeaderCheckbox.prototype.onFocus = function () {
  2348. domhandler_1.DomHandler.addClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  2349. };
  2350. TTHeaderCheckbox.prototype.onBlur = function () {
  2351. domhandler_1.DomHandler.removeClass(this.boxViewChild.nativeElement, 'ui-state-focus');
  2352. };
  2353. TTHeaderCheckbox.prototype.ngOnDestroy = function () {
  2354. if (this.selectionChangeSubscription) {
  2355. this.selectionChangeSubscription.unsubscribe();
  2356. }
  2357. if (this.valueChangeSubscription) {
  2358. this.valueChangeSubscription.unsubscribe();
  2359. }
  2360. };
  2361. TTHeaderCheckbox.prototype.updateCheckedState = function () {
  2362. var checked;
  2363. var data = this.tt.filteredNodes || this.tt.value;
  2364. if (data) {
  2365. for (var _i = 0, data_2 = data; _i < data_2.length; _i++) {
  2366. var node = data_2[_i];
  2367. if (this.tt.isSelected(node)) {
  2368. checked = true;
  2369. }
  2370. else {
  2371. checked = false;
  2372. break;
  2373. }
  2374. }
  2375. }
  2376. else {
  2377. checked = false;
  2378. }
  2379. return checked;
  2380. };
  2381. __decorate([
  2382. core_1.ViewChild('box', { static: false }),
  2383. __metadata("design:type", core_1.ElementRef)
  2384. ], TTHeaderCheckbox.prototype, "boxViewChild", void 0);
  2385. TTHeaderCheckbox = __decorate([
  2386. core_1.Component({
  2387. selector: 'p-treeTableHeaderCheckbox',
  2388. template: "\n <div class=\"ui-chkbox ui-treetable-header-chkbox ui-widget\" (click)=\"onClick($event, cb.checked)\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #cb type=\"checkbox\" [checked]=\"checked\" (focus)=\"onFocus()\" (blur)=\"onBlur()\" [disabled]=\"!tt.value||tt.value.length === 0\">\n </div>\n <div #box [ngClass]=\"{'ui-chkbox-box ui-widget ui-state-default':true,\n 'ui-state-active':checked, 'ui-state-disabled': (!tt.value || tt.value.length === 0)}\">\n <span class=\"ui-chkbox-icon ui-clickable\" [ngClass]=\"{'pi pi-check':checked}\"></span>\n </div>\n </div>\n "
  2389. }),
  2390. __metadata("design:paramtypes", [TreeTable, TreeTableService])
  2391. ], TTHeaderCheckbox);
  2392. return TTHeaderCheckbox;
  2393. }());
  2394. exports.TTHeaderCheckbox = TTHeaderCheckbox;
  2395. var TTEditableColumn = /** @class */ (function () {
  2396. function TTEditableColumn(tt, el, zone) {
  2397. this.tt = tt;
  2398. this.el = el;
  2399. this.zone = zone;
  2400. }
  2401. TTEditableColumn.prototype.ngAfterViewInit = function () {
  2402. if (this.isEnabled()) {
  2403. domhandler_1.DomHandler.addClass(this.el.nativeElement, 'ui-editable-column');
  2404. }
  2405. };
  2406. TTEditableColumn.prototype.onClick = function (event) {
  2407. if (this.isEnabled()) {
  2408. this.tt.editingCellClick = true;
  2409. if (this.tt.editingCell) {
  2410. if (this.tt.editingCell !== this.el.nativeElement) {
  2411. if (!this.tt.isEditingCellValid()) {
  2412. return;
  2413. }
  2414. domhandler_1.DomHandler.removeClass(this.tt.editingCell, 'ui-editing-cell');
  2415. this.openCell();
  2416. }
  2417. }
  2418. else {
  2419. this.openCell();
  2420. }
  2421. }
  2422. };
  2423. TTEditableColumn.prototype.openCell = function () {
  2424. var _this = this;
  2425. this.tt.updateEditingCell(this.el.nativeElement);
  2426. domhandler_1.DomHandler.addClass(this.el.nativeElement, 'ui-editing-cell');
  2427. this.tt.onEditInit.emit({ field: this.field, data: this.data });
  2428. this.zone.runOutsideAngular(function () {
  2429. setTimeout(function () {
  2430. var focusable = domhandler_1.DomHandler.findSingle(_this.el.nativeElement, 'input, textarea');
  2431. if (focusable) {
  2432. focusable.focus();
  2433. }
  2434. }, 50);
  2435. });
  2436. };
  2437. TTEditableColumn.prototype.closeEditingCell = function () {
  2438. domhandler_1.DomHandler.removeClass(this.tt.editingCell, 'ui-editing-cell');
  2439. this.tt.editingCell = null;
  2440. this.tt.unbindDocumentEditListener();
  2441. };
  2442. TTEditableColumn.prototype.onKeyDown = function (event) {
  2443. if (this.isEnabled()) {
  2444. //enter
  2445. if (event.keyCode == 13) {
  2446. if (this.tt.isEditingCellValid()) {
  2447. domhandler_1.DomHandler.removeClass(this.tt.editingCell, 'ui-editing-cell');
  2448. this.closeEditingCell();
  2449. this.tt.onEditComplete.emit({ field: this.field, data: this.data });
  2450. }
  2451. event.preventDefault();
  2452. }
  2453. //escape
  2454. else if (event.keyCode == 27) {
  2455. if (this.tt.isEditingCellValid()) {
  2456. domhandler_1.DomHandler.removeClass(this.tt.editingCell, 'ui-editing-cell');
  2457. this.closeEditingCell();
  2458. this.tt.onEditCancel.emit({ field: this.field, data: this.data });
  2459. }
  2460. event.preventDefault();
  2461. }
  2462. //tab
  2463. else if (event.keyCode == 9) {
  2464. this.tt.onEditComplete.emit({ field: this.field, data: this.data });
  2465. if (event.shiftKey)
  2466. this.moveToPreviousCell(event);
  2467. else
  2468. this.moveToNextCell(event);
  2469. }
  2470. }
  2471. };
  2472. TTEditableColumn.prototype.findCell = function (element) {
  2473. if (element) {
  2474. var cell = element;
  2475. while (cell && !domhandler_1.DomHandler.hasClass(cell, 'ui-editing-cell')) {
  2476. cell = cell.parentElement;
  2477. }
  2478. return cell;
  2479. }
  2480. else {
  2481. return null;
  2482. }
  2483. };
  2484. TTEditableColumn.prototype.moveToPreviousCell = function (event) {
  2485. var currentCell = this.findCell(event.target);
  2486. var row = currentCell.parentElement;
  2487. var targetCell = this.findPreviousEditableColumn(currentCell);
  2488. if (targetCell) {
  2489. domhandler_1.DomHandler.invokeElementMethod(targetCell, 'click');
  2490. event.preventDefault();
  2491. }
  2492. };
  2493. TTEditableColumn.prototype.moveToNextCell = function (event) {
  2494. var currentCell = this.findCell(event.target);
  2495. var row = currentCell.parentElement;
  2496. var targetCell = this.findNextEditableColumn(currentCell);
  2497. if (targetCell) {
  2498. domhandler_1.DomHandler.invokeElementMethod(targetCell, 'click');
  2499. event.preventDefault();
  2500. }
  2501. };
  2502. TTEditableColumn.prototype.findPreviousEditableColumn = function (cell) {
  2503. var prevCell = cell.previousElementSibling;
  2504. if (!prevCell) {
  2505. var previousRow = cell.parentElement ? cell.parentElement.previousElementSibling : null;
  2506. if (previousRow) {
  2507. prevCell = previousRow.lastElementChild;
  2508. }
  2509. }
  2510. if (prevCell) {
  2511. if (domhandler_1.DomHandler.hasClass(prevCell, 'ui-editable-column'))
  2512. return prevCell;
  2513. else
  2514. return this.findPreviousEditableColumn(prevCell);
  2515. }
  2516. else {
  2517. return null;
  2518. }
  2519. };
  2520. TTEditableColumn.prototype.findNextEditableColumn = function (cell) {
  2521. var nextCell = cell.nextElementSibling;
  2522. if (!nextCell) {
  2523. var nextRow = cell.parentElement ? cell.parentElement.nextElementSibling : null;
  2524. if (nextRow) {
  2525. nextCell = nextRow.firstElementChild;
  2526. }
  2527. }
  2528. if (nextCell) {
  2529. if (domhandler_1.DomHandler.hasClass(nextCell, 'ui-editable-column'))
  2530. return nextCell;
  2531. else
  2532. return this.findNextEditableColumn(nextCell);
  2533. }
  2534. else {
  2535. return null;
  2536. }
  2537. };
  2538. TTEditableColumn.prototype.isEnabled = function () {
  2539. return this.ttEditableColumnDisabled !== true;
  2540. };
  2541. __decorate([
  2542. core_1.Input("ttEditableColumn"),
  2543. __metadata("design:type", Object)
  2544. ], TTEditableColumn.prototype, "data", void 0);
  2545. __decorate([
  2546. core_1.Input("ttEditableColumnField"),
  2547. __metadata("design:type", Object)
  2548. ], TTEditableColumn.prototype, "field", void 0);
  2549. __decorate([
  2550. core_1.Input(),
  2551. __metadata("design:type", Boolean)
  2552. ], TTEditableColumn.prototype, "ttEditableColumnDisabled", void 0);
  2553. __decorate([
  2554. core_1.HostListener('click', ['$event']),
  2555. __metadata("design:type", Function),
  2556. __metadata("design:paramtypes", [MouseEvent]),
  2557. __metadata("design:returntype", void 0)
  2558. ], TTEditableColumn.prototype, "onClick", null);
  2559. __decorate([
  2560. core_1.HostListener('keydown', ['$event']),
  2561. __metadata("design:type", Function),
  2562. __metadata("design:paramtypes", [KeyboardEvent]),
  2563. __metadata("design:returntype", void 0)
  2564. ], TTEditableColumn.prototype, "onKeyDown", null);
  2565. TTEditableColumn = __decorate([
  2566. core_1.Directive({
  2567. selector: '[ttEditableColumn]'
  2568. }),
  2569. __metadata("design:paramtypes", [TreeTable, core_1.ElementRef, core_1.NgZone])
  2570. ], TTEditableColumn);
  2571. return TTEditableColumn;
  2572. }());
  2573. exports.TTEditableColumn = TTEditableColumn;
  2574. var TreeTableCellEditor = /** @class */ (function () {
  2575. function TreeTableCellEditor(tt, editableColumn) {
  2576. this.tt = tt;
  2577. this.editableColumn = editableColumn;
  2578. }
  2579. TreeTableCellEditor.prototype.ngAfterContentInit = function () {
  2580. var _this = this;
  2581. this.templates.forEach(function (item) {
  2582. switch (item.getType()) {
  2583. case 'input':
  2584. _this.inputTemplate = item.template;
  2585. break;
  2586. case 'output':
  2587. _this.outputTemplate = item.template;
  2588. break;
  2589. }
  2590. });
  2591. };
  2592. __decorate([
  2593. core_1.ContentChildren(shared_1.PrimeTemplate),
  2594. __metadata("design:type", core_1.QueryList)
  2595. ], TreeTableCellEditor.prototype, "templates", void 0);
  2596. TreeTableCellEditor = __decorate([
  2597. core_1.Component({
  2598. selector: 'p-treeTableCellEditor',
  2599. template: "\n <ng-container *ngIf=\"tt.editingCell === editableColumn.el.nativeElement\">\n <ng-container *ngTemplateOutlet=\"inputTemplate\"></ng-container>\n </ng-container>\n <ng-container *ngIf=\"!tt.editingCell || tt.editingCell !== editableColumn.el.nativeElement\">\n <ng-container *ngTemplateOutlet=\"outputTemplate\"></ng-container>\n </ng-container>\n "
  2600. }),
  2601. __metadata("design:paramtypes", [TreeTable, TTEditableColumn])
  2602. ], TreeTableCellEditor);
  2603. return TreeTableCellEditor;
  2604. }());
  2605. exports.TreeTableCellEditor = TreeTableCellEditor;
  2606. var TTRow = /** @class */ (function () {
  2607. function TTRow(tt, el, zone) {
  2608. this.tt = tt;
  2609. this.el = el;
  2610. this.zone = zone;
  2611. }
  2612. TTRow.prototype.onKeyDown = function (event) {
  2613. switch (event.which) {
  2614. //down arrow
  2615. case 40:
  2616. var nextRow = this.el.nativeElement.nextElementSibling;
  2617. if (nextRow) {
  2618. nextRow.focus();
  2619. }
  2620. event.preventDefault();
  2621. break;
  2622. //down arrow
  2623. case 38:
  2624. var prevRow = this.el.nativeElement.previousElementSibling;
  2625. if (prevRow) {
  2626. prevRow.focus();
  2627. }
  2628. event.preventDefault();
  2629. break;
  2630. //left arrow
  2631. case 37:
  2632. if (this.rowNode.node.expanded) {
  2633. this.tt.toggleRowIndex = domhandler_1.DomHandler.index(this.el.nativeElement);
  2634. this.rowNode.node.expanded = false;
  2635. this.tt.onNodeCollapse.emit({
  2636. originalEvent: event,
  2637. node: this.rowNode.node
  2638. });
  2639. this.tt.updateSerializedValue();
  2640. this.tt.tableService.onUIUpdate(this.tt.value);
  2641. this.restoreFocus();
  2642. }
  2643. break;
  2644. //right arrow
  2645. case 39:
  2646. if (!this.rowNode.node.expanded) {
  2647. this.tt.toggleRowIndex = domhandler_1.DomHandler.index(this.el.nativeElement);
  2648. this.rowNode.node.expanded = true;
  2649. this.tt.onNodeExpand.emit({
  2650. originalEvent: event,
  2651. node: this.rowNode.node
  2652. });
  2653. this.tt.updateSerializedValue();
  2654. this.tt.tableService.onUIUpdate(this.tt.value);
  2655. this.restoreFocus();
  2656. }
  2657. break;
  2658. }
  2659. };
  2660. TTRow.prototype.restoreFocus = function () {
  2661. var _this = this;
  2662. this.zone.runOutsideAngular(function () {
  2663. setTimeout(function () {
  2664. var row = domhandler_1.DomHandler.findSingle(_this.tt.containerViewChild.nativeElement, '.ui-treetable-tbody').children[_this.tt.toggleRowIndex];
  2665. if (row) {
  2666. row.focus();
  2667. }
  2668. }, 25);
  2669. });
  2670. };
  2671. __decorate([
  2672. core_1.Input('ttRow'),
  2673. __metadata("design:type", Object)
  2674. ], TTRow.prototype, "rowNode", void 0);
  2675. __decorate([
  2676. core_1.HostListener('keydown', ['$event']),
  2677. __metadata("design:type", Function),
  2678. __metadata("design:paramtypes", [KeyboardEvent]),
  2679. __metadata("design:returntype", void 0)
  2680. ], TTRow.prototype, "onKeyDown", null);
  2681. TTRow = __decorate([
  2682. core_1.Directive({
  2683. selector: '[ttRow]',
  2684. host: {
  2685. '[attr.tabindex]': '"0"'
  2686. }
  2687. }),
  2688. __metadata("design:paramtypes", [TreeTable, core_1.ElementRef, core_1.NgZone])
  2689. ], TTRow);
  2690. return TTRow;
  2691. }());
  2692. exports.TTRow = TTRow;
  2693. var TreeTableToggler = /** @class */ (function () {
  2694. function TreeTableToggler(tt) {
  2695. this.tt = tt;
  2696. }
  2697. TreeTableToggler.prototype.onClick = function (event) {
  2698. this.rowNode.node.expanded = !this.rowNode.node.expanded;
  2699. if (this.rowNode.node.expanded) {
  2700. this.tt.onNodeExpand.emit({
  2701. originalEvent: event,
  2702. node: this.rowNode.node
  2703. });
  2704. }
  2705. else {
  2706. this.tt.onNodeCollapse.emit({
  2707. originalEvent: event,
  2708. node: this.rowNode.node
  2709. });
  2710. }
  2711. this.tt.updateSerializedValue();
  2712. this.tt.tableService.onUIUpdate(this.tt.value);
  2713. event.preventDefault();
  2714. };
  2715. __decorate([
  2716. core_1.Input(),
  2717. __metadata("design:type", Object)
  2718. ], TreeTableToggler.prototype, "rowNode", void 0);
  2719. TreeTableToggler = __decorate([
  2720. core_1.Component({
  2721. selector: 'p-treeTableToggler',
  2722. template: "\n <a class=\"ui-treetable-toggler ui-unselectable-text\" *ngIf=\"rowNode.node.leaf === false || rowNode.level !== 0 || rowNode.node.children && rowNode.node.children.length\" (click)=\"onClick($event)\"\n [style.visibility]=\"rowNode.node.leaf === false || (rowNode.node.children && rowNode.node.children.length) ? 'visible' : 'hidden'\" [style.marginLeft]=\"rowNode.level * 16 + 'px'\">\n <i [ngClass]=\"rowNode.node.expanded ? 'pi pi-fw pi-chevron-down' : 'pi pi-fw pi-chevron-right'\"></i>\n </a>\n "
  2723. }),
  2724. __metadata("design:paramtypes", [TreeTable])
  2725. ], TreeTableToggler);
  2726. return TreeTableToggler;
  2727. }());
  2728. exports.TreeTableToggler = TreeTableToggler;
  2729. var TreeTableModule = /** @class */ (function () {
  2730. function TreeTableModule() {
  2731. }
  2732. TreeTableModule = __decorate([
  2733. core_1.NgModule({
  2734. imports: [common_1.CommonModule, paginator_1.PaginatorModule],
  2735. exports: [TreeTable, shared_1.SharedModule, TreeTableToggler, TTSortableColumn, TTSortIcon, TTResizableColumn, TTRow, TTReorderableColumn, TTSelectableRow, TTSelectableRowDblClick, TTContextMenuRow, TTCheckbox, TTHeaderCheckbox, TTEditableColumn, TreeTableCellEditor],
  2736. declarations: [TreeTable, TreeTableToggler, TTScrollableView, TTBody, TTSortableColumn, TTSortIcon, TTResizableColumn, TTRow, TTReorderableColumn, TTSelectableRow, TTSelectableRowDblClick, TTContextMenuRow, TTCheckbox, TTHeaderCheckbox, TTEditableColumn, TreeTableCellEditor]
  2737. })
  2738. ], TreeTableModule);
  2739. return TreeTableModule;
  2740. }());
  2741. exports.TreeTableModule = TreeTableModule;
  2742. //# sourceMappingURL=treetable.js.map