table.es5.js 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { __extends } from 'tslib';
  9. import { coerceBooleanProperty } from '@angular/cdk/coercion';
  10. import { ContentChild, Directive, ElementRef, Input, TemplateRef, ChangeDetectionStrategy, Component, IterableDiffers, ViewContainerRef, ViewEncapsulation, Attribute, ChangeDetectorRef, ContentChildren, EmbeddedViewRef, Inject, isDevMode, Optional, ViewChild, InjectionToken, NgModule } from '@angular/core';
  11. import { Directionality } from '@angular/cdk/bidi';
  12. import { isDataSource } from '@angular/cdk/collections';
  13. export { DataSource } from '@angular/cdk/collections';
  14. import { Platform } from '@angular/cdk/platform';
  15. import { DOCUMENT, CommonModule } from '@angular/common';
  16. import { BehaviorSubject, Observable, of, Subject } from 'rxjs';
  17. import { takeUntil } from 'rxjs/operators';
  18. /**
  19. * @fileoverview added by tsickle
  20. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  21. */
  22. /**
  23. * Mixin to provide a directive with a function that checks if the sticky input has been
  24. * changed since the last time the function was called. Essentially adds a dirty-check to the
  25. * sticky value.
  26. * \@docs-private
  27. * @template T
  28. * @param {?} base
  29. * @return {?}
  30. */
  31. function mixinHasStickyInput(base) {
  32. return /** @class */ (function (_super) {
  33. __extends(class_1, _super);
  34. function class_1() {
  35. var args = [];
  36. for (var _i = 0; _i < arguments.length; _i++) {
  37. args[_i] = arguments[_i];
  38. }
  39. var _this = _super.apply(this, args) || this;
  40. _this._sticky = false;
  41. /**
  42. * Whether the sticky input has changed since it was last checked.
  43. */
  44. _this._hasStickyChanged = false;
  45. return _this;
  46. }
  47. Object.defineProperty(class_1.prototype, "sticky", {
  48. /** Whether sticky positioning should be applied. */
  49. get: /**
  50. * Whether sticky positioning should be applied.
  51. * @return {?}
  52. */
  53. function () { return this._sticky; },
  54. set: /**
  55. * @param {?} v
  56. * @return {?}
  57. */
  58. function (v) {
  59. /** @type {?} */
  60. var prevValue = this._sticky;
  61. this._sticky = coerceBooleanProperty(v);
  62. this._hasStickyChanged = prevValue !== this._sticky;
  63. },
  64. enumerable: true,
  65. configurable: true
  66. });
  67. /** Whether the sticky value has changed since this was last called. */
  68. /**
  69. * Whether the sticky value has changed since this was last called.
  70. * @return {?}
  71. */
  72. class_1.prototype.hasStickyChanged = /**
  73. * Whether the sticky value has changed since this was last called.
  74. * @return {?}
  75. */
  76. function () {
  77. /** @type {?} */
  78. var hasStickyChanged = this._hasStickyChanged;
  79. this._hasStickyChanged = false;
  80. return hasStickyChanged;
  81. };
  82. /** Resets the dirty check for cases where the sticky state has been used without checking. */
  83. /**
  84. * Resets the dirty check for cases where the sticky state has been used without checking.
  85. * @return {?}
  86. */
  87. class_1.prototype.resetStickyChanged = /**
  88. * Resets the dirty check for cases where the sticky state has been used without checking.
  89. * @return {?}
  90. */
  91. function () {
  92. this._hasStickyChanged = false;
  93. };
  94. return class_1;
  95. }(base));
  96. }
  97. /**
  98. * @fileoverview added by tsickle
  99. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  100. */
  101. /**
  102. * Cell definition for a CDK table.
  103. * Captures the template of a column's data row cell as well as cell-specific properties.
  104. */
  105. var CdkCellDef = /** @class */ (function () {
  106. function CdkCellDef(/** @docs-private */ template) {
  107. this.template = template;
  108. }
  109. CdkCellDef.decorators = [
  110. { type: Directive, args: [{ selector: '[cdkCellDef]' },] },
  111. ];
  112. /** @nocollapse */
  113. CdkCellDef.ctorParameters = function () { return [
  114. { type: TemplateRef }
  115. ]; };
  116. return CdkCellDef;
  117. }());
  118. /**
  119. * Header cell definition for a CDK table.
  120. * Captures the template of a column's header cell and as well as cell-specific properties.
  121. */
  122. var CdkHeaderCellDef = /** @class */ (function () {
  123. function CdkHeaderCellDef(/** @docs-private */ template) {
  124. this.template = template;
  125. }
  126. CdkHeaderCellDef.decorators = [
  127. { type: Directive, args: [{ selector: '[cdkHeaderCellDef]' },] },
  128. ];
  129. /** @nocollapse */
  130. CdkHeaderCellDef.ctorParameters = function () { return [
  131. { type: TemplateRef }
  132. ]; };
  133. return CdkHeaderCellDef;
  134. }());
  135. /**
  136. * Footer cell definition for a CDK table.
  137. * Captures the template of a column's footer cell and as well as cell-specific properties.
  138. */
  139. var CdkFooterCellDef = /** @class */ (function () {
  140. function CdkFooterCellDef(/** @docs-private */ template) {
  141. this.template = template;
  142. }
  143. CdkFooterCellDef.decorators = [
  144. { type: Directive, args: [{ selector: '[cdkFooterCellDef]' },] },
  145. ];
  146. /** @nocollapse */
  147. CdkFooterCellDef.ctorParameters = function () { return [
  148. { type: TemplateRef }
  149. ]; };
  150. return CdkFooterCellDef;
  151. }());
  152. // Boilerplate for applying mixins to CdkColumnDef.
  153. /**
  154. * \@docs-private
  155. */
  156. var
  157. // Boilerplate for applying mixins to CdkColumnDef.
  158. /**
  159. * \@docs-private
  160. */
  161. CdkColumnDefBase = /** @class */ (function () {
  162. function CdkColumnDefBase() {
  163. }
  164. return CdkColumnDefBase;
  165. }());
  166. /** @type {?} */
  167. var _CdkColumnDefBase = mixinHasStickyInput(CdkColumnDefBase);
  168. /**
  169. * Column definition for the CDK table.
  170. * Defines a set of cells available for a table column.
  171. */
  172. var CdkColumnDef = /** @class */ (function (_super) {
  173. __extends(CdkColumnDef, _super);
  174. function CdkColumnDef() {
  175. var _this = _super !== null && _super.apply(this, arguments) || this;
  176. _this._stickyEnd = false;
  177. return _this;
  178. }
  179. Object.defineProperty(CdkColumnDef.prototype, "name", {
  180. /** Unique name for this column. */
  181. get: /**
  182. * Unique name for this column.
  183. * @return {?}
  184. */
  185. function () {
  186. return this._name;
  187. },
  188. set: /**
  189. * @param {?} name
  190. * @return {?}
  191. */
  192. function (name) {
  193. // If the directive is set without a name (updated programatically), then this setter will
  194. // trigger with an empty string and should not overwrite the programatically set value.
  195. if (!name) {
  196. return;
  197. }
  198. this._name = name;
  199. this.cssClassFriendlyName = name.replace(/[^a-z0-9_-]/ig, '-');
  200. },
  201. enumerable: true,
  202. configurable: true
  203. });
  204. Object.defineProperty(CdkColumnDef.prototype, "stickyEnd", {
  205. /**
  206. * Whether this column should be sticky positioned on the end of the row. Should make sure
  207. * that it mimics the `CanStick` mixin such that `_hasStickyChanged` is set to true if the value
  208. * has been changed.
  209. */
  210. get: /**
  211. * Whether this column should be sticky positioned on the end of the row. Should make sure
  212. * that it mimics the `CanStick` mixin such that `_hasStickyChanged` is set to true if the value
  213. * has been changed.
  214. * @return {?}
  215. */
  216. function () {
  217. return this._stickyEnd;
  218. },
  219. set: /**
  220. * @param {?} v
  221. * @return {?}
  222. */
  223. function (v) {
  224. /** @type {?} */
  225. var prevValue = this._stickyEnd;
  226. this._stickyEnd = coerceBooleanProperty(v);
  227. this._hasStickyChanged = prevValue !== this._stickyEnd;
  228. },
  229. enumerable: true,
  230. configurable: true
  231. });
  232. CdkColumnDef.decorators = [
  233. { type: Directive, args: [{
  234. selector: '[cdkColumnDef]',
  235. inputs: ['sticky'],
  236. providers: [{ provide: 'MAT_SORT_HEADER_COLUMN_DEF', useExisting: CdkColumnDef }],
  237. },] },
  238. ];
  239. CdkColumnDef.propDecorators = {
  240. name: [{ type: Input, args: ['cdkColumnDef',] }],
  241. stickyEnd: [{ type: Input, args: ['stickyEnd',] }],
  242. cell: [{ type: ContentChild, args: [CdkCellDef, { static: false },] }],
  243. headerCell: [{ type: ContentChild, args: [CdkHeaderCellDef, { static: false },] }],
  244. footerCell: [{ type: ContentChild, args: [CdkFooterCellDef, { static: false },] }]
  245. };
  246. return CdkColumnDef;
  247. }(_CdkColumnDefBase));
  248. /**
  249. * Base class for the cells. Adds a CSS classname that identifies the column it renders in.
  250. */
  251. var /**
  252. * Base class for the cells. Adds a CSS classname that identifies the column it renders in.
  253. */
  254. BaseCdkCell = /** @class */ (function () {
  255. function BaseCdkCell(columnDef, elementRef) {
  256. /** @type {?} */
  257. var columnClassName = "cdk-column-" + columnDef.cssClassFriendlyName;
  258. elementRef.nativeElement.classList.add(columnClassName);
  259. }
  260. return BaseCdkCell;
  261. }());
  262. /**
  263. * Header cell template container that adds the right classes and role.
  264. */
  265. var CdkHeaderCell = /** @class */ (function (_super) {
  266. __extends(CdkHeaderCell, _super);
  267. function CdkHeaderCell(columnDef, elementRef) {
  268. return _super.call(this, columnDef, elementRef) || this;
  269. }
  270. CdkHeaderCell.decorators = [
  271. { type: Directive, args: [{
  272. selector: 'cdk-header-cell, th[cdk-header-cell]',
  273. host: {
  274. 'class': 'cdk-header-cell',
  275. 'role': 'columnheader',
  276. },
  277. },] },
  278. ];
  279. /** @nocollapse */
  280. CdkHeaderCell.ctorParameters = function () { return [
  281. { type: CdkColumnDef },
  282. { type: ElementRef }
  283. ]; };
  284. return CdkHeaderCell;
  285. }(BaseCdkCell));
  286. /**
  287. * Footer cell template container that adds the right classes and role.
  288. */
  289. var CdkFooterCell = /** @class */ (function (_super) {
  290. __extends(CdkFooterCell, _super);
  291. function CdkFooterCell(columnDef, elementRef) {
  292. return _super.call(this, columnDef, elementRef) || this;
  293. }
  294. CdkFooterCell.decorators = [
  295. { type: Directive, args: [{
  296. selector: 'cdk-footer-cell, td[cdk-footer-cell]',
  297. host: {
  298. 'class': 'cdk-footer-cell',
  299. 'role': 'gridcell',
  300. },
  301. },] },
  302. ];
  303. /** @nocollapse */
  304. CdkFooterCell.ctorParameters = function () { return [
  305. { type: CdkColumnDef },
  306. { type: ElementRef }
  307. ]; };
  308. return CdkFooterCell;
  309. }(BaseCdkCell));
  310. /**
  311. * Cell template container that adds the right classes and role.
  312. */
  313. var CdkCell = /** @class */ (function (_super) {
  314. __extends(CdkCell, _super);
  315. function CdkCell(columnDef, elementRef) {
  316. return _super.call(this, columnDef, elementRef) || this;
  317. }
  318. CdkCell.decorators = [
  319. { type: Directive, args: [{
  320. selector: 'cdk-cell, td[cdk-cell]',
  321. host: {
  322. 'class': 'cdk-cell',
  323. 'role': 'gridcell',
  324. },
  325. },] },
  326. ];
  327. /** @nocollapse */
  328. CdkCell.ctorParameters = function () { return [
  329. { type: CdkColumnDef },
  330. { type: ElementRef }
  331. ]; };
  332. return CdkCell;
  333. }(BaseCdkCell));
  334. /**
  335. * @fileoverview added by tsickle
  336. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  337. */
  338. /**
  339. * The row template that can be used by the mat-table. Should not be used outside of the
  340. * material library.
  341. * @type {?}
  342. */
  343. var CDK_ROW_TEMPLATE = "<ng-container cdkCellOutlet></ng-container>";
  344. /**
  345. * Base class for the CdkHeaderRowDef and CdkRowDef that handles checking their columns inputs
  346. * for changes and notifying the table.
  347. * @abstract
  348. */
  349. var /**
  350. * Base class for the CdkHeaderRowDef and CdkRowDef that handles checking their columns inputs
  351. * for changes and notifying the table.
  352. * @abstract
  353. */
  354. BaseRowDef = /** @class */ (function () {
  355. function BaseRowDef(template, _differs) {
  356. this.template = template;
  357. this._differs = _differs;
  358. }
  359. /**
  360. * @param {?} changes
  361. * @return {?}
  362. */
  363. BaseRowDef.prototype.ngOnChanges = /**
  364. * @param {?} changes
  365. * @return {?}
  366. */
  367. function (changes) {
  368. // Create a new columns differ if one does not yet exist. Initialize it based on initial value
  369. // of the columns property or an empty array if none is provided.
  370. if (!this._columnsDiffer) {
  371. /** @type {?} */
  372. var columns = (changes['columns'] && changes['columns'].currentValue) || [];
  373. this._columnsDiffer = this._differs.find(columns).create();
  374. this._columnsDiffer.diff(columns);
  375. }
  376. };
  377. /**
  378. * Returns the difference between the current columns and the columns from the last diff, or null
  379. * if there is no difference.
  380. */
  381. /**
  382. * Returns the difference between the current columns and the columns from the last diff, or null
  383. * if there is no difference.
  384. * @return {?}
  385. */
  386. BaseRowDef.prototype.getColumnsDiff = /**
  387. * Returns the difference between the current columns and the columns from the last diff, or null
  388. * if there is no difference.
  389. * @return {?}
  390. */
  391. function () {
  392. return this._columnsDiffer.diff(this.columns);
  393. };
  394. /** Gets this row def's relevant cell template from the provided column def. */
  395. /**
  396. * Gets this row def's relevant cell template from the provided column def.
  397. * @param {?} column
  398. * @return {?}
  399. */
  400. BaseRowDef.prototype.extractCellTemplate = /**
  401. * Gets this row def's relevant cell template from the provided column def.
  402. * @param {?} column
  403. * @return {?}
  404. */
  405. function (column) {
  406. if (this instanceof CdkHeaderRowDef) {
  407. return column.headerCell.template;
  408. }
  409. if (this instanceof CdkFooterRowDef) {
  410. return column.footerCell.template;
  411. }
  412. else {
  413. return column.cell.template;
  414. }
  415. };
  416. return BaseRowDef;
  417. }());
  418. // Boilerplate for applying mixins to CdkHeaderRowDef.
  419. /**
  420. * \@docs-private
  421. */
  422. var
  423. // Boilerplate for applying mixins to CdkHeaderRowDef.
  424. /**
  425. * \@docs-private
  426. */
  427. CdkHeaderRowDefBase = /** @class */ (function (_super) {
  428. __extends(CdkHeaderRowDefBase, _super);
  429. function CdkHeaderRowDefBase() {
  430. return _super !== null && _super.apply(this, arguments) || this;
  431. }
  432. return CdkHeaderRowDefBase;
  433. }(BaseRowDef));
  434. /** @type {?} */
  435. var _CdkHeaderRowDefBase = mixinHasStickyInput(CdkHeaderRowDefBase);
  436. /**
  437. * Header row definition for the CDK table.
  438. * Captures the header row's template and other header properties such as the columns to display.
  439. */
  440. var CdkHeaderRowDef = /** @class */ (function (_super) {
  441. __extends(CdkHeaderRowDef, _super);
  442. function CdkHeaderRowDef(template, _differs) {
  443. return _super.call(this, template, _differs) || this;
  444. }
  445. // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
  446. // Explicitly define it so that the method is called as part of the Angular lifecycle.
  447. // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
  448. // Explicitly define it so that the method is called as part of the Angular lifecycle.
  449. /**
  450. * @param {?} changes
  451. * @return {?}
  452. */
  453. CdkHeaderRowDef.prototype.ngOnChanges =
  454. // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
  455. // Explicitly define it so that the method is called as part of the Angular lifecycle.
  456. /**
  457. * @param {?} changes
  458. * @return {?}
  459. */
  460. function (changes) {
  461. _super.prototype.ngOnChanges.call(this, changes);
  462. };
  463. CdkHeaderRowDef.decorators = [
  464. { type: Directive, args: [{
  465. selector: '[cdkHeaderRowDef]',
  466. inputs: ['columns: cdkHeaderRowDef', 'sticky: cdkHeaderRowDefSticky'],
  467. },] },
  468. ];
  469. /** @nocollapse */
  470. CdkHeaderRowDef.ctorParameters = function () { return [
  471. { type: TemplateRef },
  472. { type: IterableDiffers }
  473. ]; };
  474. return CdkHeaderRowDef;
  475. }(_CdkHeaderRowDefBase));
  476. // Boilerplate for applying mixins to CdkFooterRowDef.
  477. /**
  478. * \@docs-private
  479. */
  480. var
  481. // Boilerplate for applying mixins to CdkFooterRowDef.
  482. /**
  483. * \@docs-private
  484. */
  485. CdkFooterRowDefBase = /** @class */ (function (_super) {
  486. __extends(CdkFooterRowDefBase, _super);
  487. function CdkFooterRowDefBase() {
  488. return _super !== null && _super.apply(this, arguments) || this;
  489. }
  490. return CdkFooterRowDefBase;
  491. }(BaseRowDef));
  492. /** @type {?} */
  493. var _CdkFooterRowDefBase = mixinHasStickyInput(CdkFooterRowDefBase);
  494. /**
  495. * Footer row definition for the CDK table.
  496. * Captures the footer row's template and other footer properties such as the columns to display.
  497. */
  498. var CdkFooterRowDef = /** @class */ (function (_super) {
  499. __extends(CdkFooterRowDef, _super);
  500. function CdkFooterRowDef(template, _differs) {
  501. return _super.call(this, template, _differs) || this;
  502. }
  503. // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
  504. // Explicitly define it so that the method is called as part of the Angular lifecycle.
  505. // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
  506. // Explicitly define it so that the method is called as part of the Angular lifecycle.
  507. /**
  508. * @param {?} changes
  509. * @return {?}
  510. */
  511. CdkFooterRowDef.prototype.ngOnChanges =
  512. // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
  513. // Explicitly define it so that the method is called as part of the Angular lifecycle.
  514. /**
  515. * @param {?} changes
  516. * @return {?}
  517. */
  518. function (changes) {
  519. _super.prototype.ngOnChanges.call(this, changes);
  520. };
  521. CdkFooterRowDef.decorators = [
  522. { type: Directive, args: [{
  523. selector: '[cdkFooterRowDef]',
  524. inputs: ['columns: cdkFooterRowDef', 'sticky: cdkFooterRowDefSticky'],
  525. },] },
  526. ];
  527. /** @nocollapse */
  528. CdkFooterRowDef.ctorParameters = function () { return [
  529. { type: TemplateRef },
  530. { type: IterableDiffers }
  531. ]; };
  532. return CdkFooterRowDef;
  533. }(_CdkFooterRowDefBase));
  534. /**
  535. * Data row definition for the CDK table.
  536. * Captures the header row's template and other row properties such as the columns to display and
  537. * a when predicate that describes when this row should be used.
  538. * @template T
  539. */
  540. var CdkRowDef = /** @class */ (function (_super) {
  541. __extends(CdkRowDef, _super);
  542. // TODO(andrewseguin): Add an input for providing a switch function to determine
  543. // if this template should be used.
  544. function CdkRowDef(template, _differs) {
  545. return _super.call(this, template, _differs) || this;
  546. }
  547. CdkRowDef.decorators = [
  548. { type: Directive, args: [{
  549. selector: '[cdkRowDef]',
  550. inputs: ['columns: cdkRowDefColumns', 'when: cdkRowDefWhen'],
  551. },] },
  552. ];
  553. /** @nocollapse */
  554. CdkRowDef.ctorParameters = function () { return [
  555. { type: TemplateRef },
  556. { type: IterableDiffers }
  557. ]; };
  558. return CdkRowDef;
  559. }(BaseRowDef));
  560. /**
  561. * Outlet for rendering cells inside of a row or header row.
  562. * \@docs-private
  563. */
  564. var CdkCellOutlet = /** @class */ (function () {
  565. function CdkCellOutlet(_viewContainer) {
  566. this._viewContainer = _viewContainer;
  567. CdkCellOutlet.mostRecentCellOutlet = this;
  568. }
  569. /**
  570. * @return {?}
  571. */
  572. CdkCellOutlet.prototype.ngOnDestroy = /**
  573. * @return {?}
  574. */
  575. function () {
  576. // If this was the last outlet being rendered in the view, remove the reference
  577. // from the static property after it has been destroyed to avoid leaking memory.
  578. if (CdkCellOutlet.mostRecentCellOutlet === this) {
  579. CdkCellOutlet.mostRecentCellOutlet = null;
  580. }
  581. };
  582. /**
  583. * Static property containing the latest constructed instance of this class.
  584. * Used by the CDK table when each CdkHeaderRow and CdkRow component is created using
  585. * createEmbeddedView. After one of these components are created, this property will provide
  586. * a handle to provide that component's cells and context. After init, the CdkCellOutlet will
  587. * construct the cells with the provided context.
  588. */
  589. CdkCellOutlet.mostRecentCellOutlet = null;
  590. CdkCellOutlet.decorators = [
  591. { type: Directive, args: [{ selector: '[cdkCellOutlet]' },] },
  592. ];
  593. /** @nocollapse */
  594. CdkCellOutlet.ctorParameters = function () { return [
  595. { type: ViewContainerRef }
  596. ]; };
  597. return CdkCellOutlet;
  598. }());
  599. /**
  600. * Header template container that contains the cell outlet. Adds the right class and role.
  601. */
  602. var CdkHeaderRow = /** @class */ (function () {
  603. function CdkHeaderRow() {
  604. }
  605. CdkHeaderRow.decorators = [
  606. { type: Component, args: [{selector: 'cdk-header-row, tr[cdk-header-row]',
  607. template: CDK_ROW_TEMPLATE,
  608. host: {
  609. 'class': 'cdk-header-row',
  610. 'role': 'row',
  611. },
  612. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  613. // tslint:disable-next-line:validate-decorators
  614. changeDetection: ChangeDetectionStrategy.Default,
  615. encapsulation: ViewEncapsulation.None,
  616. },] },
  617. ];
  618. return CdkHeaderRow;
  619. }());
  620. /**
  621. * Footer template container that contains the cell outlet. Adds the right class and role.
  622. */
  623. var CdkFooterRow = /** @class */ (function () {
  624. function CdkFooterRow() {
  625. }
  626. CdkFooterRow.decorators = [
  627. { type: Component, args: [{selector: 'cdk-footer-row, tr[cdk-footer-row]',
  628. template: CDK_ROW_TEMPLATE,
  629. host: {
  630. 'class': 'cdk-footer-row',
  631. 'role': 'row',
  632. },
  633. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  634. // tslint:disable-next-line:validate-decorators
  635. changeDetection: ChangeDetectionStrategy.Default,
  636. encapsulation: ViewEncapsulation.None,
  637. },] },
  638. ];
  639. return CdkFooterRow;
  640. }());
  641. /**
  642. * Data row template container that contains the cell outlet. Adds the right class and role.
  643. */
  644. var CdkRow = /** @class */ (function () {
  645. function CdkRow() {
  646. }
  647. CdkRow.decorators = [
  648. { type: Component, args: [{selector: 'cdk-row, tr[cdk-row]',
  649. template: CDK_ROW_TEMPLATE,
  650. host: {
  651. 'class': 'cdk-row',
  652. 'role': 'row',
  653. },
  654. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  655. // tslint:disable-next-line:validate-decorators
  656. changeDetection: ChangeDetectionStrategy.Default,
  657. encapsulation: ViewEncapsulation.None,
  658. },] },
  659. ];
  660. return CdkRow;
  661. }());
  662. /**
  663. * @fileoverview added by tsickle
  664. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  665. */
  666. /**
  667. * List of all possible directions that can be used for sticky positioning.
  668. * \@docs-private
  669. * @type {?}
  670. */
  671. var STICKY_DIRECTIONS = ['top', 'bottom', 'left', 'right'];
  672. /**
  673. * Applies and removes sticky positioning styles to the `CdkTable` rows and columns cells.
  674. * \@docs-private
  675. */
  676. var /**
  677. * Applies and removes sticky positioning styles to the `CdkTable` rows and columns cells.
  678. * \@docs-private
  679. */
  680. StickyStyler = /** @class */ (function () {
  681. /**
  682. * @param _isNativeHtmlTable Whether the sticky logic should be based on a table
  683. * that uses the native `<table>` element.
  684. * @param _stickCellCss The CSS class that will be applied to every row/cell that has
  685. * sticky positioning applied.
  686. * @param direction The directionality context of the table (ltr/rtl); affects column positioning
  687. * by reversing left/right positions.
  688. * @param _isBrowser Whether the table is currently being rendered on the server or the client.
  689. */
  690. function StickyStyler(_isNativeHtmlTable, _stickCellCss, direction, _isBrowser) {
  691. if (_isBrowser === void 0) { _isBrowser = true; }
  692. this._isNativeHtmlTable = _isNativeHtmlTable;
  693. this._stickCellCss = _stickCellCss;
  694. this.direction = direction;
  695. this._isBrowser = _isBrowser;
  696. }
  697. /**
  698. * Clears the sticky positioning styles from the row and its cells by resetting the `position`
  699. * style, setting the zIndex to 0, and unsetting each provided sticky direction.
  700. * @param rows The list of rows that should be cleared from sticking in the provided directions
  701. * @param stickyDirections The directions that should no longer be set as sticky on the rows.
  702. */
  703. /**
  704. * Clears the sticky positioning styles from the row and its cells by resetting the `position`
  705. * style, setting the zIndex to 0, and unsetting each provided sticky direction.
  706. * @param {?} rows The list of rows that should be cleared from sticking in the provided directions
  707. * @param {?} stickyDirections The directions that should no longer be set as sticky on the rows.
  708. * @return {?}
  709. */
  710. StickyStyler.prototype.clearStickyPositioning = /**
  711. * Clears the sticky positioning styles from the row and its cells by resetting the `position`
  712. * style, setting the zIndex to 0, and unsetting each provided sticky direction.
  713. * @param {?} rows The list of rows that should be cleared from sticking in the provided directions
  714. * @param {?} stickyDirections The directions that should no longer be set as sticky on the rows.
  715. * @return {?}
  716. */
  717. function (rows, stickyDirections) {
  718. for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
  719. var row = rows_1[_i];
  720. // If the row isn't an element (e.g. if it's an `ng-container`),
  721. // it won't have inline styles or `children` so we skip it.
  722. if (row.nodeType !== row.ELEMENT_NODE) {
  723. continue;
  724. }
  725. this._removeStickyStyle(row, stickyDirections);
  726. for (var i = 0; i < row.children.length; i++) {
  727. /** @type {?} */
  728. var cell = (/** @type {?} */ (row.children[i]));
  729. this._removeStickyStyle(cell, stickyDirections);
  730. }
  731. }
  732. };
  733. /**
  734. * Applies sticky left and right positions to the cells of each row according to the sticky
  735. * states of the rendered column definitions.
  736. * @param rows The rows that should have its set of cells stuck according to the sticky states.
  737. * @param stickyStartStates A list of boolean states where each state represents whether the cell
  738. * in this index position should be stuck to the start of the row.
  739. * @param stickyEndStates A list of boolean states where each state represents whether the cell
  740. * in this index position should be stuck to the end of the row.
  741. */
  742. /**
  743. * Applies sticky left and right positions to the cells of each row according to the sticky
  744. * states of the rendered column definitions.
  745. * @param {?} rows The rows that should have its set of cells stuck according to the sticky states.
  746. * @param {?} stickyStartStates A list of boolean states where each state represents whether the cell
  747. * in this index position should be stuck to the start of the row.
  748. * @param {?} stickyEndStates A list of boolean states where each state represents whether the cell
  749. * in this index position should be stuck to the end of the row.
  750. * @return {?}
  751. */
  752. StickyStyler.prototype.updateStickyColumns = /**
  753. * Applies sticky left and right positions to the cells of each row according to the sticky
  754. * states of the rendered column definitions.
  755. * @param {?} rows The rows that should have its set of cells stuck according to the sticky states.
  756. * @param {?} stickyStartStates A list of boolean states where each state represents whether the cell
  757. * in this index position should be stuck to the start of the row.
  758. * @param {?} stickyEndStates A list of boolean states where each state represents whether the cell
  759. * in this index position should be stuck to the end of the row.
  760. * @return {?}
  761. */
  762. function (rows, stickyStartStates, stickyEndStates) {
  763. /** @type {?} */
  764. var hasStickyColumns = stickyStartStates.some((/**
  765. * @param {?} state
  766. * @return {?}
  767. */
  768. function (state) { return state; })) || stickyEndStates.some((/**
  769. * @param {?} state
  770. * @return {?}
  771. */
  772. function (state) { return state; }));
  773. if (!rows.length || !hasStickyColumns || !this._isBrowser) {
  774. return;
  775. }
  776. /** @type {?} */
  777. var firstRow = rows[0];
  778. /** @type {?} */
  779. var numCells = firstRow.children.length;
  780. /** @type {?} */
  781. var cellWidths = this._getCellWidths(firstRow);
  782. /** @type {?} */
  783. var startPositions = this._getStickyStartColumnPositions(cellWidths, stickyStartStates);
  784. /** @type {?} */
  785. var endPositions = this._getStickyEndColumnPositions(cellWidths, stickyEndStates);
  786. /** @type {?} */
  787. var isRtl = this.direction === 'rtl';
  788. for (var _i = 0, rows_2 = rows; _i < rows_2.length; _i++) {
  789. var row = rows_2[_i];
  790. for (var i = 0; i < numCells; i++) {
  791. /** @type {?} */
  792. var cell = (/** @type {?} */ (row.children[i]));
  793. if (stickyStartStates[i]) {
  794. this._addStickyStyle(cell, isRtl ? 'right' : 'left', startPositions[i]);
  795. }
  796. if (stickyEndStates[i]) {
  797. this._addStickyStyle(cell, isRtl ? 'left' : 'right', endPositions[i]);
  798. }
  799. }
  800. }
  801. };
  802. /**
  803. * Applies sticky positioning to the row's cells if using the native table layout, and to the
  804. * row itself otherwise.
  805. * @param rowsToStick The list of rows that should be stuck according to their corresponding
  806. * sticky state and to the provided top or bottom position.
  807. * @param stickyStates A list of boolean states where each state represents whether the row
  808. * should be stuck in the particular top or bottom position.
  809. * @param position The position direction in which the row should be stuck if that row should be
  810. * sticky.
  811. *
  812. */
  813. /**
  814. * Applies sticky positioning to the row's cells if using the native table layout, and to the
  815. * row itself otherwise.
  816. * @param {?} rowsToStick The list of rows that should be stuck according to their corresponding
  817. * sticky state and to the provided top or bottom position.
  818. * @param {?} stickyStates A list of boolean states where each state represents whether the row
  819. * should be stuck in the particular top or bottom position.
  820. * @param {?} position The position direction in which the row should be stuck if that row should be
  821. * sticky.
  822. *
  823. * @return {?}
  824. */
  825. StickyStyler.prototype.stickRows = /**
  826. * Applies sticky positioning to the row's cells if using the native table layout, and to the
  827. * row itself otherwise.
  828. * @param {?} rowsToStick The list of rows that should be stuck according to their corresponding
  829. * sticky state and to the provided top or bottom position.
  830. * @param {?} stickyStates A list of boolean states where each state represents whether the row
  831. * should be stuck in the particular top or bottom position.
  832. * @param {?} position The position direction in which the row should be stuck if that row should be
  833. * sticky.
  834. *
  835. * @return {?}
  836. */
  837. function (rowsToStick, stickyStates, position) {
  838. // Since we can't measure the rows on the server, we can't stick the rows properly.
  839. if (!this._isBrowser) {
  840. return;
  841. }
  842. // If positioning the rows to the bottom, reverse their order when evaluating the sticky
  843. // position such that the last row stuck will be "bottom: 0px" and so on.
  844. /** @type {?} */
  845. var rows = position === 'bottom' ? rowsToStick.reverse() : rowsToStick;
  846. /** @type {?} */
  847. var stickyHeight = 0;
  848. for (var rowIndex = 0; rowIndex < rows.length; rowIndex++) {
  849. if (!stickyStates[rowIndex]) {
  850. continue;
  851. }
  852. /** @type {?} */
  853. var row = rows[rowIndex];
  854. if (this._isNativeHtmlTable) {
  855. for (var j = 0; j < row.children.length; j++) {
  856. /** @type {?} */
  857. var cell = (/** @type {?} */ (row.children[j]));
  858. this._addStickyStyle(cell, position, stickyHeight);
  859. }
  860. }
  861. else {
  862. // Flex does not respect the stick positioning on the cells, needs to be applied to the row.
  863. // If this is applied on a native table, Safari causes the header to fly in wrong direction.
  864. this._addStickyStyle(row, position, stickyHeight);
  865. }
  866. if (rowIndex === rows.length - 1) {
  867. // prevent unnecessary reflow from getBoundingClientRect()
  868. return;
  869. }
  870. stickyHeight += row.getBoundingClientRect().height;
  871. }
  872. };
  873. /**
  874. * When using the native table in Safari, sticky footer cells do not stick. The only way to stick
  875. * footer rows is to apply sticky styling to the tfoot container. This should only be done if
  876. * all footer rows are sticky. If not all footer rows are sticky, remove sticky positioning from
  877. * the tfoot element.
  878. */
  879. /**
  880. * When using the native table in Safari, sticky footer cells do not stick. The only way to stick
  881. * footer rows is to apply sticky styling to the tfoot container. This should only be done if
  882. * all footer rows are sticky. If not all footer rows are sticky, remove sticky positioning from
  883. * the tfoot element.
  884. * @param {?} tableElement
  885. * @param {?} stickyStates
  886. * @return {?}
  887. */
  888. StickyStyler.prototype.updateStickyFooterContainer = /**
  889. * When using the native table in Safari, sticky footer cells do not stick. The only way to stick
  890. * footer rows is to apply sticky styling to the tfoot container. This should only be done if
  891. * all footer rows are sticky. If not all footer rows are sticky, remove sticky positioning from
  892. * the tfoot element.
  893. * @param {?} tableElement
  894. * @param {?} stickyStates
  895. * @return {?}
  896. */
  897. function (tableElement, stickyStates) {
  898. if (!this._isNativeHtmlTable) {
  899. return;
  900. }
  901. /** @type {?} */
  902. var tfoot = (/** @type {?} */ (tableElement.querySelector('tfoot')));
  903. if (stickyStates.some((/**
  904. * @param {?} state
  905. * @return {?}
  906. */
  907. function (state) { return !state; }))) {
  908. this._removeStickyStyle(tfoot, ['bottom']);
  909. }
  910. else {
  911. this._addStickyStyle(tfoot, 'bottom', 0);
  912. }
  913. };
  914. /**
  915. * Removes the sticky style on the element by removing the sticky cell CSS class, re-evaluating
  916. * the zIndex, removing each of the provided sticky directions, and removing the
  917. * sticky position if there are no more directions.
  918. */
  919. /**
  920. * Removes the sticky style on the element by removing the sticky cell CSS class, re-evaluating
  921. * the zIndex, removing each of the provided sticky directions, and removing the
  922. * sticky position if there are no more directions.
  923. * @param {?} element
  924. * @param {?} stickyDirections
  925. * @return {?}
  926. */
  927. StickyStyler.prototype._removeStickyStyle = /**
  928. * Removes the sticky style on the element by removing the sticky cell CSS class, re-evaluating
  929. * the zIndex, removing each of the provided sticky directions, and removing the
  930. * sticky position if there are no more directions.
  931. * @param {?} element
  932. * @param {?} stickyDirections
  933. * @return {?}
  934. */
  935. function (element, stickyDirections) {
  936. for (var _i = 0, stickyDirections_1 = stickyDirections; _i < stickyDirections_1.length; _i++) {
  937. var dir = stickyDirections_1[_i];
  938. element.style[dir] = '';
  939. }
  940. element.style.zIndex = this._getCalculatedZIndex(element);
  941. // If the element no longer has any more sticky directions, remove sticky positioning and
  942. // the sticky CSS class.
  943. /** @type {?} */
  944. var hasDirection = STICKY_DIRECTIONS.some((/**
  945. * @param {?} dir
  946. * @return {?}
  947. */
  948. function (dir) { return !!element.style[dir]; }));
  949. if (!hasDirection) {
  950. element.style.position = '';
  951. element.classList.remove(this._stickCellCss);
  952. }
  953. };
  954. /**
  955. * Adds the sticky styling to the element by adding the sticky style class, changing position
  956. * to be sticky (and -webkit-sticky), setting the appropriate zIndex, and adding a sticky
  957. * direction and value.
  958. */
  959. /**
  960. * Adds the sticky styling to the element by adding the sticky style class, changing position
  961. * to be sticky (and -webkit-sticky), setting the appropriate zIndex, and adding a sticky
  962. * direction and value.
  963. * @param {?} element
  964. * @param {?} dir
  965. * @param {?} dirValue
  966. * @return {?}
  967. */
  968. StickyStyler.prototype._addStickyStyle = /**
  969. * Adds the sticky styling to the element by adding the sticky style class, changing position
  970. * to be sticky (and -webkit-sticky), setting the appropriate zIndex, and adding a sticky
  971. * direction and value.
  972. * @param {?} element
  973. * @param {?} dir
  974. * @param {?} dirValue
  975. * @return {?}
  976. */
  977. function (element, dir, dirValue) {
  978. element.classList.add(this._stickCellCss);
  979. element.style[dir] = dirValue + "px";
  980. element.style.cssText += 'position: -webkit-sticky; position: sticky; ';
  981. element.style.zIndex = this._getCalculatedZIndex(element);
  982. };
  983. /**
  984. * Calculate what the z-index should be for the element, depending on what directions (top,
  985. * bottom, left, right) have been set. It should be true that elements with a top direction
  986. * should have the highest index since these are elements like a table header. If any of those
  987. * elements are also sticky in another direction, then they should appear above other elements
  988. * that are only sticky top (e.g. a sticky column on a sticky header). Bottom-sticky elements
  989. * (e.g. footer rows) should then be next in the ordering such that they are below the header
  990. * but above any non-sticky elements. Finally, left/right sticky elements (e.g. sticky columns)
  991. * should minimally increment so that they are above non-sticky elements but below top and bottom
  992. * elements.
  993. */
  994. /**
  995. * Calculate what the z-index should be for the element, depending on what directions (top,
  996. * bottom, left, right) have been set. It should be true that elements with a top direction
  997. * should have the highest index since these are elements like a table header. If any of those
  998. * elements are also sticky in another direction, then they should appear above other elements
  999. * that are only sticky top (e.g. a sticky column on a sticky header). Bottom-sticky elements
  1000. * (e.g. footer rows) should then be next in the ordering such that they are below the header
  1001. * but above any non-sticky elements. Finally, left/right sticky elements (e.g. sticky columns)
  1002. * should minimally increment so that they are above non-sticky elements but below top and bottom
  1003. * elements.
  1004. * @param {?} element
  1005. * @return {?}
  1006. */
  1007. StickyStyler.prototype._getCalculatedZIndex = /**
  1008. * Calculate what the z-index should be for the element, depending on what directions (top,
  1009. * bottom, left, right) have been set. It should be true that elements with a top direction
  1010. * should have the highest index since these are elements like a table header. If any of those
  1011. * elements are also sticky in another direction, then they should appear above other elements
  1012. * that are only sticky top (e.g. a sticky column on a sticky header). Bottom-sticky elements
  1013. * (e.g. footer rows) should then be next in the ordering such that they are below the header
  1014. * but above any non-sticky elements. Finally, left/right sticky elements (e.g. sticky columns)
  1015. * should minimally increment so that they are above non-sticky elements but below top and bottom
  1016. * elements.
  1017. * @param {?} element
  1018. * @return {?}
  1019. */
  1020. function (element) {
  1021. /** @type {?} */
  1022. var zIndexIncrements = {
  1023. top: 100,
  1024. bottom: 10,
  1025. left: 1,
  1026. right: 1,
  1027. };
  1028. /** @type {?} */
  1029. var zIndex = 0;
  1030. for (var _i = 0, STICKY_DIRECTIONS_1 = STICKY_DIRECTIONS; _i < STICKY_DIRECTIONS_1.length; _i++) {
  1031. var dir = STICKY_DIRECTIONS_1[_i];
  1032. if (element.style[dir]) {
  1033. zIndex += zIndexIncrements[dir];
  1034. }
  1035. }
  1036. return zIndex ? "" + zIndex : '';
  1037. };
  1038. /** Gets the widths for each cell in the provided row. */
  1039. /**
  1040. * Gets the widths for each cell in the provided row.
  1041. * @param {?} row
  1042. * @return {?}
  1043. */
  1044. StickyStyler.prototype._getCellWidths = /**
  1045. * Gets the widths for each cell in the provided row.
  1046. * @param {?} row
  1047. * @return {?}
  1048. */
  1049. function (row) {
  1050. /** @type {?} */
  1051. var cellWidths = [];
  1052. /** @type {?} */
  1053. var firstRowCells = row.children;
  1054. for (var i = 0; i < firstRowCells.length; i++) {
  1055. /** @type {?} */
  1056. var cell = (/** @type {?} */ (firstRowCells[i]));
  1057. cellWidths.push(cell.getBoundingClientRect().width);
  1058. }
  1059. return cellWidths;
  1060. };
  1061. /**
  1062. * Determines the left and right positions of each sticky column cell, which will be the
  1063. * accumulation of all sticky column cell widths to the left and right, respectively.
  1064. * Non-sticky cells do not need to have a value set since their positions will not be applied.
  1065. */
  1066. /**
  1067. * Determines the left and right positions of each sticky column cell, which will be the
  1068. * accumulation of all sticky column cell widths to the left and right, respectively.
  1069. * Non-sticky cells do not need to have a value set since their positions will not be applied.
  1070. * @param {?} widths
  1071. * @param {?} stickyStates
  1072. * @return {?}
  1073. */
  1074. StickyStyler.prototype._getStickyStartColumnPositions = /**
  1075. * Determines the left and right positions of each sticky column cell, which will be the
  1076. * accumulation of all sticky column cell widths to the left and right, respectively.
  1077. * Non-sticky cells do not need to have a value set since their positions will not be applied.
  1078. * @param {?} widths
  1079. * @param {?} stickyStates
  1080. * @return {?}
  1081. */
  1082. function (widths, stickyStates) {
  1083. /** @type {?} */
  1084. var positions = [];
  1085. /** @type {?} */
  1086. var nextPosition = 0;
  1087. for (var i = 0; i < widths.length; i++) {
  1088. if (stickyStates[i]) {
  1089. positions[i] = nextPosition;
  1090. nextPosition += widths[i];
  1091. }
  1092. }
  1093. return positions;
  1094. };
  1095. /**
  1096. * Determines the left and right positions of each sticky column cell, which will be the
  1097. * accumulation of all sticky column cell widths to the left and right, respectively.
  1098. * Non-sticky cells do not need to have a value set since their positions will not be applied.
  1099. */
  1100. /**
  1101. * Determines the left and right positions of each sticky column cell, which will be the
  1102. * accumulation of all sticky column cell widths to the left and right, respectively.
  1103. * Non-sticky cells do not need to have a value set since their positions will not be applied.
  1104. * @param {?} widths
  1105. * @param {?} stickyStates
  1106. * @return {?}
  1107. */
  1108. StickyStyler.prototype._getStickyEndColumnPositions = /**
  1109. * Determines the left and right positions of each sticky column cell, which will be the
  1110. * accumulation of all sticky column cell widths to the left and right, respectively.
  1111. * Non-sticky cells do not need to have a value set since their positions will not be applied.
  1112. * @param {?} widths
  1113. * @param {?} stickyStates
  1114. * @return {?}
  1115. */
  1116. function (widths, stickyStates) {
  1117. /** @type {?} */
  1118. var positions = [];
  1119. /** @type {?} */
  1120. var nextPosition = 0;
  1121. for (var i = widths.length; i > 0; i--) {
  1122. if (stickyStates[i]) {
  1123. positions[i] = nextPosition;
  1124. nextPosition += widths[i];
  1125. }
  1126. }
  1127. return positions;
  1128. };
  1129. return StickyStyler;
  1130. }());
  1131. /**
  1132. * @fileoverview added by tsickle
  1133. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1134. */
  1135. /**
  1136. * Returns an error to be thrown when attempting to find an unexisting column.
  1137. * \@docs-private
  1138. * @param {?} id Id whose lookup failed.
  1139. * @return {?}
  1140. */
  1141. function getTableUnknownColumnError(id) {
  1142. return Error("Could not find column with id \"" + id + "\".");
  1143. }
  1144. /**
  1145. * Returns an error to be thrown when two column definitions have the same name.
  1146. * \@docs-private
  1147. * @param {?} name
  1148. * @return {?}
  1149. */
  1150. function getTableDuplicateColumnNameError(name) {
  1151. return Error("Duplicate column definition name provided: \"" + name + "\".");
  1152. }
  1153. /**
  1154. * Returns an error to be thrown when there are multiple rows that are missing a when function.
  1155. * \@docs-private
  1156. * @return {?}
  1157. */
  1158. function getTableMultipleDefaultRowDefsError() {
  1159. return Error("There can only be one default row without a when predicate function.");
  1160. }
  1161. /**
  1162. * Returns an error to be thrown when there are no matching row defs for a particular set of data.
  1163. * \@docs-private
  1164. * @param {?} data
  1165. * @return {?}
  1166. */
  1167. function getTableMissingMatchingRowDefError(data) {
  1168. return Error("Could not find a matching row definition for the" +
  1169. ("provided row data: " + JSON.stringify(data)));
  1170. }
  1171. /**
  1172. * Returns an error to be thrown when there is no row definitions present in the content.
  1173. * \@docs-private
  1174. * @return {?}
  1175. */
  1176. function getTableMissingRowDefsError() {
  1177. return Error('Missing definitions for header, footer, and row; ' +
  1178. 'cannot determine which columns should be rendered.');
  1179. }
  1180. /**
  1181. * Returns an error to be thrown when the data source does not match the compatible types.
  1182. * \@docs-private
  1183. * @return {?}
  1184. */
  1185. function getTableUnknownDataSourceError() {
  1186. return Error("Provided data source did not match an array, Observable, or DataSource");
  1187. }
  1188. /**
  1189. * Returns an error to be thrown when the text column cannot find a parent table to inject.
  1190. * \@docs-private
  1191. * @return {?}
  1192. */
  1193. function getTableTextColumnMissingParentTableError() {
  1194. return Error("Text column could not find a parent table for registration.");
  1195. }
  1196. /**
  1197. * Returns an error to be thrown when a table text column doesn't have a name.
  1198. * \@docs-private
  1199. * @return {?}
  1200. */
  1201. function getTableTextColumnMissingNameError() {
  1202. return Error("Table text column must have a name.");
  1203. }
  1204. /**
  1205. * @fileoverview added by tsickle
  1206. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1207. */
  1208. /**
  1209. * Provides a handle for the table to grab the view container's ng-container to insert data rows.
  1210. * \@docs-private
  1211. */
  1212. var DataRowOutlet = /** @class */ (function () {
  1213. function DataRowOutlet(viewContainer, elementRef) {
  1214. this.viewContainer = viewContainer;
  1215. this.elementRef = elementRef;
  1216. }
  1217. DataRowOutlet.decorators = [
  1218. { type: Directive, args: [{ selector: '[rowOutlet]' },] },
  1219. ];
  1220. /** @nocollapse */
  1221. DataRowOutlet.ctorParameters = function () { return [
  1222. { type: ViewContainerRef },
  1223. { type: ElementRef }
  1224. ]; };
  1225. return DataRowOutlet;
  1226. }());
  1227. /**
  1228. * Provides a handle for the table to grab the view container's ng-container to insert the header.
  1229. * \@docs-private
  1230. */
  1231. var HeaderRowOutlet = /** @class */ (function () {
  1232. function HeaderRowOutlet(viewContainer, elementRef) {
  1233. this.viewContainer = viewContainer;
  1234. this.elementRef = elementRef;
  1235. }
  1236. HeaderRowOutlet.decorators = [
  1237. { type: Directive, args: [{ selector: '[headerRowOutlet]' },] },
  1238. ];
  1239. /** @nocollapse */
  1240. HeaderRowOutlet.ctorParameters = function () { return [
  1241. { type: ViewContainerRef },
  1242. { type: ElementRef }
  1243. ]; };
  1244. return HeaderRowOutlet;
  1245. }());
  1246. /**
  1247. * Provides a handle for the table to grab the view container's ng-container to insert the footer.
  1248. * \@docs-private
  1249. */
  1250. var FooterRowOutlet = /** @class */ (function () {
  1251. function FooterRowOutlet(viewContainer, elementRef) {
  1252. this.viewContainer = viewContainer;
  1253. this.elementRef = elementRef;
  1254. }
  1255. FooterRowOutlet.decorators = [
  1256. { type: Directive, args: [{ selector: '[footerRowOutlet]' },] },
  1257. ];
  1258. /** @nocollapse */
  1259. FooterRowOutlet.ctorParameters = function () { return [
  1260. { type: ViewContainerRef },
  1261. { type: ElementRef }
  1262. ]; };
  1263. return FooterRowOutlet;
  1264. }());
  1265. /**
  1266. * The table template that can be used by the mat-table. Should not be used outside of the
  1267. * material library.
  1268. * \@docs-private
  1269. * @type {?}
  1270. */
  1271. var CDK_TABLE_TEMPLATE =
  1272. // Note that according to MDN, the `caption` element has to be projected as the **first**
  1273. // element in the table. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption
  1274. "\n <ng-content select=\"caption\"></ng-content>\n <ng-container headerRowOutlet></ng-container>\n <ng-container rowOutlet></ng-container>\n <ng-container footerRowOutlet></ng-container>\n";
  1275. /**
  1276. * Class used to conveniently type the embedded view ref for rows with a context.
  1277. * \@docs-private
  1278. * @abstract
  1279. * @template T
  1280. */
  1281. var /**
  1282. * Class used to conveniently type the embedded view ref for rows with a context.
  1283. * \@docs-private
  1284. * @abstract
  1285. * @template T
  1286. */
  1287. RowViewRef = /** @class */ (function (_super) {
  1288. __extends(RowViewRef, _super);
  1289. function RowViewRef() {
  1290. return _super !== null && _super.apply(this, arguments) || this;
  1291. }
  1292. return RowViewRef;
  1293. }(EmbeddedViewRef));
  1294. /**
  1295. * A data table that can render a header row, data rows, and a footer row.
  1296. * Uses the dataSource input to determine the data to be rendered. The data can be provided either
  1297. * as a data array, an Observable stream that emits the data array to render, or a DataSource with a
  1298. * connect function that will return an Observable stream that emits the data array to render.
  1299. * @template T
  1300. */
  1301. var CdkTable = /** @class */ (function () {
  1302. function CdkTable(_differs, _changeDetectorRef, _elementRef, role, _dir, _document, _platform) {
  1303. this._differs = _differs;
  1304. this._changeDetectorRef = _changeDetectorRef;
  1305. this._elementRef = _elementRef;
  1306. this._dir = _dir;
  1307. this._platform = _platform;
  1308. /**
  1309. * Subject that emits when the component has been destroyed.
  1310. */
  1311. this._onDestroy = new Subject();
  1312. /**
  1313. * Map of all the user's defined columns (header, data, and footer cell template) identified by
  1314. * name. Collection populated by the column definitions gathered by `ContentChildren` as well as
  1315. * any custom column definitions added to `_customColumnDefs`.
  1316. */
  1317. this._columnDefsByName = new Map();
  1318. /**
  1319. * Column definitions that were defined outside of the direct content children of the table.
  1320. * These will be defined when, e.g., creating a wrapper around the cdkTable that has
  1321. * column definitions as *its* content child.
  1322. */
  1323. this._customColumnDefs = new Set();
  1324. /**
  1325. * Data row definitions that were defined outside of the direct content children of the table.
  1326. * These will be defined when, e.g., creating a wrapper around the cdkTable that has
  1327. * built-in data rows as *its* content child.
  1328. */
  1329. this._customRowDefs = new Set();
  1330. /**
  1331. * Header row definitions that were defined outside of the direct content children of the table.
  1332. * These will be defined when, e.g., creating a wrapper around the cdkTable that has
  1333. * built-in header rows as *its* content child.
  1334. */
  1335. this._customHeaderRowDefs = new Set();
  1336. /**
  1337. * Footer row definitions that were defined outside of the direct content children of the table.
  1338. * These will be defined when, e.g., creating a wrapper around the cdkTable that has a
  1339. * built-in footer row as *its* content child.
  1340. */
  1341. this._customFooterRowDefs = new Set();
  1342. /**
  1343. * Whether the header row definition has been changed. Triggers an update to the header row after
  1344. * content is checked. Initialized as true so that the table renders the initial set of rows.
  1345. */
  1346. this._headerRowDefChanged = true;
  1347. /**
  1348. * Whether the footer row definition has been changed. Triggers an update to the footer row after
  1349. * content is checked. Initialized as true so that the table renders the initial set of rows.
  1350. */
  1351. this._footerRowDefChanged = true;
  1352. /**
  1353. * Cache of the latest rendered `RenderRow` objects as a map for easy retrieval when constructing
  1354. * a new list of `RenderRow` objects for rendering rows. Since the new list is constructed with
  1355. * the cached `RenderRow` objects when possible, the row identity is preserved when the data
  1356. * and row template matches, which allows the `IterableDiffer` to check rows by reference
  1357. * and understand which rows are added/moved/removed.
  1358. *
  1359. * Implemented as a map of maps where the first key is the `data: T` object and the second is the
  1360. * `CdkRowDef<T>` object. With the two keys, the cache points to a `RenderRow<T>` object that
  1361. * contains an array of created pairs. The array is necessary to handle cases where the data
  1362. * array contains multiple duplicate data objects and each instantiated `RenderRow` must be
  1363. * stored.
  1364. */
  1365. this._cachedRenderRowsMap = new Map();
  1366. /**
  1367. * CSS class added to any row or cell that has sticky positioning applied. May be overriden by
  1368. * table subclasses.
  1369. */
  1370. this.stickyCssClass = 'cdk-table-sticky';
  1371. this._multiTemplateDataRows = false;
  1372. // TODO(andrewseguin): Remove max value as the end index
  1373. // and instead calculate the view on init and scroll.
  1374. /**
  1375. * Stream containing the latest information on what rows are being displayed on screen.
  1376. * Can be used by the data source to as a heuristic of what data should be provided.
  1377. *
  1378. * \@docs-private
  1379. */
  1380. this.viewChange = new BehaviorSubject({ start: 0, end: Number.MAX_VALUE });
  1381. if (!role) {
  1382. this._elementRef.nativeElement.setAttribute('role', 'grid');
  1383. }
  1384. this._document = _document;
  1385. this._isNativeHtmlTable = this._elementRef.nativeElement.nodeName === 'TABLE';
  1386. }
  1387. Object.defineProperty(CdkTable.prototype, "trackBy", {
  1388. /**
  1389. * Tracking function that will be used to check the differences in data changes. Used similarly
  1390. * to `ngFor` `trackBy` function. Optimize row operations by identifying a row based on its data
  1391. * relative to the function to know if a row should be added/removed/moved.
  1392. * Accepts a function that takes two parameters, `index` and `item`.
  1393. */
  1394. get: /**
  1395. * Tracking function that will be used to check the differences in data changes. Used similarly
  1396. * to `ngFor` `trackBy` function. Optimize row operations by identifying a row based on its data
  1397. * relative to the function to know if a row should be added/removed/moved.
  1398. * Accepts a function that takes two parameters, `index` and `item`.
  1399. * @return {?}
  1400. */
  1401. function () {
  1402. return this._trackByFn;
  1403. },
  1404. set: /**
  1405. * @param {?} fn
  1406. * @return {?}
  1407. */
  1408. function (fn) {
  1409. if (isDevMode() && fn != null && typeof fn !== 'function' && (/** @type {?} */ (console)) &&
  1410. (/** @type {?} */ (console.warn))) {
  1411. console.warn("trackBy must be a function, but received " + JSON.stringify(fn) + ".");
  1412. }
  1413. this._trackByFn = fn;
  1414. },
  1415. enumerable: true,
  1416. configurable: true
  1417. });
  1418. Object.defineProperty(CdkTable.prototype, "dataSource", {
  1419. /**
  1420. * The table's source of data, which can be provided in three ways (in order of complexity):
  1421. * - Simple data array (each object represents one table row)
  1422. * - Stream that emits a data array each time the array changes
  1423. * - `DataSource` object that implements the connect/disconnect interface.
  1424. *
  1425. * If a data array is provided, the table must be notified when the array's objects are
  1426. * added, removed, or moved. This can be done by calling the `renderRows()` function which will
  1427. * render the diff since the last table render. If the data array reference is changed, the table
  1428. * will automatically trigger an update to the rows.
  1429. *
  1430. * When providing an Observable stream, the table will trigger an update automatically when the
  1431. * stream emits a new array of data.
  1432. *
  1433. * Finally, when providing a `DataSource` object, the table will use the Observable stream
  1434. * provided by the connect function and trigger updates when that stream emits new data array
  1435. * values. During the table's ngOnDestroy or when the data source is removed from the table, the
  1436. * table will call the DataSource's `disconnect` function (may be useful for cleaning up any
  1437. * subscriptions registered during the connect process).
  1438. */
  1439. get: /**
  1440. * The table's source of data, which can be provided in three ways (in order of complexity):
  1441. * - Simple data array (each object represents one table row)
  1442. * - Stream that emits a data array each time the array changes
  1443. * - `DataSource` object that implements the connect/disconnect interface.
  1444. *
  1445. * If a data array is provided, the table must be notified when the array's objects are
  1446. * added, removed, or moved. This can be done by calling the `renderRows()` function which will
  1447. * render the diff since the last table render. If the data array reference is changed, the table
  1448. * will automatically trigger an update to the rows.
  1449. *
  1450. * When providing an Observable stream, the table will trigger an update automatically when the
  1451. * stream emits a new array of data.
  1452. *
  1453. * Finally, when providing a `DataSource` object, the table will use the Observable stream
  1454. * provided by the connect function and trigger updates when that stream emits new data array
  1455. * values. During the table's ngOnDestroy or when the data source is removed from the table, the
  1456. * table will call the DataSource's `disconnect` function (may be useful for cleaning up any
  1457. * subscriptions registered during the connect process).
  1458. * @return {?}
  1459. */
  1460. function () {
  1461. return this._dataSource;
  1462. },
  1463. set: /**
  1464. * @param {?} dataSource
  1465. * @return {?}
  1466. */
  1467. function (dataSource) {
  1468. if (this._dataSource !== dataSource) {
  1469. this._switchDataSource(dataSource);
  1470. }
  1471. },
  1472. enumerable: true,
  1473. configurable: true
  1474. });
  1475. Object.defineProperty(CdkTable.prototype, "multiTemplateDataRows", {
  1476. /**
  1477. * Whether to allow multiple rows per data object by evaluating which rows evaluate their 'when'
  1478. * predicate to true. If `multiTemplateDataRows` is false, which is the default value, then each
  1479. * dataobject will render the first row that evaluates its when predicate to true, in the order
  1480. * defined in the table, or otherwise the default row which does not have a when predicate.
  1481. */
  1482. get: /**
  1483. * Whether to allow multiple rows per data object by evaluating which rows evaluate their 'when'
  1484. * predicate to true. If `multiTemplateDataRows` is false, which is the default value, then each
  1485. * dataobject will render the first row that evaluates its when predicate to true, in the order
  1486. * defined in the table, or otherwise the default row which does not have a when predicate.
  1487. * @return {?}
  1488. */
  1489. function () {
  1490. return this._multiTemplateDataRows;
  1491. },
  1492. set: /**
  1493. * @param {?} v
  1494. * @return {?}
  1495. */
  1496. function (v) {
  1497. this._multiTemplateDataRows = coerceBooleanProperty(v);
  1498. // In Ivy if this value is set via a static attribute (e.g. <table multiTemplateDataRows>),
  1499. // this setter will be invoked before the row outlet has been defined hence the null check.
  1500. if (this._rowOutlet && this._rowOutlet.viewContainer.length) {
  1501. this._forceRenderDataRows();
  1502. }
  1503. },
  1504. enumerable: true,
  1505. configurable: true
  1506. });
  1507. /**
  1508. * @return {?}
  1509. */
  1510. CdkTable.prototype.ngOnInit = /**
  1511. * @return {?}
  1512. */
  1513. function () {
  1514. var _this = this;
  1515. this._setupStickyStyler();
  1516. if (this._isNativeHtmlTable) {
  1517. this._applyNativeTableSections();
  1518. }
  1519. // Set up the trackBy function so that it uses the `RenderRow` as its identity by default. If
  1520. // the user has provided a custom trackBy, return the result of that function as evaluated
  1521. // with the values of the `RenderRow`'s data and index.
  1522. this._dataDiffer = this._differs.find([]).create((/**
  1523. * @param {?} _i
  1524. * @param {?} dataRow
  1525. * @return {?}
  1526. */
  1527. function (_i, dataRow) {
  1528. return _this.trackBy ? _this.trackBy(dataRow.dataIndex, dataRow.data) : dataRow;
  1529. }));
  1530. };
  1531. /**
  1532. * @return {?}
  1533. */
  1534. CdkTable.prototype.ngAfterContentChecked = /**
  1535. * @return {?}
  1536. */
  1537. function () {
  1538. // Cache the row and column definitions gathered by ContentChildren and programmatic injection.
  1539. this._cacheRowDefs();
  1540. this._cacheColumnDefs();
  1541. // Make sure that the user has at least added header, footer, or data row def.
  1542. if (!this._headerRowDefs.length && !this._footerRowDefs.length && !this._rowDefs.length) {
  1543. throw getTableMissingRowDefsError();
  1544. }
  1545. // Render updates if the list of columns have been changed for the header, row, or footer defs.
  1546. this._renderUpdatedColumns();
  1547. // If the header row definition has been changed, trigger a render to the header row.
  1548. if (this._headerRowDefChanged) {
  1549. this._forceRenderHeaderRows();
  1550. this._headerRowDefChanged = false;
  1551. }
  1552. // If the footer row definition has been changed, trigger a render to the footer row.
  1553. if (this._footerRowDefChanged) {
  1554. this._forceRenderFooterRows();
  1555. this._footerRowDefChanged = false;
  1556. }
  1557. // If there is a data source and row definitions, connect to the data source unless a
  1558. // connection has already been made.
  1559. if (this.dataSource && this._rowDefs.length > 0 && !this._renderChangeSubscription) {
  1560. this._observeRenderChanges();
  1561. }
  1562. this._checkStickyStates();
  1563. };
  1564. /**
  1565. * @return {?}
  1566. */
  1567. CdkTable.prototype.ngOnDestroy = /**
  1568. * @return {?}
  1569. */
  1570. function () {
  1571. this._rowOutlet.viewContainer.clear();
  1572. this._headerRowOutlet.viewContainer.clear();
  1573. this._footerRowOutlet.viewContainer.clear();
  1574. this._cachedRenderRowsMap.clear();
  1575. this._onDestroy.next();
  1576. this._onDestroy.complete();
  1577. if (isDataSource(this.dataSource)) {
  1578. this.dataSource.disconnect(this);
  1579. }
  1580. };
  1581. /**
  1582. * Renders rows based on the table's latest set of data, which was either provided directly as an
  1583. * input or retrieved through an Observable stream (directly or from a DataSource).
  1584. * Checks for differences in the data since the last diff to perform only the necessary
  1585. * changes (add/remove/move rows).
  1586. *
  1587. * If the table's data source is a DataSource or Observable, this will be invoked automatically
  1588. * each time the provided Observable stream emits a new data array. Otherwise if your data is
  1589. * an array, this function will need to be called to render any changes.
  1590. */
  1591. /**
  1592. * Renders rows based on the table's latest set of data, which was either provided directly as an
  1593. * input or retrieved through an Observable stream (directly or from a DataSource).
  1594. * Checks for differences in the data since the last diff to perform only the necessary
  1595. * changes (add/remove/move rows).
  1596. *
  1597. * If the table's data source is a DataSource or Observable, this will be invoked automatically
  1598. * each time the provided Observable stream emits a new data array. Otherwise if your data is
  1599. * an array, this function will need to be called to render any changes.
  1600. * @return {?}
  1601. */
  1602. CdkTable.prototype.renderRows = /**
  1603. * Renders rows based on the table's latest set of data, which was either provided directly as an
  1604. * input or retrieved through an Observable stream (directly or from a DataSource).
  1605. * Checks for differences in the data since the last diff to perform only the necessary
  1606. * changes (add/remove/move rows).
  1607. *
  1608. * If the table's data source is a DataSource or Observable, this will be invoked automatically
  1609. * each time the provided Observable stream emits a new data array. Otherwise if your data is
  1610. * an array, this function will need to be called to render any changes.
  1611. * @return {?}
  1612. */
  1613. function () {
  1614. var _this = this;
  1615. this._renderRows = this._getAllRenderRows();
  1616. /** @type {?} */
  1617. var changes = this._dataDiffer.diff(this._renderRows);
  1618. if (!changes) {
  1619. return;
  1620. }
  1621. /** @type {?} */
  1622. var viewContainer = this._rowOutlet.viewContainer;
  1623. changes.forEachOperation((/**
  1624. * @param {?} record
  1625. * @param {?} prevIndex
  1626. * @param {?} currentIndex
  1627. * @return {?}
  1628. */
  1629. function (record, prevIndex, currentIndex) {
  1630. if (record.previousIndex == null) {
  1631. _this._insertRow(record.item, (/** @type {?} */ (currentIndex)));
  1632. }
  1633. else if (currentIndex == null) {
  1634. viewContainer.remove((/** @type {?} */ (prevIndex)));
  1635. }
  1636. else {
  1637. /** @type {?} */
  1638. var view = (/** @type {?} */ (viewContainer.get((/** @type {?} */ (prevIndex)))));
  1639. viewContainer.move((/** @type {?} */ (view)), currentIndex);
  1640. }
  1641. }));
  1642. // Update the meta context of a row's context data (index, count, first, last, ...)
  1643. this._updateRowIndexContext();
  1644. // Update rows that did not get added/removed/moved but may have had their identity changed,
  1645. // e.g. if trackBy matched data on some property but the actual data reference changed.
  1646. changes.forEachIdentityChange((/**
  1647. * @param {?} record
  1648. * @return {?}
  1649. */
  1650. function (record) {
  1651. /** @type {?} */
  1652. var rowView = (/** @type {?} */ (viewContainer.get((/** @type {?} */ (record.currentIndex)))));
  1653. rowView.context.$implicit = record.item.data;
  1654. }));
  1655. this.updateStickyColumnStyles();
  1656. };
  1657. /**
  1658. * Sets the header row definition to be used. Overrides the header row definition gathered by
  1659. * using `ContentChild`, if one exists. Sets a flag that will re-render the header row after the
  1660. * table's content is checked.
  1661. * @docs-private
  1662. * @deprecated Use `addHeaderRowDef` and `removeHeaderRowDef` instead
  1663. * @breaking-change 8.0.0
  1664. */
  1665. /**
  1666. * Sets the header row definition to be used. Overrides the header row definition gathered by
  1667. * using `ContentChild`, if one exists. Sets a flag that will re-render the header row after the
  1668. * table's content is checked.
  1669. * \@docs-private
  1670. * @deprecated Use `addHeaderRowDef` and `removeHeaderRowDef` instead
  1671. * \@breaking-change 8.0.0
  1672. * @param {?} headerRowDef
  1673. * @return {?}
  1674. */
  1675. CdkTable.prototype.setHeaderRowDef = /**
  1676. * Sets the header row definition to be used. Overrides the header row definition gathered by
  1677. * using `ContentChild`, if one exists. Sets a flag that will re-render the header row after the
  1678. * table's content is checked.
  1679. * \@docs-private
  1680. * @deprecated Use `addHeaderRowDef` and `removeHeaderRowDef` instead
  1681. * \@breaking-change 8.0.0
  1682. * @param {?} headerRowDef
  1683. * @return {?}
  1684. */
  1685. function (headerRowDef) {
  1686. this._customHeaderRowDefs = new Set([headerRowDef]);
  1687. this._headerRowDefChanged = true;
  1688. };
  1689. /**
  1690. * Sets the footer row definition to be used. Overrides the footer row definition gathered by
  1691. * using `ContentChild`, if one exists. Sets a flag that will re-render the footer row after the
  1692. * table's content is checked.
  1693. * @docs-private
  1694. * @deprecated Use `addFooterRowDef` and `removeFooterRowDef` instead
  1695. * @breaking-change 8.0.0
  1696. */
  1697. /**
  1698. * Sets the footer row definition to be used. Overrides the footer row definition gathered by
  1699. * using `ContentChild`, if one exists. Sets a flag that will re-render the footer row after the
  1700. * table's content is checked.
  1701. * \@docs-private
  1702. * @deprecated Use `addFooterRowDef` and `removeFooterRowDef` instead
  1703. * \@breaking-change 8.0.0
  1704. * @param {?} footerRowDef
  1705. * @return {?}
  1706. */
  1707. CdkTable.prototype.setFooterRowDef = /**
  1708. * Sets the footer row definition to be used. Overrides the footer row definition gathered by
  1709. * using `ContentChild`, if one exists. Sets a flag that will re-render the footer row after the
  1710. * table's content is checked.
  1711. * \@docs-private
  1712. * @deprecated Use `addFooterRowDef` and `removeFooterRowDef` instead
  1713. * \@breaking-change 8.0.0
  1714. * @param {?} footerRowDef
  1715. * @return {?}
  1716. */
  1717. function (footerRowDef) {
  1718. this._customFooterRowDefs = new Set([footerRowDef]);
  1719. this._footerRowDefChanged = true;
  1720. };
  1721. /** Adds a column definition that was not included as part of the content children. */
  1722. /**
  1723. * Adds a column definition that was not included as part of the content children.
  1724. * @param {?} columnDef
  1725. * @return {?}
  1726. */
  1727. CdkTable.prototype.addColumnDef = /**
  1728. * Adds a column definition that was not included as part of the content children.
  1729. * @param {?} columnDef
  1730. * @return {?}
  1731. */
  1732. function (columnDef) {
  1733. this._customColumnDefs.add(columnDef);
  1734. };
  1735. /** Removes a column definition that was not included as part of the content children. */
  1736. /**
  1737. * Removes a column definition that was not included as part of the content children.
  1738. * @param {?} columnDef
  1739. * @return {?}
  1740. */
  1741. CdkTable.prototype.removeColumnDef = /**
  1742. * Removes a column definition that was not included as part of the content children.
  1743. * @param {?} columnDef
  1744. * @return {?}
  1745. */
  1746. function (columnDef) {
  1747. this._customColumnDefs.delete(columnDef);
  1748. };
  1749. /** Adds a row definition that was not included as part of the content children. */
  1750. /**
  1751. * Adds a row definition that was not included as part of the content children.
  1752. * @param {?} rowDef
  1753. * @return {?}
  1754. */
  1755. CdkTable.prototype.addRowDef = /**
  1756. * Adds a row definition that was not included as part of the content children.
  1757. * @param {?} rowDef
  1758. * @return {?}
  1759. */
  1760. function (rowDef) {
  1761. this._customRowDefs.add(rowDef);
  1762. };
  1763. /** Removes a row definition that was not included as part of the content children. */
  1764. /**
  1765. * Removes a row definition that was not included as part of the content children.
  1766. * @param {?} rowDef
  1767. * @return {?}
  1768. */
  1769. CdkTable.prototype.removeRowDef = /**
  1770. * Removes a row definition that was not included as part of the content children.
  1771. * @param {?} rowDef
  1772. * @return {?}
  1773. */
  1774. function (rowDef) {
  1775. this._customRowDefs.delete(rowDef);
  1776. };
  1777. /** Adds a header row definition that was not included as part of the content children. */
  1778. /**
  1779. * Adds a header row definition that was not included as part of the content children.
  1780. * @param {?} headerRowDef
  1781. * @return {?}
  1782. */
  1783. CdkTable.prototype.addHeaderRowDef = /**
  1784. * Adds a header row definition that was not included as part of the content children.
  1785. * @param {?} headerRowDef
  1786. * @return {?}
  1787. */
  1788. function (headerRowDef) {
  1789. this._customHeaderRowDefs.add(headerRowDef);
  1790. this._headerRowDefChanged = true;
  1791. };
  1792. /** Removes a header row definition that was not included as part of the content children. */
  1793. /**
  1794. * Removes a header row definition that was not included as part of the content children.
  1795. * @param {?} headerRowDef
  1796. * @return {?}
  1797. */
  1798. CdkTable.prototype.removeHeaderRowDef = /**
  1799. * Removes a header row definition that was not included as part of the content children.
  1800. * @param {?} headerRowDef
  1801. * @return {?}
  1802. */
  1803. function (headerRowDef) {
  1804. this._customHeaderRowDefs.delete(headerRowDef);
  1805. this._headerRowDefChanged = true;
  1806. };
  1807. /** Adds a footer row definition that was not included as part of the content children. */
  1808. /**
  1809. * Adds a footer row definition that was not included as part of the content children.
  1810. * @param {?} footerRowDef
  1811. * @return {?}
  1812. */
  1813. CdkTable.prototype.addFooterRowDef = /**
  1814. * Adds a footer row definition that was not included as part of the content children.
  1815. * @param {?} footerRowDef
  1816. * @return {?}
  1817. */
  1818. function (footerRowDef) {
  1819. this._customFooterRowDefs.add(footerRowDef);
  1820. this._footerRowDefChanged = true;
  1821. };
  1822. /** Removes a footer row definition that was not included as part of the content children. */
  1823. /**
  1824. * Removes a footer row definition that was not included as part of the content children.
  1825. * @param {?} footerRowDef
  1826. * @return {?}
  1827. */
  1828. CdkTable.prototype.removeFooterRowDef = /**
  1829. * Removes a footer row definition that was not included as part of the content children.
  1830. * @param {?} footerRowDef
  1831. * @return {?}
  1832. */
  1833. function (footerRowDef) {
  1834. this._customFooterRowDefs.delete(footerRowDef);
  1835. this._footerRowDefChanged = true;
  1836. };
  1837. /**
  1838. * Updates the header sticky styles. First resets all applied styles with respect to the cells
  1839. * sticking to the top. Then, evaluating which cells need to be stuck to the top. This is
  1840. * automatically called when the header row changes its displayed set of columns, or if its
  1841. * sticky input changes. May be called manually for cases where the cell content changes outside
  1842. * of these events.
  1843. */
  1844. /**
  1845. * Updates the header sticky styles. First resets all applied styles with respect to the cells
  1846. * sticking to the top. Then, evaluating which cells need to be stuck to the top. This is
  1847. * automatically called when the header row changes its displayed set of columns, or if its
  1848. * sticky input changes. May be called manually for cases where the cell content changes outside
  1849. * of these events.
  1850. * @return {?}
  1851. */
  1852. CdkTable.prototype.updateStickyHeaderRowStyles = /**
  1853. * Updates the header sticky styles. First resets all applied styles with respect to the cells
  1854. * sticking to the top. Then, evaluating which cells need to be stuck to the top. This is
  1855. * automatically called when the header row changes its displayed set of columns, or if its
  1856. * sticky input changes. May be called manually for cases where the cell content changes outside
  1857. * of these events.
  1858. * @return {?}
  1859. */
  1860. function () {
  1861. /** @type {?} */
  1862. var headerRows = this._getRenderedRows(this._headerRowOutlet);
  1863. /** @type {?} */
  1864. var tableElement = (/** @type {?} */ (this._elementRef.nativeElement));
  1865. // Hide the thead element if there are no header rows. This is necessary to satisfy
  1866. // overzealous a11y checkers that fail because the `rowgroup` element does not contain
  1867. // required child `row`.
  1868. /** @type {?} */
  1869. var thead = tableElement.querySelector('thead');
  1870. if (thead) {
  1871. thead.style.display = headerRows.length ? '' : 'none';
  1872. }
  1873. /** @type {?} */
  1874. var stickyStates = this._headerRowDefs.map((/**
  1875. * @param {?} def
  1876. * @return {?}
  1877. */
  1878. function (def) { return def.sticky; }));
  1879. this._stickyStyler.clearStickyPositioning(headerRows, ['top']);
  1880. this._stickyStyler.stickRows(headerRows, stickyStates, 'top');
  1881. // Reset the dirty state of the sticky input change since it has been used.
  1882. this._headerRowDefs.forEach((/**
  1883. * @param {?} def
  1884. * @return {?}
  1885. */
  1886. function (def) { return def.resetStickyChanged(); }));
  1887. };
  1888. /**
  1889. * Updates the footer sticky styles. First resets all applied styles with respect to the cells
  1890. * sticking to the bottom. Then, evaluating which cells need to be stuck to the bottom. This is
  1891. * automatically called when the footer row changes its displayed set of columns, or if its
  1892. * sticky input changes. May be called manually for cases where the cell content changes outside
  1893. * of these events.
  1894. */
  1895. /**
  1896. * Updates the footer sticky styles. First resets all applied styles with respect to the cells
  1897. * sticking to the bottom. Then, evaluating which cells need to be stuck to the bottom. This is
  1898. * automatically called when the footer row changes its displayed set of columns, or if its
  1899. * sticky input changes. May be called manually for cases where the cell content changes outside
  1900. * of these events.
  1901. * @return {?}
  1902. */
  1903. CdkTable.prototype.updateStickyFooterRowStyles = /**
  1904. * Updates the footer sticky styles. First resets all applied styles with respect to the cells
  1905. * sticking to the bottom. Then, evaluating which cells need to be stuck to the bottom. This is
  1906. * automatically called when the footer row changes its displayed set of columns, or if its
  1907. * sticky input changes. May be called manually for cases where the cell content changes outside
  1908. * of these events.
  1909. * @return {?}
  1910. */
  1911. function () {
  1912. /** @type {?} */
  1913. var footerRows = this._getRenderedRows(this._footerRowOutlet);
  1914. /** @type {?} */
  1915. var tableElement = (/** @type {?} */ (this._elementRef.nativeElement));
  1916. // Hide the tfoot element if there are no footer rows. This is necessary to satisfy
  1917. // overzealous a11y checkers that fail because the `rowgroup` element does not contain
  1918. // required child `row`.
  1919. /** @type {?} */
  1920. var tfoot = tableElement.querySelector('tfoot');
  1921. if (tfoot) {
  1922. tfoot.style.display = footerRows.length ? '' : 'none';
  1923. }
  1924. /** @type {?} */
  1925. var stickyStates = this._footerRowDefs.map((/**
  1926. * @param {?} def
  1927. * @return {?}
  1928. */
  1929. function (def) { return def.sticky; }));
  1930. this._stickyStyler.clearStickyPositioning(footerRows, ['bottom']);
  1931. this._stickyStyler.stickRows(footerRows, stickyStates, 'bottom');
  1932. this._stickyStyler.updateStickyFooterContainer(this._elementRef.nativeElement, stickyStates);
  1933. // Reset the dirty state of the sticky input change since it has been used.
  1934. this._footerRowDefs.forEach((/**
  1935. * @param {?} def
  1936. * @return {?}
  1937. */
  1938. function (def) { return def.resetStickyChanged(); }));
  1939. };
  1940. /**
  1941. * Updates the column sticky styles. First resets all applied styles with respect to the cells
  1942. * sticking to the left and right. Then sticky styles are added for the left and right according
  1943. * to the column definitions for each cell in each row. This is automatically called when
  1944. * the data source provides a new set of data or when a column definition changes its sticky
  1945. * input. May be called manually for cases where the cell content changes outside of these events.
  1946. */
  1947. /**
  1948. * Updates the column sticky styles. First resets all applied styles with respect to the cells
  1949. * sticking to the left and right. Then sticky styles are added for the left and right according
  1950. * to the column definitions for each cell in each row. This is automatically called when
  1951. * the data source provides a new set of data or when a column definition changes its sticky
  1952. * input. May be called manually for cases where the cell content changes outside of these events.
  1953. * @return {?}
  1954. */
  1955. CdkTable.prototype.updateStickyColumnStyles = /**
  1956. * Updates the column sticky styles. First resets all applied styles with respect to the cells
  1957. * sticking to the left and right. Then sticky styles are added for the left and right according
  1958. * to the column definitions for each cell in each row. This is automatically called when
  1959. * the data source provides a new set of data or when a column definition changes its sticky
  1960. * input. May be called manually for cases where the cell content changes outside of these events.
  1961. * @return {?}
  1962. */
  1963. function () {
  1964. var _this = this;
  1965. /** @type {?} */
  1966. var headerRows = this._getRenderedRows(this._headerRowOutlet);
  1967. /** @type {?} */
  1968. var dataRows = this._getRenderedRows(this._rowOutlet);
  1969. /** @type {?} */
  1970. var footerRows = this._getRenderedRows(this._footerRowOutlet);
  1971. // Clear the left and right positioning from all columns in the table across all rows since
  1972. // sticky columns span across all table sections (header, data, footer)
  1973. this._stickyStyler.clearStickyPositioning(headerRows.concat(dataRows, footerRows), ['left', 'right']);
  1974. // Update the sticky styles for each header row depending on the def's sticky state
  1975. headerRows.forEach((/**
  1976. * @param {?} headerRow
  1977. * @param {?} i
  1978. * @return {?}
  1979. */
  1980. function (headerRow, i) {
  1981. _this._addStickyColumnStyles([headerRow], _this._headerRowDefs[i]);
  1982. }));
  1983. // Update the sticky styles for each data row depending on its def's sticky state
  1984. this._rowDefs.forEach((/**
  1985. * @param {?} rowDef
  1986. * @return {?}
  1987. */
  1988. function (rowDef) {
  1989. // Collect all the rows rendered with this row definition.
  1990. /** @type {?} */
  1991. var rows = [];
  1992. for (var i = 0; i < dataRows.length; i++) {
  1993. if (_this._renderRows[i].rowDef === rowDef) {
  1994. rows.push(dataRows[i]);
  1995. }
  1996. }
  1997. _this._addStickyColumnStyles(rows, rowDef);
  1998. }));
  1999. // Update the sticky styles for each footer row depending on the def's sticky state
  2000. footerRows.forEach((/**
  2001. * @param {?} footerRow
  2002. * @param {?} i
  2003. * @return {?}
  2004. */
  2005. function (footerRow, i) {
  2006. _this._addStickyColumnStyles([footerRow], _this._footerRowDefs[i]);
  2007. }));
  2008. // Reset the dirty state of the sticky input change since it has been used.
  2009. Array.from(this._columnDefsByName.values()).forEach((/**
  2010. * @param {?} def
  2011. * @return {?}
  2012. */
  2013. function (def) { return def.resetStickyChanged(); }));
  2014. };
  2015. /**
  2016. * Get the list of RenderRow objects to render according to the current list of data and defined
  2017. * row definitions. If the previous list already contained a particular pair, it should be reused
  2018. * so that the differ equates their references.
  2019. */
  2020. /**
  2021. * Get the list of RenderRow objects to render according to the current list of data and defined
  2022. * row definitions. If the previous list already contained a particular pair, it should be reused
  2023. * so that the differ equates their references.
  2024. * @private
  2025. * @return {?}
  2026. */
  2027. CdkTable.prototype._getAllRenderRows = /**
  2028. * Get the list of RenderRow objects to render according to the current list of data and defined
  2029. * row definitions. If the previous list already contained a particular pair, it should be reused
  2030. * so that the differ equates their references.
  2031. * @private
  2032. * @return {?}
  2033. */
  2034. function () {
  2035. /** @type {?} */
  2036. var renderRows = [];
  2037. // Store the cache and create a new one. Any re-used RenderRow objects will be moved into the
  2038. // new cache while unused ones can be picked up by garbage collection.
  2039. /** @type {?} */
  2040. var prevCachedRenderRows = this._cachedRenderRowsMap;
  2041. this._cachedRenderRowsMap = new Map();
  2042. // For each data object, get the list of rows that should be rendered, represented by the
  2043. // respective `RenderRow` object which is the pair of `data` and `CdkRowDef`.
  2044. for (var i = 0; i < this._data.length; i++) {
  2045. /** @type {?} */
  2046. var data = this._data[i];
  2047. /** @type {?} */
  2048. var renderRowsForData = this._getRenderRowsForData(data, i, prevCachedRenderRows.get(data));
  2049. if (!this._cachedRenderRowsMap.has(data)) {
  2050. this._cachedRenderRowsMap.set(data, new WeakMap());
  2051. }
  2052. for (var j = 0; j < renderRowsForData.length; j++) {
  2053. /** @type {?} */
  2054. var renderRow = renderRowsForData[j];
  2055. /** @type {?} */
  2056. var cache = (/** @type {?} */ (this._cachedRenderRowsMap.get(renderRow.data)));
  2057. if (cache.has(renderRow.rowDef)) {
  2058. (/** @type {?} */ (cache.get(renderRow.rowDef))).push(renderRow);
  2059. }
  2060. else {
  2061. cache.set(renderRow.rowDef, [renderRow]);
  2062. }
  2063. renderRows.push(renderRow);
  2064. }
  2065. }
  2066. return renderRows;
  2067. };
  2068. /**
  2069. * Gets a list of `RenderRow<T>` for the provided data object and any `CdkRowDef` objects that
  2070. * should be rendered for this data. Reuses the cached RenderRow objects if they match the same
  2071. * `(T, CdkRowDef)` pair.
  2072. */
  2073. /**
  2074. * Gets a list of `RenderRow<T>` for the provided data object and any `CdkRowDef` objects that
  2075. * should be rendered for this data. Reuses the cached RenderRow objects if they match the same
  2076. * `(T, CdkRowDef)` pair.
  2077. * @private
  2078. * @param {?} data
  2079. * @param {?} dataIndex
  2080. * @param {?=} cache
  2081. * @return {?}
  2082. */
  2083. CdkTable.prototype._getRenderRowsForData = /**
  2084. * Gets a list of `RenderRow<T>` for the provided data object and any `CdkRowDef` objects that
  2085. * should be rendered for this data. Reuses the cached RenderRow objects if they match the same
  2086. * `(T, CdkRowDef)` pair.
  2087. * @private
  2088. * @param {?} data
  2089. * @param {?} dataIndex
  2090. * @param {?=} cache
  2091. * @return {?}
  2092. */
  2093. function (data, dataIndex, cache) {
  2094. /** @type {?} */
  2095. var rowDefs = this._getRowDefs(data, dataIndex);
  2096. return rowDefs.map((/**
  2097. * @param {?} rowDef
  2098. * @return {?}
  2099. */
  2100. function (rowDef) {
  2101. /** @type {?} */
  2102. var cachedRenderRows = (cache && cache.has(rowDef)) ? (/** @type {?} */ (cache.get(rowDef))) : [];
  2103. if (cachedRenderRows.length) {
  2104. /** @type {?} */
  2105. var dataRow = (/** @type {?} */ (cachedRenderRows.shift()));
  2106. dataRow.dataIndex = dataIndex;
  2107. return dataRow;
  2108. }
  2109. else {
  2110. return { data: data, rowDef: rowDef, dataIndex: dataIndex };
  2111. }
  2112. }));
  2113. };
  2114. /** Update the map containing the content's column definitions. */
  2115. /**
  2116. * Update the map containing the content's column definitions.
  2117. * @private
  2118. * @return {?}
  2119. */
  2120. CdkTable.prototype._cacheColumnDefs = /**
  2121. * Update the map containing the content's column definitions.
  2122. * @private
  2123. * @return {?}
  2124. */
  2125. function () {
  2126. var _this = this;
  2127. this._columnDefsByName.clear();
  2128. /** @type {?} */
  2129. var columnDefs = mergeQueryListAndSet(this._contentColumnDefs, this._customColumnDefs);
  2130. columnDefs.forEach((/**
  2131. * @param {?} columnDef
  2132. * @return {?}
  2133. */
  2134. function (columnDef) {
  2135. if (_this._columnDefsByName.has(columnDef.name)) {
  2136. throw getTableDuplicateColumnNameError(columnDef.name);
  2137. }
  2138. _this._columnDefsByName.set(columnDef.name, columnDef);
  2139. }));
  2140. };
  2141. /** Update the list of all available row definitions that can be used. */
  2142. /**
  2143. * Update the list of all available row definitions that can be used.
  2144. * @private
  2145. * @return {?}
  2146. */
  2147. CdkTable.prototype._cacheRowDefs = /**
  2148. * Update the list of all available row definitions that can be used.
  2149. * @private
  2150. * @return {?}
  2151. */
  2152. function () {
  2153. this._headerRowDefs =
  2154. mergeQueryListAndSet(this._contentHeaderRowDefs, this._customHeaderRowDefs);
  2155. this._footerRowDefs =
  2156. mergeQueryListAndSet(this._contentFooterRowDefs, this._customFooterRowDefs);
  2157. this._rowDefs = mergeQueryListAndSet(this._contentRowDefs, this._customRowDefs);
  2158. // After all row definitions are determined, find the row definition to be considered default.
  2159. /** @type {?} */
  2160. var defaultRowDefs = this._rowDefs.filter((/**
  2161. * @param {?} def
  2162. * @return {?}
  2163. */
  2164. function (def) { return !def.when; }));
  2165. if (!this.multiTemplateDataRows && defaultRowDefs.length > 1) {
  2166. throw getTableMultipleDefaultRowDefsError();
  2167. }
  2168. this._defaultRowDef = defaultRowDefs[0];
  2169. };
  2170. /**
  2171. * Check if the header, data, or footer rows have changed what columns they want to display or
  2172. * whether the sticky states have changed for the header or footer. If there is a diff, then
  2173. * re-render that section.
  2174. */
  2175. /**
  2176. * Check if the header, data, or footer rows have changed what columns they want to display or
  2177. * whether the sticky states have changed for the header or footer. If there is a diff, then
  2178. * re-render that section.
  2179. * @private
  2180. * @return {?}
  2181. */
  2182. CdkTable.prototype._renderUpdatedColumns = /**
  2183. * Check if the header, data, or footer rows have changed what columns they want to display or
  2184. * whether the sticky states have changed for the header or footer. If there is a diff, then
  2185. * re-render that section.
  2186. * @private
  2187. * @return {?}
  2188. */
  2189. function () {
  2190. /** @type {?} */
  2191. var columnsDiffReducer = (/**
  2192. * @param {?} acc
  2193. * @param {?} def
  2194. * @return {?}
  2195. */
  2196. function (acc, def) { return acc || !!def.getColumnsDiff(); });
  2197. // Force re-render data rows if the list of column definitions have changed.
  2198. if (this._rowDefs.reduce(columnsDiffReducer, false)) {
  2199. this._forceRenderDataRows();
  2200. }
  2201. // Force re-render header/footer rows if the list of column definitions have changed..
  2202. if (this._headerRowDefs.reduce(columnsDiffReducer, false)) {
  2203. this._forceRenderHeaderRows();
  2204. }
  2205. if (this._footerRowDefs.reduce(columnsDiffReducer, false)) {
  2206. this._forceRenderFooterRows();
  2207. }
  2208. };
  2209. /**
  2210. * Switch to the provided data source by resetting the data and unsubscribing from the current
  2211. * render change subscription if one exists. If the data source is null, interpret this by
  2212. * clearing the row outlet. Otherwise start listening for new data.
  2213. */
  2214. /**
  2215. * Switch to the provided data source by resetting the data and unsubscribing from the current
  2216. * render change subscription if one exists. If the data source is null, interpret this by
  2217. * clearing the row outlet. Otherwise start listening for new data.
  2218. * @private
  2219. * @param {?} dataSource
  2220. * @return {?}
  2221. */
  2222. CdkTable.prototype._switchDataSource = /**
  2223. * Switch to the provided data source by resetting the data and unsubscribing from the current
  2224. * render change subscription if one exists. If the data source is null, interpret this by
  2225. * clearing the row outlet. Otherwise start listening for new data.
  2226. * @private
  2227. * @param {?} dataSource
  2228. * @return {?}
  2229. */
  2230. function (dataSource) {
  2231. this._data = [];
  2232. if (isDataSource(this.dataSource)) {
  2233. this.dataSource.disconnect(this);
  2234. }
  2235. // Stop listening for data from the previous data source.
  2236. if (this._renderChangeSubscription) {
  2237. this._renderChangeSubscription.unsubscribe();
  2238. this._renderChangeSubscription = null;
  2239. }
  2240. if (!dataSource) {
  2241. if (this._dataDiffer) {
  2242. this._dataDiffer.diff([]);
  2243. }
  2244. this._rowOutlet.viewContainer.clear();
  2245. }
  2246. this._dataSource = dataSource;
  2247. };
  2248. /** Set up a subscription for the data provided by the data source. */
  2249. /**
  2250. * Set up a subscription for the data provided by the data source.
  2251. * @private
  2252. * @return {?}
  2253. */
  2254. CdkTable.prototype._observeRenderChanges = /**
  2255. * Set up a subscription for the data provided by the data source.
  2256. * @private
  2257. * @return {?}
  2258. */
  2259. function () {
  2260. var _this = this;
  2261. // If no data source has been set, there is nothing to observe for changes.
  2262. if (!this.dataSource) {
  2263. return;
  2264. }
  2265. /** @type {?} */
  2266. var dataStream;
  2267. if (isDataSource(this.dataSource)) {
  2268. dataStream = this.dataSource.connect(this);
  2269. }
  2270. else if (this.dataSource instanceof Observable) {
  2271. dataStream = this.dataSource;
  2272. }
  2273. else if (Array.isArray(this.dataSource)) {
  2274. dataStream = of(this.dataSource);
  2275. }
  2276. if (dataStream === undefined) {
  2277. throw getTableUnknownDataSourceError();
  2278. }
  2279. this._renderChangeSubscription = dataStream.pipe(takeUntil(this._onDestroy)).subscribe((/**
  2280. * @param {?} data
  2281. * @return {?}
  2282. */
  2283. function (data) {
  2284. _this._data = data || [];
  2285. _this.renderRows();
  2286. }));
  2287. };
  2288. /**
  2289. * Clears any existing content in the header row outlet and creates a new embedded view
  2290. * in the outlet using the header row definition.
  2291. */
  2292. /**
  2293. * Clears any existing content in the header row outlet and creates a new embedded view
  2294. * in the outlet using the header row definition.
  2295. * @private
  2296. * @return {?}
  2297. */
  2298. CdkTable.prototype._forceRenderHeaderRows = /**
  2299. * Clears any existing content in the header row outlet and creates a new embedded view
  2300. * in the outlet using the header row definition.
  2301. * @private
  2302. * @return {?}
  2303. */
  2304. function () {
  2305. var _this = this;
  2306. // Clear the header row outlet if any content exists.
  2307. if (this._headerRowOutlet.viewContainer.length > 0) {
  2308. this._headerRowOutlet.viewContainer.clear();
  2309. }
  2310. this._headerRowDefs.forEach((/**
  2311. * @param {?} def
  2312. * @param {?} i
  2313. * @return {?}
  2314. */
  2315. function (def, i) { return _this._renderRow(_this._headerRowOutlet, def, i); }));
  2316. this.updateStickyHeaderRowStyles();
  2317. this.updateStickyColumnStyles();
  2318. };
  2319. /**
  2320. * Clears any existing content in the footer row outlet and creates a new embedded view
  2321. * in the outlet using the footer row definition.
  2322. */
  2323. /**
  2324. * Clears any existing content in the footer row outlet and creates a new embedded view
  2325. * in the outlet using the footer row definition.
  2326. * @private
  2327. * @return {?}
  2328. */
  2329. CdkTable.prototype._forceRenderFooterRows = /**
  2330. * Clears any existing content in the footer row outlet and creates a new embedded view
  2331. * in the outlet using the footer row definition.
  2332. * @private
  2333. * @return {?}
  2334. */
  2335. function () {
  2336. var _this = this;
  2337. // Clear the footer row outlet if any content exists.
  2338. if (this._footerRowOutlet.viewContainer.length > 0) {
  2339. this._footerRowOutlet.viewContainer.clear();
  2340. }
  2341. this._footerRowDefs.forEach((/**
  2342. * @param {?} def
  2343. * @param {?} i
  2344. * @return {?}
  2345. */
  2346. function (def, i) { return _this._renderRow(_this._footerRowOutlet, def, i); }));
  2347. this.updateStickyFooterRowStyles();
  2348. this.updateStickyColumnStyles();
  2349. };
  2350. /** Adds the sticky column styles for the rows according to the columns' stick states. */
  2351. /**
  2352. * Adds the sticky column styles for the rows according to the columns' stick states.
  2353. * @private
  2354. * @param {?} rows
  2355. * @param {?} rowDef
  2356. * @return {?}
  2357. */
  2358. CdkTable.prototype._addStickyColumnStyles = /**
  2359. * Adds the sticky column styles for the rows according to the columns' stick states.
  2360. * @private
  2361. * @param {?} rows
  2362. * @param {?} rowDef
  2363. * @return {?}
  2364. */
  2365. function (rows, rowDef) {
  2366. var _this = this;
  2367. /** @type {?} */
  2368. var columnDefs = Array.from(rowDef.columns || []).map((/**
  2369. * @param {?} columnName
  2370. * @return {?}
  2371. */
  2372. function (columnName) {
  2373. /** @type {?} */
  2374. var columnDef = _this._columnDefsByName.get(columnName);
  2375. if (!columnDef) {
  2376. throw getTableUnknownColumnError(columnName);
  2377. }
  2378. return (/** @type {?} */ (columnDef));
  2379. }));
  2380. /** @type {?} */
  2381. var stickyStartStates = columnDefs.map((/**
  2382. * @param {?} columnDef
  2383. * @return {?}
  2384. */
  2385. function (columnDef) { return columnDef.sticky; }));
  2386. /** @type {?} */
  2387. var stickyEndStates = columnDefs.map((/**
  2388. * @param {?} columnDef
  2389. * @return {?}
  2390. */
  2391. function (columnDef) { return columnDef.stickyEnd; }));
  2392. this._stickyStyler.updateStickyColumns(rows, stickyStartStates, stickyEndStates);
  2393. };
  2394. /** Gets the list of rows that have been rendered in the row outlet. */
  2395. /**
  2396. * Gets the list of rows that have been rendered in the row outlet.
  2397. * @param {?} rowOutlet
  2398. * @return {?}
  2399. */
  2400. CdkTable.prototype._getRenderedRows = /**
  2401. * Gets the list of rows that have been rendered in the row outlet.
  2402. * @param {?} rowOutlet
  2403. * @return {?}
  2404. */
  2405. function (rowOutlet) {
  2406. /** @type {?} */
  2407. var renderedRows = [];
  2408. for (var i = 0; i < rowOutlet.viewContainer.length; i++) {
  2409. /** @type {?} */
  2410. var viewRef = ((/** @type {?} */ ((/** @type {?} */ (rowOutlet.viewContainer.get(i))))));
  2411. renderedRows.push(viewRef.rootNodes[0]);
  2412. }
  2413. return renderedRows;
  2414. };
  2415. /**
  2416. * Get the matching row definitions that should be used for this row data. If there is only
  2417. * one row definition, it is returned. Otherwise, find the row definitions that has a when
  2418. * predicate that returns true with the data. If none return true, return the default row
  2419. * definition.
  2420. */
  2421. /**
  2422. * Get the matching row definitions that should be used for this row data. If there is only
  2423. * one row definition, it is returned. Otherwise, find the row definitions that has a when
  2424. * predicate that returns true with the data. If none return true, return the default row
  2425. * definition.
  2426. * @param {?} data
  2427. * @param {?} dataIndex
  2428. * @return {?}
  2429. */
  2430. CdkTable.prototype._getRowDefs = /**
  2431. * Get the matching row definitions that should be used for this row data. If there is only
  2432. * one row definition, it is returned. Otherwise, find the row definitions that has a when
  2433. * predicate that returns true with the data. If none return true, return the default row
  2434. * definition.
  2435. * @param {?} data
  2436. * @param {?} dataIndex
  2437. * @return {?}
  2438. */
  2439. function (data, dataIndex) {
  2440. if (this._rowDefs.length == 1) {
  2441. return [this._rowDefs[0]];
  2442. }
  2443. /** @type {?} */
  2444. var rowDefs = [];
  2445. if (this.multiTemplateDataRows) {
  2446. rowDefs = this._rowDefs.filter((/**
  2447. * @param {?} def
  2448. * @return {?}
  2449. */
  2450. function (def) { return !def.when || def.when(dataIndex, data); }));
  2451. }
  2452. else {
  2453. /** @type {?} */
  2454. var rowDef = this._rowDefs.find((/**
  2455. * @param {?} def
  2456. * @return {?}
  2457. */
  2458. function (def) { return def.when && def.when(dataIndex, data); })) || this._defaultRowDef;
  2459. if (rowDef) {
  2460. rowDefs.push(rowDef);
  2461. }
  2462. }
  2463. if (!rowDefs.length) {
  2464. throw getTableMissingMatchingRowDefError(data);
  2465. }
  2466. return rowDefs;
  2467. };
  2468. /**
  2469. * Create the embedded view for the data row template and place it in the correct index location
  2470. * within the data row view container.
  2471. */
  2472. /**
  2473. * Create the embedded view for the data row template and place it in the correct index location
  2474. * within the data row view container.
  2475. * @private
  2476. * @param {?} renderRow
  2477. * @param {?} renderIndex
  2478. * @return {?}
  2479. */
  2480. CdkTable.prototype._insertRow = /**
  2481. * Create the embedded view for the data row template and place it in the correct index location
  2482. * within the data row view container.
  2483. * @private
  2484. * @param {?} renderRow
  2485. * @param {?} renderIndex
  2486. * @return {?}
  2487. */
  2488. function (renderRow, renderIndex) {
  2489. /** @type {?} */
  2490. var rowDef = renderRow.rowDef;
  2491. /** @type {?} */
  2492. var context = { $implicit: renderRow.data };
  2493. this._renderRow(this._rowOutlet, rowDef, renderIndex, context);
  2494. };
  2495. /**
  2496. * Creates a new row template in the outlet and fills it with the set of cell templates.
  2497. * Optionally takes a context to provide to the row and cells, as well as an optional index
  2498. * of where to place the new row template in the outlet.
  2499. */
  2500. /**
  2501. * Creates a new row template in the outlet and fills it with the set of cell templates.
  2502. * Optionally takes a context to provide to the row and cells, as well as an optional index
  2503. * of where to place the new row template in the outlet.
  2504. * @private
  2505. * @param {?} outlet
  2506. * @param {?} rowDef
  2507. * @param {?} index
  2508. * @param {?=} context
  2509. * @return {?}
  2510. */
  2511. CdkTable.prototype._renderRow = /**
  2512. * Creates a new row template in the outlet and fills it with the set of cell templates.
  2513. * Optionally takes a context to provide to the row and cells, as well as an optional index
  2514. * of where to place the new row template in the outlet.
  2515. * @private
  2516. * @param {?} outlet
  2517. * @param {?} rowDef
  2518. * @param {?} index
  2519. * @param {?=} context
  2520. * @return {?}
  2521. */
  2522. function (outlet, rowDef, index, context) {
  2523. if (context === void 0) { context = {}; }
  2524. // TODO(andrewseguin): enforce that one outlet was instantiated from createEmbeddedView
  2525. outlet.viewContainer.createEmbeddedView(rowDef.template, context, index);
  2526. for (var _a = 0, _b = this._getCellTemplates(rowDef); _a < _b.length; _a++) {
  2527. var cellTemplate = _b[_a];
  2528. if (CdkCellOutlet.mostRecentCellOutlet) {
  2529. CdkCellOutlet.mostRecentCellOutlet._viewContainer.createEmbeddedView(cellTemplate, context);
  2530. }
  2531. }
  2532. this._changeDetectorRef.markForCheck();
  2533. };
  2534. /**
  2535. * Updates the index-related context for each row to reflect any changes in the index of the rows,
  2536. * e.g. first/last/even/odd.
  2537. */
  2538. /**
  2539. * Updates the index-related context for each row to reflect any changes in the index of the rows,
  2540. * e.g. first/last/even/odd.
  2541. * @private
  2542. * @return {?}
  2543. */
  2544. CdkTable.prototype._updateRowIndexContext = /**
  2545. * Updates the index-related context for each row to reflect any changes in the index of the rows,
  2546. * e.g. first/last/even/odd.
  2547. * @private
  2548. * @return {?}
  2549. */
  2550. function () {
  2551. /** @type {?} */
  2552. var viewContainer = this._rowOutlet.viewContainer;
  2553. for (var renderIndex = 0, count = viewContainer.length; renderIndex < count; renderIndex++) {
  2554. /** @type {?} */
  2555. var viewRef = (/** @type {?} */ (viewContainer.get(renderIndex)));
  2556. /** @type {?} */
  2557. var context = (/** @type {?} */ (viewRef.context));
  2558. context.count = count;
  2559. context.first = renderIndex === 0;
  2560. context.last = renderIndex === count - 1;
  2561. context.even = renderIndex % 2 === 0;
  2562. context.odd = !context.even;
  2563. if (this.multiTemplateDataRows) {
  2564. context.dataIndex = this._renderRows[renderIndex].dataIndex;
  2565. context.renderIndex = renderIndex;
  2566. }
  2567. else {
  2568. context.index = this._renderRows[renderIndex].dataIndex;
  2569. }
  2570. }
  2571. };
  2572. /** Gets the column definitions for the provided row def. */
  2573. /**
  2574. * Gets the column definitions for the provided row def.
  2575. * @private
  2576. * @param {?} rowDef
  2577. * @return {?}
  2578. */
  2579. CdkTable.prototype._getCellTemplates = /**
  2580. * Gets the column definitions for the provided row def.
  2581. * @private
  2582. * @param {?} rowDef
  2583. * @return {?}
  2584. */
  2585. function (rowDef) {
  2586. var _this = this;
  2587. if (!rowDef || !rowDef.columns) {
  2588. return [];
  2589. }
  2590. return Array.from(rowDef.columns, (/**
  2591. * @param {?} columnId
  2592. * @return {?}
  2593. */
  2594. function (columnId) {
  2595. /** @type {?} */
  2596. var column = _this._columnDefsByName.get(columnId);
  2597. if (!column) {
  2598. throw getTableUnknownColumnError(columnId);
  2599. }
  2600. return rowDef.extractCellTemplate(column);
  2601. }));
  2602. };
  2603. /** Adds native table sections (e.g. tbody) and moves the row outlets into them. */
  2604. /**
  2605. * Adds native table sections (e.g. tbody) and moves the row outlets into them.
  2606. * @private
  2607. * @return {?}
  2608. */
  2609. CdkTable.prototype._applyNativeTableSections = /**
  2610. * Adds native table sections (e.g. tbody) and moves the row outlets into them.
  2611. * @private
  2612. * @return {?}
  2613. */
  2614. function () {
  2615. /** @type {?} */
  2616. var documentFragment = this._document.createDocumentFragment();
  2617. /** @type {?} */
  2618. var sections = [
  2619. { tag: 'thead', outlet: this._headerRowOutlet },
  2620. { tag: 'tbody', outlet: this._rowOutlet },
  2621. { tag: 'tfoot', outlet: this._footerRowOutlet },
  2622. ];
  2623. for (var _a = 0, sections_1 = sections; _a < sections_1.length; _a++) {
  2624. var section = sections_1[_a];
  2625. /** @type {?} */
  2626. var element = this._document.createElement(section.tag);
  2627. element.setAttribute('role', 'rowgroup');
  2628. element.appendChild(section.outlet.elementRef.nativeElement);
  2629. documentFragment.appendChild(element);
  2630. }
  2631. // Use a DocumentFragment so we don't hit the DOM on each iteration.
  2632. this._elementRef.nativeElement.appendChild(documentFragment);
  2633. };
  2634. /**
  2635. * Forces a re-render of the data rows. Should be called in cases where there has been an input
  2636. * change that affects the evaluation of which rows should be rendered, e.g. toggling
  2637. * `multiTemplateDataRows` or adding/removing row definitions.
  2638. */
  2639. /**
  2640. * Forces a re-render of the data rows. Should be called in cases where there has been an input
  2641. * change that affects the evaluation of which rows should be rendered, e.g. toggling
  2642. * `multiTemplateDataRows` or adding/removing row definitions.
  2643. * @private
  2644. * @return {?}
  2645. */
  2646. CdkTable.prototype._forceRenderDataRows = /**
  2647. * Forces a re-render of the data rows. Should be called in cases where there has been an input
  2648. * change that affects the evaluation of which rows should be rendered, e.g. toggling
  2649. * `multiTemplateDataRows` or adding/removing row definitions.
  2650. * @private
  2651. * @return {?}
  2652. */
  2653. function () {
  2654. this._dataDiffer.diff([]);
  2655. this._rowOutlet.viewContainer.clear();
  2656. this.renderRows();
  2657. this.updateStickyColumnStyles();
  2658. };
  2659. /**
  2660. * Checks if there has been a change in sticky states since last check and applies the correct
  2661. * sticky styles. Since checking resets the "dirty" state, this should only be performed once
  2662. * during a change detection and after the inputs are settled (after content check).
  2663. */
  2664. /**
  2665. * Checks if there has been a change in sticky states since last check and applies the correct
  2666. * sticky styles. Since checking resets the "dirty" state, this should only be performed once
  2667. * during a change detection and after the inputs are settled (after content check).
  2668. * @private
  2669. * @return {?}
  2670. */
  2671. CdkTable.prototype._checkStickyStates = /**
  2672. * Checks if there has been a change in sticky states since last check and applies the correct
  2673. * sticky styles. Since checking resets the "dirty" state, this should only be performed once
  2674. * during a change detection and after the inputs are settled (after content check).
  2675. * @private
  2676. * @return {?}
  2677. */
  2678. function () {
  2679. /** @type {?} */
  2680. var stickyCheckReducer = (/**
  2681. * @param {?} acc
  2682. * @param {?} d
  2683. * @return {?}
  2684. */
  2685. function (acc, d) {
  2686. return acc || d.hasStickyChanged();
  2687. });
  2688. // Note that the check needs to occur for every definition since it notifies the definition
  2689. // that it can reset its dirty state. Using another operator like `some` may short-circuit
  2690. // remaining definitions and leave them in an unchecked state.
  2691. if (this._headerRowDefs.reduce(stickyCheckReducer, false)) {
  2692. this.updateStickyHeaderRowStyles();
  2693. }
  2694. if (this._footerRowDefs.reduce(stickyCheckReducer, false)) {
  2695. this.updateStickyFooterRowStyles();
  2696. }
  2697. if (Array.from(this._columnDefsByName.values()).reduce(stickyCheckReducer, false)) {
  2698. this.updateStickyColumnStyles();
  2699. }
  2700. };
  2701. /**
  2702. * Creates the sticky styler that will be used for sticky rows and columns. Listens
  2703. * for directionality changes and provides the latest direction to the styler. Re-applies column
  2704. * stickiness when directionality changes.
  2705. */
  2706. /**
  2707. * Creates the sticky styler that will be used for sticky rows and columns. Listens
  2708. * for directionality changes and provides the latest direction to the styler. Re-applies column
  2709. * stickiness when directionality changes.
  2710. * @private
  2711. * @return {?}
  2712. */
  2713. CdkTable.prototype._setupStickyStyler = /**
  2714. * Creates the sticky styler that will be used for sticky rows and columns. Listens
  2715. * for directionality changes and provides the latest direction to the styler. Re-applies column
  2716. * stickiness when directionality changes.
  2717. * @private
  2718. * @return {?}
  2719. */
  2720. function () {
  2721. var _this = this;
  2722. /** @type {?} */
  2723. var direction = this._dir ? this._dir.value : 'ltr';
  2724. this._stickyStyler = new StickyStyler(this._isNativeHtmlTable, this.stickyCssClass, direction, this._platform.isBrowser);
  2725. (this._dir ? this._dir.change : of())
  2726. .pipe(takeUntil(this._onDestroy))
  2727. .subscribe((/**
  2728. * @param {?} value
  2729. * @return {?}
  2730. */
  2731. function (value) {
  2732. _this._stickyStyler.direction = value;
  2733. _this.updateStickyColumnStyles();
  2734. }));
  2735. };
  2736. CdkTable.decorators = [
  2737. { type: Component, args: [{selector: 'cdk-table, table[cdk-table]',
  2738. exportAs: 'cdkTable',
  2739. template: CDK_TABLE_TEMPLATE,
  2740. host: {
  2741. 'class': 'cdk-table',
  2742. },
  2743. encapsulation: ViewEncapsulation.None,
  2744. // The "OnPush" status for the `MatTable` component is effectively a noop, so we are removing it.
  2745. // The view for `MatTable` consists entirely of templates declared in other views. As they are
  2746. // declared elsewhere, they are checked when their declaration points are checked.
  2747. // tslint:disable-next-line:validate-decorators
  2748. changeDetection: ChangeDetectionStrategy.Default,
  2749. },] },
  2750. ];
  2751. /** @nocollapse */
  2752. CdkTable.ctorParameters = function () { return [
  2753. { type: IterableDiffers },
  2754. { type: ChangeDetectorRef },
  2755. { type: ElementRef },
  2756. { type: String, decorators: [{ type: Attribute, args: ['role',] }] },
  2757. { type: Directionality, decorators: [{ type: Optional }] },
  2758. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
  2759. { type: Platform }
  2760. ]; };
  2761. CdkTable.propDecorators = {
  2762. trackBy: [{ type: Input }],
  2763. dataSource: [{ type: Input }],
  2764. multiTemplateDataRows: [{ type: Input }],
  2765. _rowOutlet: [{ type: ViewChild, args: [DataRowOutlet, { static: true },] }],
  2766. _headerRowOutlet: [{ type: ViewChild, args: [HeaderRowOutlet, { static: true },] }],
  2767. _footerRowOutlet: [{ type: ViewChild, args: [FooterRowOutlet, { static: true },] }],
  2768. _contentColumnDefs: [{ type: ContentChildren, args: [CdkColumnDef,] }],
  2769. _contentRowDefs: [{ type: ContentChildren, args: [CdkRowDef,] }],
  2770. _contentHeaderRowDefs: [{ type: ContentChildren, args: [CdkHeaderRowDef,] }],
  2771. _contentFooterRowDefs: [{ type: ContentChildren, args: [CdkFooterRowDef,] }]
  2772. };
  2773. return CdkTable;
  2774. }());
  2775. /**
  2776. * Utility function that gets a merged list of the entries in a QueryList and values of a Set.
  2777. * @template T
  2778. * @param {?} queryList
  2779. * @param {?} set
  2780. * @return {?}
  2781. */
  2782. function mergeQueryListAndSet(queryList, set) {
  2783. return queryList.toArray().concat(Array.from(set));
  2784. }
  2785. /**
  2786. * @fileoverview added by tsickle
  2787. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2788. */
  2789. /**
  2790. * Injection token that can be used to specify the text column options.
  2791. * @type {?}
  2792. */
  2793. var TEXT_COLUMN_OPTIONS = new InjectionToken('text-column-options');
  2794. /**
  2795. * Column that simply shows text content for the header and row cells. Assumes that the table
  2796. * is using the native table implementation (`<table>`).
  2797. *
  2798. * By default, the name of this column will be the header text and data property accessor.
  2799. * The header text can be overridden with the `headerText` input. Cell values can be overridden with
  2800. * the `dataAccessor` input. Change the text justification to the start or end using the `justify`
  2801. * input.
  2802. * @template T
  2803. */
  2804. var CdkTextColumn = /** @class */ (function () {
  2805. function CdkTextColumn(_table, _options) {
  2806. this._table = _table;
  2807. this._options = _options;
  2808. /**
  2809. * Alignment of the cell values.
  2810. */
  2811. this.justify = 'start';
  2812. this._options = _options || {};
  2813. }
  2814. Object.defineProperty(CdkTextColumn.prototype, "name", {
  2815. /** Column name that should be used to reference this column. */
  2816. get: /**
  2817. * Column name that should be used to reference this column.
  2818. * @return {?}
  2819. */
  2820. function () {
  2821. return this._name;
  2822. },
  2823. set: /**
  2824. * @param {?} name
  2825. * @return {?}
  2826. */
  2827. function (name) {
  2828. this._name = name;
  2829. // With Ivy, inputs can be initialized before static query results are
  2830. // available. In that case, we defer the synchronization until "ngOnInit" fires.
  2831. this._syncColumnDefName();
  2832. },
  2833. enumerable: true,
  2834. configurable: true
  2835. });
  2836. /**
  2837. * @return {?}
  2838. */
  2839. CdkTextColumn.prototype.ngOnInit = /**
  2840. * @return {?}
  2841. */
  2842. function () {
  2843. this._syncColumnDefName();
  2844. if (this.headerText === undefined) {
  2845. this.headerText = this._createDefaultHeaderText();
  2846. }
  2847. if (!this.dataAccessor) {
  2848. this.dataAccessor =
  2849. this._options.defaultDataAccessor || ((/**
  2850. * @param {?} data
  2851. * @param {?} name
  2852. * @return {?}
  2853. */
  2854. function (data, name) { return ((/** @type {?} */ (data)))[name]; }));
  2855. }
  2856. if (this._table) {
  2857. // Provide the cell and headerCell directly to the table with the static `ViewChild` query,
  2858. // since the columnDef will not pick up its content by the time the table finishes checking
  2859. // its content and initializing the rows.
  2860. this.columnDef.cell = this.cell;
  2861. this.columnDef.headerCell = this.headerCell;
  2862. this._table.addColumnDef(this.columnDef);
  2863. }
  2864. else {
  2865. throw getTableTextColumnMissingParentTableError();
  2866. }
  2867. };
  2868. /**
  2869. * @return {?}
  2870. */
  2871. CdkTextColumn.prototype.ngOnDestroy = /**
  2872. * @return {?}
  2873. */
  2874. function () {
  2875. if (this._table) {
  2876. this._table.removeColumnDef(this.columnDef);
  2877. }
  2878. };
  2879. /**
  2880. * Creates a default header text. Use the options' header text transformation function if one
  2881. * has been provided. Otherwise simply capitalize the column name.
  2882. */
  2883. /**
  2884. * Creates a default header text. Use the options' header text transformation function if one
  2885. * has been provided. Otherwise simply capitalize the column name.
  2886. * @return {?}
  2887. */
  2888. CdkTextColumn.prototype._createDefaultHeaderText = /**
  2889. * Creates a default header text. Use the options' header text transformation function if one
  2890. * has been provided. Otherwise simply capitalize the column name.
  2891. * @return {?}
  2892. */
  2893. function () {
  2894. /** @type {?} */
  2895. var name = this.name;
  2896. if (isDevMode() && !name) {
  2897. throw getTableTextColumnMissingNameError();
  2898. }
  2899. if (this._options && this._options.defaultHeaderTextTransform) {
  2900. return this._options.defaultHeaderTextTransform(name);
  2901. }
  2902. return name[0].toUpperCase() + name.slice(1);
  2903. };
  2904. /** Synchronizes the column definition name with the text column name. */
  2905. /**
  2906. * Synchronizes the column definition name with the text column name.
  2907. * @private
  2908. * @return {?}
  2909. */
  2910. CdkTextColumn.prototype._syncColumnDefName = /**
  2911. * Synchronizes the column definition name with the text column name.
  2912. * @private
  2913. * @return {?}
  2914. */
  2915. function () {
  2916. if (this.columnDef) {
  2917. this.columnDef.name = this.name;
  2918. }
  2919. };
  2920. CdkTextColumn.decorators = [
  2921. { type: Component, args: [{selector: 'cdk-text-column',
  2922. template: "\n <ng-container cdkColumnDef>\n <th cdk-header-cell *cdkHeaderCellDef [style.text-align]=\"justify\">\n {{headerText}}\n </th>\n <td cdk-cell *cdkCellDef=\"let data\" [style.text-align]=\"justify\">\n {{dataAccessor(data, name)}}\n </td>\n </ng-container>\n ",
  2923. encapsulation: ViewEncapsulation.None,
  2924. // Change detection is intentionally not set to OnPush. This component's template will be provided
  2925. // to the table to be inserted into its view. This is problematic when change detection runs since
  2926. // the bindings in this template will be evaluated _after_ the table's view is evaluated, which
  2927. // mean's the template in the table's view will not have the updated value (and in fact will cause
  2928. // an ExpressionChangedAfterItHasBeenCheckedError).
  2929. // tslint:disable-next-line:validate-decorators
  2930. changeDetection: ChangeDetectionStrategy.Default,
  2931. },] },
  2932. ];
  2933. /** @nocollapse */
  2934. CdkTextColumn.ctorParameters = function () { return [
  2935. { type: CdkTable, decorators: [{ type: Optional }] },
  2936. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [TEXT_COLUMN_OPTIONS,] }] }
  2937. ]; };
  2938. CdkTextColumn.propDecorators = {
  2939. name: [{ type: Input }],
  2940. headerText: [{ type: Input }],
  2941. dataAccessor: [{ type: Input }],
  2942. justify: [{ type: Input }],
  2943. columnDef: [{ type: ViewChild, args: [CdkColumnDef, { static: true },] }],
  2944. cell: [{ type: ViewChild, args: [CdkCellDef, { static: true },] }],
  2945. headerCell: [{ type: ViewChild, args: [CdkHeaderCellDef, { static: true },] }]
  2946. };
  2947. return CdkTextColumn;
  2948. }());
  2949. /**
  2950. * @fileoverview added by tsickle
  2951. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2952. */
  2953. /** @type {?} */
  2954. var EXPORTED_DECLARATIONS = [
  2955. CdkTable,
  2956. CdkRowDef,
  2957. CdkCellDef,
  2958. CdkCellOutlet,
  2959. CdkHeaderCellDef,
  2960. CdkFooterCellDef,
  2961. CdkColumnDef,
  2962. CdkCell,
  2963. CdkRow,
  2964. CdkHeaderCell,
  2965. CdkFooterCell,
  2966. CdkHeaderRow,
  2967. CdkHeaderRowDef,
  2968. CdkFooterRow,
  2969. CdkFooterRowDef,
  2970. DataRowOutlet,
  2971. HeaderRowOutlet,
  2972. FooterRowOutlet,
  2973. CdkTextColumn,
  2974. ];
  2975. var CdkTableModule = /** @class */ (function () {
  2976. function CdkTableModule() {
  2977. }
  2978. CdkTableModule.decorators = [
  2979. { type: NgModule, args: [{
  2980. imports: [CommonModule],
  2981. exports: EXPORTED_DECLARATIONS,
  2982. declarations: EXPORTED_DECLARATIONS
  2983. },] },
  2984. ];
  2985. return CdkTableModule;
  2986. }());
  2987. /**
  2988. * @fileoverview added by tsickle
  2989. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2990. */
  2991. /**
  2992. * @fileoverview added by tsickle
  2993. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2994. */
  2995. export { DataRowOutlet, HeaderRowOutlet, FooterRowOutlet, CDK_TABLE_TEMPLATE, CdkTable, CdkCellDef, CdkHeaderCellDef, CdkFooterCellDef, CdkColumnDef, BaseCdkCell, CdkHeaderCell, CdkFooterCell, CdkCell, CDK_ROW_TEMPLATE, BaseRowDef, CdkHeaderRowDef, CdkFooterRowDef, CdkRowDef, CdkCellOutlet, CdkHeaderRow, CdkFooterRow, CdkRow, CdkTableModule, STICKY_DIRECTIONS, StickyStyler, mixinHasStickyInput, TEXT_COLUMN_OPTIONS, CdkTextColumn };
  2996. //# sourceMappingURL=table.es5.js.map