table.es5.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  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 { CDK_TABLE_TEMPLATE, CdkTable, CdkCell, CdkCellDef, CdkColumnDef, CdkFooterCell, CdkFooterCellDef, CdkHeaderCell, CdkHeaderCellDef, CDK_ROW_TEMPLATE, CdkFooterRow, CdkFooterRowDef, CdkHeaderRow, CdkHeaderRowDef, CdkRow, CdkRowDef, CdkTextColumn, CdkTableModule, DataSource } from '@angular/cdk/table';
  10. import { ChangeDetectionStrategy, Component, ViewEncapsulation, Directive, ElementRef, Input, NgModule } from '@angular/core';
  11. import { CommonModule } from '@angular/common';
  12. import { MatCommonModule } from '@angular/material/core';
  13. import { _isNumberValue } from '@angular/cdk/coercion';
  14. import { BehaviorSubject, combineLatest, merge, of, Subscription, Subject } from 'rxjs';
  15. import { map } from 'rxjs/operators';
  16. /**
  17. * @fileoverview added by tsickle
  18. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  19. */
  20. /**
  21. * Wrapper for the CdkTable with Material design styles.
  22. * @template T
  23. */
  24. var MatTable = /** @class */ (function (_super) {
  25. __extends(MatTable, _super);
  26. function MatTable() {
  27. var _this = _super !== null && _super.apply(this, arguments) || this;
  28. /**
  29. * Overrides the sticky CSS class set by the `CdkTable`.
  30. */
  31. _this.stickyCssClass = 'mat-table-sticky';
  32. return _this;
  33. }
  34. MatTable.decorators = [
  35. { type: Component, args: [{selector: 'mat-table, table[mat-table]',
  36. exportAs: 'matTable',
  37. template: CDK_TABLE_TEMPLATE,
  38. styles: ["mat-table{display:block}mat-header-row{min-height:56px}mat-footer-row,mat-row{min-height:48px}mat-footer-row,mat-header-row,mat-row{display:flex;border-width:0;border-bottom-width:1px;border-style:solid;align-items:center;box-sizing:border-box}mat-footer-row::after,mat-header-row::after,mat-row::after{display:inline-block;min-height:inherit;content:''}mat-cell:first-of-type,mat-footer-cell:first-of-type,mat-header-cell:first-of-type{padding-left:24px}[dir=rtl] mat-cell:first-of-type,[dir=rtl] mat-footer-cell:first-of-type,[dir=rtl] mat-header-cell:first-of-type{padding-left:0;padding-right:24px}mat-cell:last-of-type,mat-footer-cell:last-of-type,mat-header-cell:last-of-type{padding-right:24px}[dir=rtl] mat-cell:last-of-type,[dir=rtl] mat-footer-cell:last-of-type,[dir=rtl] mat-header-cell:last-of-type{padding-right:0;padding-left:24px}mat-cell,mat-footer-cell,mat-header-cell{flex:1;display:flex;align-items:center;overflow:hidden;word-wrap:break-word;min-height:inherit}table.mat-table{border-spacing:0}tr.mat-header-row{height:56px}tr.mat-footer-row,tr.mat-row{height:48px}th.mat-header-cell{text-align:left}[dir=rtl] th.mat-header-cell{text-align:right}td.mat-cell,td.mat-footer-cell,th.mat-header-cell{padding:0;border-bottom-width:1px;border-bottom-style:solid}td.mat-cell:first-of-type,td.mat-footer-cell:first-of-type,th.mat-header-cell:first-of-type{padding-left:24px}[dir=rtl] td.mat-cell:first-of-type,[dir=rtl] td.mat-footer-cell:first-of-type,[dir=rtl] th.mat-header-cell:first-of-type{padding-left:0;padding-right:24px}td.mat-cell:last-of-type,td.mat-footer-cell:last-of-type,th.mat-header-cell:last-of-type{padding-right:24px}[dir=rtl] td.mat-cell:last-of-type,[dir=rtl] td.mat-footer-cell:last-of-type,[dir=rtl] th.mat-header-cell:last-of-type{padding-right:0;padding-left:24px}"],
  39. host: {
  40. 'class': 'mat-table',
  41. },
  42. providers: [{ provide: CdkTable, useExisting: MatTable }],
  43. encapsulation: ViewEncapsulation.None,
  44. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  45. // tslint:disable-next-line:validate-decorators
  46. changeDetection: ChangeDetectionStrategy.Default,
  47. },] },
  48. ];
  49. return MatTable;
  50. }(CdkTable));
  51. /**
  52. * @fileoverview added by tsickle
  53. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  54. */
  55. /**
  56. * Cell definition for the mat-table.
  57. * Captures the template of a column's data row cell as well as cell-specific properties.
  58. */
  59. var MatCellDef = /** @class */ (function (_super) {
  60. __extends(MatCellDef, _super);
  61. function MatCellDef() {
  62. return _super !== null && _super.apply(this, arguments) || this;
  63. }
  64. MatCellDef.decorators = [
  65. { type: Directive, args: [{
  66. selector: '[matCellDef]',
  67. providers: [{ provide: CdkCellDef, useExisting: MatCellDef }]
  68. },] },
  69. ];
  70. return MatCellDef;
  71. }(CdkCellDef));
  72. /**
  73. * Header cell definition for the mat-table.
  74. * Captures the template of a column's header cell and as well as cell-specific properties.
  75. */
  76. var MatHeaderCellDef = /** @class */ (function (_super) {
  77. __extends(MatHeaderCellDef, _super);
  78. function MatHeaderCellDef() {
  79. return _super !== null && _super.apply(this, arguments) || this;
  80. }
  81. MatHeaderCellDef.decorators = [
  82. { type: Directive, args: [{
  83. selector: '[matHeaderCellDef]',
  84. providers: [{ provide: CdkHeaderCellDef, useExisting: MatHeaderCellDef }]
  85. },] },
  86. ];
  87. return MatHeaderCellDef;
  88. }(CdkHeaderCellDef));
  89. /**
  90. * Footer cell definition for the mat-table.
  91. * Captures the template of a column's footer cell and as well as cell-specific properties.
  92. */
  93. var MatFooterCellDef = /** @class */ (function (_super) {
  94. __extends(MatFooterCellDef, _super);
  95. function MatFooterCellDef() {
  96. return _super !== null && _super.apply(this, arguments) || this;
  97. }
  98. MatFooterCellDef.decorators = [
  99. { type: Directive, args: [{
  100. selector: '[matFooterCellDef]',
  101. providers: [{ provide: CdkFooterCellDef, useExisting: MatFooterCellDef }]
  102. },] },
  103. ];
  104. return MatFooterCellDef;
  105. }(CdkFooterCellDef));
  106. /**
  107. * Column definition for the mat-table.
  108. * Defines a set of cells available for a table column.
  109. */
  110. var MatColumnDef = /** @class */ (function (_super) {
  111. __extends(MatColumnDef, _super);
  112. function MatColumnDef() {
  113. return _super !== null && _super.apply(this, arguments) || this;
  114. }
  115. MatColumnDef.decorators = [
  116. { type: Directive, args: [{
  117. selector: '[matColumnDef]',
  118. providers: [
  119. { provide: CdkColumnDef, useExisting: MatColumnDef },
  120. { provide: 'MAT_SORT_HEADER_COLUMN_DEF', useExisting: MatColumnDef }
  121. ],
  122. },] },
  123. ];
  124. MatColumnDef.propDecorators = {
  125. name: [{ type: Input, args: ['matColumnDef',] }],
  126. sticky: [{ type: Input }],
  127. stickyEnd: [{ type: Input }]
  128. };
  129. return MatColumnDef;
  130. }(CdkColumnDef));
  131. /**
  132. * Header cell template container that adds the right classes and role.
  133. */
  134. var MatHeaderCell = /** @class */ (function (_super) {
  135. __extends(MatHeaderCell, _super);
  136. function MatHeaderCell(columnDef, elementRef) {
  137. var _this = _super.call(this, columnDef, elementRef) || this;
  138. elementRef.nativeElement.classList.add("mat-column-" + columnDef.cssClassFriendlyName);
  139. return _this;
  140. }
  141. MatHeaderCell.decorators = [
  142. { type: Directive, args: [{
  143. selector: 'mat-header-cell, th[mat-header-cell]',
  144. host: {
  145. 'class': 'mat-header-cell',
  146. 'role': 'columnheader',
  147. },
  148. },] },
  149. ];
  150. /** @nocollapse */
  151. MatHeaderCell.ctorParameters = function () { return [
  152. { type: CdkColumnDef },
  153. { type: ElementRef }
  154. ]; };
  155. return MatHeaderCell;
  156. }(CdkHeaderCell));
  157. /**
  158. * Footer cell template container that adds the right classes and role.
  159. */
  160. var MatFooterCell = /** @class */ (function (_super) {
  161. __extends(MatFooterCell, _super);
  162. function MatFooterCell(columnDef, elementRef) {
  163. var _this = _super.call(this, columnDef, elementRef) || this;
  164. elementRef.nativeElement.classList.add("mat-column-" + columnDef.cssClassFriendlyName);
  165. return _this;
  166. }
  167. MatFooterCell.decorators = [
  168. { type: Directive, args: [{
  169. selector: 'mat-footer-cell, td[mat-footer-cell]',
  170. host: {
  171. 'class': 'mat-footer-cell',
  172. 'role': 'gridcell',
  173. },
  174. },] },
  175. ];
  176. /** @nocollapse */
  177. MatFooterCell.ctorParameters = function () { return [
  178. { type: CdkColumnDef },
  179. { type: ElementRef }
  180. ]; };
  181. return MatFooterCell;
  182. }(CdkFooterCell));
  183. /**
  184. * Cell template container that adds the right classes and role.
  185. */
  186. var MatCell = /** @class */ (function (_super) {
  187. __extends(MatCell, _super);
  188. function MatCell(columnDef, elementRef) {
  189. var _this = _super.call(this, columnDef, elementRef) || this;
  190. elementRef.nativeElement.classList.add("mat-column-" + columnDef.cssClassFriendlyName);
  191. return _this;
  192. }
  193. MatCell.decorators = [
  194. { type: Directive, args: [{
  195. selector: 'mat-cell, td[mat-cell]',
  196. host: {
  197. 'class': 'mat-cell',
  198. 'role': 'gridcell',
  199. },
  200. },] },
  201. ];
  202. /** @nocollapse */
  203. MatCell.ctorParameters = function () { return [
  204. { type: CdkColumnDef },
  205. { type: ElementRef }
  206. ]; };
  207. return MatCell;
  208. }(CdkCell));
  209. /**
  210. * @fileoverview added by tsickle
  211. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  212. */
  213. /**
  214. * Header row definition for the mat-table.
  215. * Captures the header row's template and other header properties such as the columns to display.
  216. */
  217. var MatHeaderRowDef = /** @class */ (function (_super) {
  218. __extends(MatHeaderRowDef, _super);
  219. function MatHeaderRowDef() {
  220. return _super !== null && _super.apply(this, arguments) || this;
  221. }
  222. MatHeaderRowDef.decorators = [
  223. { type: Directive, args: [{
  224. selector: '[matHeaderRowDef]',
  225. providers: [{ provide: CdkHeaderRowDef, useExisting: MatHeaderRowDef }],
  226. inputs: ['columns: matHeaderRowDef', 'sticky: matHeaderRowDefSticky'],
  227. },] },
  228. ];
  229. return MatHeaderRowDef;
  230. }(CdkHeaderRowDef));
  231. /**
  232. * Footer row definition for the mat-table.
  233. * Captures the footer row's template and other footer properties such as the columns to display.
  234. */
  235. var MatFooterRowDef = /** @class */ (function (_super) {
  236. __extends(MatFooterRowDef, _super);
  237. function MatFooterRowDef() {
  238. return _super !== null && _super.apply(this, arguments) || this;
  239. }
  240. MatFooterRowDef.decorators = [
  241. { type: Directive, args: [{
  242. selector: '[matFooterRowDef]',
  243. providers: [{ provide: CdkFooterRowDef, useExisting: MatFooterRowDef }],
  244. inputs: ['columns: matFooterRowDef', 'sticky: matFooterRowDefSticky'],
  245. },] },
  246. ];
  247. return MatFooterRowDef;
  248. }(CdkFooterRowDef));
  249. /**
  250. * Data row definition for the mat-table.
  251. * Captures the data row's template and other properties such as the columns to display and
  252. * a when predicate that describes when this row should be used.
  253. * @template T
  254. */
  255. var MatRowDef = /** @class */ (function (_super) {
  256. __extends(MatRowDef, _super);
  257. function MatRowDef() {
  258. return _super !== null && _super.apply(this, arguments) || this;
  259. }
  260. MatRowDef.decorators = [
  261. { type: Directive, args: [{
  262. selector: '[matRowDef]',
  263. providers: [{ provide: CdkRowDef, useExisting: MatRowDef }],
  264. inputs: ['columns: matRowDefColumns', 'when: matRowDefWhen'],
  265. },] },
  266. ];
  267. return MatRowDef;
  268. }(CdkRowDef));
  269. /**
  270. * Footer template container that contains the cell outlet. Adds the right class and role.
  271. */
  272. var MatHeaderRow = /** @class */ (function (_super) {
  273. __extends(MatHeaderRow, _super);
  274. function MatHeaderRow() {
  275. return _super !== null && _super.apply(this, arguments) || this;
  276. }
  277. MatHeaderRow.decorators = [
  278. { type: Component, args: [{selector: 'mat-header-row, tr[mat-header-row]',
  279. template: CDK_ROW_TEMPLATE,
  280. host: {
  281. 'class': 'mat-header-row',
  282. 'role': 'row',
  283. },
  284. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  285. // tslint:disable-next-line:validate-decorators
  286. changeDetection: ChangeDetectionStrategy.Default,
  287. encapsulation: ViewEncapsulation.None,
  288. exportAs: 'matHeaderRow',
  289. providers: [{ provide: CdkHeaderRow, useExisting: MatHeaderRow }],
  290. },] },
  291. ];
  292. return MatHeaderRow;
  293. }(CdkHeaderRow));
  294. /**
  295. * Footer template container that contains the cell outlet. Adds the right class and role.
  296. */
  297. var MatFooterRow = /** @class */ (function (_super) {
  298. __extends(MatFooterRow, _super);
  299. function MatFooterRow() {
  300. return _super !== null && _super.apply(this, arguments) || this;
  301. }
  302. MatFooterRow.decorators = [
  303. { type: Component, args: [{selector: 'mat-footer-row, tr[mat-footer-row]',
  304. template: CDK_ROW_TEMPLATE,
  305. host: {
  306. 'class': 'mat-footer-row',
  307. 'role': 'row',
  308. },
  309. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  310. // tslint:disable-next-line:validate-decorators
  311. changeDetection: ChangeDetectionStrategy.Default,
  312. encapsulation: ViewEncapsulation.None,
  313. exportAs: 'matFooterRow',
  314. providers: [{ provide: CdkFooterRow, useExisting: MatFooterRow }],
  315. },] },
  316. ];
  317. return MatFooterRow;
  318. }(CdkFooterRow));
  319. /**
  320. * Data row template container that contains the cell outlet. Adds the right class and role.
  321. */
  322. var MatRow = /** @class */ (function (_super) {
  323. __extends(MatRow, _super);
  324. function MatRow() {
  325. return _super !== null && _super.apply(this, arguments) || this;
  326. }
  327. MatRow.decorators = [
  328. { type: Component, args: [{selector: 'mat-row, tr[mat-row]',
  329. template: CDK_ROW_TEMPLATE,
  330. host: {
  331. 'class': 'mat-row',
  332. 'role': 'row',
  333. },
  334. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  335. // tslint:disable-next-line:validate-decorators
  336. changeDetection: ChangeDetectionStrategy.Default,
  337. encapsulation: ViewEncapsulation.None,
  338. exportAs: 'matRow',
  339. providers: [{ provide: CdkRow, useExisting: MatRow }],
  340. },] },
  341. ];
  342. return MatRow;
  343. }(CdkRow));
  344. /**
  345. * @fileoverview added by tsickle
  346. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  347. */
  348. /**
  349. * Column that simply shows text content for the header and row cells. Assumes that the table
  350. * is using the native table implementation (`<table>`).
  351. *
  352. * By default, the name of this column will be the header text and data property accessor.
  353. * The header text can be overridden with the `headerText` input. Cell values can be overridden with
  354. * the `dataAccessor` input. Change the text justification to the start or end using the `justify`
  355. * input.
  356. * @template T
  357. */
  358. var MatTextColumn = /** @class */ (function (_super) {
  359. __extends(MatTextColumn, _super);
  360. function MatTextColumn() {
  361. return _super !== null && _super.apply(this, arguments) || this;
  362. }
  363. MatTextColumn.decorators = [
  364. { type: Component, args: [{selector: 'mat-text-column',
  365. template: "\n <ng-container matColumnDef>\n <th mat-header-cell *matHeaderCellDef [style.text-align]=\"justify\">\n {{headerText}}\n </th>\n <td mat-cell *matCellDef=\"let data\" [style.text-align]=\"justify\">\n {{dataAccessor(data, name)}}\n </td>\n </ng-container>\n ",
  366. encapsulation: ViewEncapsulation.None,
  367. // Change detection is intentionally not set to OnPush. This component's template will be provided
  368. // to the table to be inserted into its view. This is problematic when change detection runs since
  369. // the bindings in this template will be evaluated _after_ the table's view is evaluated, which
  370. // mean's the template in the table's view will not have the updated value (and in fact will cause
  371. // an ExpressionChangedAfterItHasBeenCheckedError).
  372. // tslint:disable-next-line:validate-decorators
  373. changeDetection: ChangeDetectionStrategy.Default,
  374. },] },
  375. ];
  376. return MatTextColumn;
  377. }(CdkTextColumn));
  378. /**
  379. * @fileoverview added by tsickle
  380. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  381. */
  382. /** @type {?} */
  383. var EXPORTED_DECLARATIONS = [
  384. // Table
  385. MatTable,
  386. // Template defs
  387. MatHeaderCellDef,
  388. MatHeaderRowDef,
  389. MatColumnDef,
  390. MatCellDef,
  391. MatRowDef,
  392. MatFooterCellDef,
  393. MatFooterRowDef,
  394. // Cell directives
  395. MatHeaderCell,
  396. MatCell,
  397. MatFooterCell,
  398. // Row directives
  399. MatHeaderRow,
  400. MatRow,
  401. MatFooterRow,
  402. MatTextColumn,
  403. ];
  404. var MatTableModule = /** @class */ (function () {
  405. function MatTableModule() {
  406. }
  407. MatTableModule.decorators = [
  408. { type: NgModule, args: [{
  409. imports: [
  410. CdkTableModule,
  411. CommonModule,
  412. MatCommonModule,
  413. ],
  414. exports: EXPORTED_DECLARATIONS,
  415. declarations: EXPORTED_DECLARATIONS,
  416. },] },
  417. ];
  418. return MatTableModule;
  419. }());
  420. /**
  421. * @fileoverview added by tsickle
  422. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  423. */
  424. /**
  425. * Corresponds to `Number.MAX_SAFE_INTEGER`. Moved out into a variable here due to
  426. * flaky browser support and the value not being defined in Closure's typings.
  427. * @type {?}
  428. */
  429. var MAX_SAFE_INTEGER = 9007199254740991;
  430. /**
  431. * Data source that accepts a client-side data array and includes native support of filtering,
  432. * sorting (using MatSort), and pagination (using MatPaginator).
  433. *
  434. * Allows for sort customization by overriding sortingDataAccessor, which defines how data
  435. * properties are accessed. Also allows for filter customization by overriding filterTermAccessor,
  436. * which defines how row data is converted to a string for filter matching.
  437. * @template T
  438. */
  439. var /**
  440. * Data source that accepts a client-side data array and includes native support of filtering,
  441. * sorting (using MatSort), and pagination (using MatPaginator).
  442. *
  443. * Allows for sort customization by overriding sortingDataAccessor, which defines how data
  444. * properties are accessed. Also allows for filter customization by overriding filterTermAccessor,
  445. * which defines how row data is converted to a string for filter matching.
  446. * @template T
  447. */
  448. MatTableDataSource = /** @class */ (function (_super) {
  449. __extends(MatTableDataSource, _super);
  450. function MatTableDataSource(initialData) {
  451. if (initialData === void 0) { initialData = []; }
  452. var _this = _super.call(this) || this;
  453. /**
  454. * Stream emitting render data to the table (depends on ordered data changes).
  455. */
  456. _this._renderData = new BehaviorSubject([]);
  457. /**
  458. * Stream that emits when a new filter string is set on the data source.
  459. */
  460. _this._filter = new BehaviorSubject('');
  461. /**
  462. * Used to react to internal changes of the paginator that are made by the data source itself.
  463. */
  464. _this._internalPageChanges = new Subject();
  465. /**
  466. * Subscription to the changes that should trigger an update to the table's rendered rows, such
  467. * as filtering, sorting, pagination, or base data changes.
  468. */
  469. _this._renderChangesSubscription = Subscription.EMPTY;
  470. /**
  471. * Data accessor function that is used for accessing data properties for sorting through
  472. * the default sortData function.
  473. * This default function assumes that the sort header IDs (which defaults to the column name)
  474. * matches the data's properties (e.g. column Xyz represents data['Xyz']).
  475. * May be set to a custom function for different behavior.
  476. * @param data Data object that is being accessed.
  477. * @param sortHeaderId The name of the column that represents the data.
  478. */
  479. _this.sortingDataAccessor = (/**
  480. * @param {?} data
  481. * @param {?} sortHeaderId
  482. * @return {?}
  483. */
  484. function (data, sortHeaderId) {
  485. /** @type {?} */
  486. var value = ((/** @type {?} */ (data)))[sortHeaderId];
  487. if (_isNumberValue(value)) {
  488. /** @type {?} */
  489. var numberValue = Number(value);
  490. // Numbers beyond `MAX_SAFE_INTEGER` can't be compared reliably so we
  491. // leave them as strings. For more info: https://goo.gl/y5vbSg
  492. return numberValue < MAX_SAFE_INTEGER ? numberValue : value;
  493. }
  494. return value;
  495. });
  496. /**
  497. * Gets a sorted copy of the data array based on the state of the MatSort. Called
  498. * after changes are made to the filtered data or when sort changes are emitted from MatSort.
  499. * By default, the function retrieves the active sort and its direction and compares data
  500. * by retrieving data using the sortingDataAccessor. May be overridden for a custom implementation
  501. * of data ordering.
  502. * @param data The array of data that should be sorted.
  503. * @param sort The connected MatSort that holds the current sort state.
  504. */
  505. _this.sortData = (/**
  506. * @param {?} data
  507. * @param {?} sort
  508. * @return {?}
  509. */
  510. function (data, sort) {
  511. /** @type {?} */
  512. var active = sort.active;
  513. /** @type {?} */
  514. var direction = sort.direction;
  515. if (!active || direction == '') {
  516. return data;
  517. }
  518. return data.sort((/**
  519. * @param {?} a
  520. * @param {?} b
  521. * @return {?}
  522. */
  523. function (a, b) {
  524. /** @type {?} */
  525. var valueA = _this.sortingDataAccessor(a, active);
  526. /** @type {?} */
  527. var valueB = _this.sortingDataAccessor(b, active);
  528. // If both valueA and valueB exist (truthy), then compare the two. Otherwise, check if
  529. // one value exists while the other doesn't. In this case, existing value should come first.
  530. // This avoids inconsistent results when comparing values to undefined/null.
  531. // If neither value exists, return 0 (equal).
  532. /** @type {?} */
  533. var comparatorResult = 0;
  534. if (valueA != null && valueB != null) {
  535. // Check if one value is greater than the other; if equal, comparatorResult should remain 0.
  536. if (valueA > valueB) {
  537. comparatorResult = 1;
  538. }
  539. else if (valueA < valueB) {
  540. comparatorResult = -1;
  541. }
  542. }
  543. else if (valueA != null) {
  544. comparatorResult = 1;
  545. }
  546. else if (valueB != null) {
  547. comparatorResult = -1;
  548. }
  549. return comparatorResult * (direction == 'asc' ? 1 : -1);
  550. }));
  551. });
  552. /**
  553. * Checks if a data object matches the data source's filter string. By default, each data object
  554. * is converted to a string of its properties and returns true if the filter has
  555. * at least one occurrence in that string. By default, the filter string has its whitespace
  556. * trimmed and the match is case-insensitive. May be overridden for a custom implementation of
  557. * filter matching.
  558. * @param data Data object used to check against the filter.
  559. * @param filter Filter string that has been set on the data source.
  560. * @return Whether the filter matches against the data
  561. */
  562. _this.filterPredicate = (/**
  563. * @param {?} data
  564. * @param {?} filter
  565. * @return {?}
  566. */
  567. function (data, filter) {
  568. // Transform the data into a lowercase string of all property values.
  569. /** @type {?} */
  570. var dataStr = Object.keys(data).reduce((/**
  571. * @param {?} currentTerm
  572. * @param {?} key
  573. * @return {?}
  574. */
  575. function (currentTerm, key) {
  576. // Use an obscure Unicode character to delimit the words in the concatenated string.
  577. // This avoids matches where the values of two columns combined will match the user's query
  578. // (e.g. `Flute` and `Stop` will match `Test`). The character is intended to be something
  579. // that has a very low chance of being typed in by somebody in a text field. This one in
  580. // particular is "White up-pointing triangle with dot" from
  581. // https://en.wikipedia.org/wiki/List_of_Unicode_characters
  582. return currentTerm + ((/** @type {?} */ (data)))[key] + '◬';
  583. }), '').toLowerCase();
  584. // Transform the filter by converting it to lowercase and removing whitespace.
  585. /** @type {?} */
  586. var transformedFilter = filter.trim().toLowerCase();
  587. return dataStr.indexOf(transformedFilter) != -1;
  588. });
  589. _this._data = new BehaviorSubject(initialData);
  590. _this._updateChangeSubscription();
  591. return _this;
  592. }
  593. Object.defineProperty(MatTableDataSource.prototype, "data", {
  594. /** Array of data that should be rendered by the table, where each object represents one row. */
  595. get: /**
  596. * Array of data that should be rendered by the table, where each object represents one row.
  597. * @return {?}
  598. */
  599. function () { return this._data.value; },
  600. set: /**
  601. * @param {?} data
  602. * @return {?}
  603. */
  604. function (data) { this._data.next(data); },
  605. enumerable: true,
  606. configurable: true
  607. });
  608. Object.defineProperty(MatTableDataSource.prototype, "filter", {
  609. /**
  610. * Filter term that should be used to filter out objects from the data array. To override how
  611. * data objects match to this filter string, provide a custom function for filterPredicate.
  612. */
  613. get: /**
  614. * Filter term that should be used to filter out objects from the data array. To override how
  615. * data objects match to this filter string, provide a custom function for filterPredicate.
  616. * @return {?}
  617. */
  618. function () { return this._filter.value; },
  619. set: /**
  620. * @param {?} filter
  621. * @return {?}
  622. */
  623. function (filter) { this._filter.next(filter); },
  624. enumerable: true,
  625. configurable: true
  626. });
  627. Object.defineProperty(MatTableDataSource.prototype, "sort", {
  628. /**
  629. * Instance of the MatSort directive used by the table to control its sorting. Sort changes
  630. * emitted by the MatSort will trigger an update to the table's rendered data.
  631. */
  632. get: /**
  633. * Instance of the MatSort directive used by the table to control its sorting. Sort changes
  634. * emitted by the MatSort will trigger an update to the table's rendered data.
  635. * @return {?}
  636. */
  637. function () { return this._sort; },
  638. set: /**
  639. * @param {?} sort
  640. * @return {?}
  641. */
  642. function (sort) {
  643. this._sort = sort;
  644. this._updateChangeSubscription();
  645. },
  646. enumerable: true,
  647. configurable: true
  648. });
  649. Object.defineProperty(MatTableDataSource.prototype, "paginator", {
  650. /**
  651. * Instance of the MatPaginator component used by the table to control what page of the data is
  652. * displayed. Page changes emitted by the MatPaginator will trigger an update to the
  653. * table's rendered data.
  654. *
  655. * Note that the data source uses the paginator's properties to calculate which page of data
  656. * should be displayed. If the paginator receives its properties as template inputs,
  657. * e.g. `[pageLength]=100` or `[pageIndex]=1`, then be sure that the paginator's view has been
  658. * initialized before assigning it to this data source.
  659. */
  660. get: /**
  661. * Instance of the MatPaginator component used by the table to control what page of the data is
  662. * displayed. Page changes emitted by the MatPaginator will trigger an update to the
  663. * table's rendered data.
  664. *
  665. * Note that the data source uses the paginator's properties to calculate which page of data
  666. * should be displayed. If the paginator receives its properties as template inputs,
  667. * e.g. `[pageLength]=100` or `[pageIndex]=1`, then be sure that the paginator's view has been
  668. * initialized before assigning it to this data source.
  669. * @return {?}
  670. */
  671. function () { return this._paginator; },
  672. set: /**
  673. * @param {?} paginator
  674. * @return {?}
  675. */
  676. function (paginator) {
  677. this._paginator = paginator;
  678. this._updateChangeSubscription();
  679. },
  680. enumerable: true,
  681. configurable: true
  682. });
  683. /**
  684. * Subscribe to changes that should trigger an update to the table's rendered rows. When the
  685. * changes occur, process the current state of the filter, sort, and pagination along with
  686. * the provided base data and send it to the table for rendering.
  687. */
  688. /**
  689. * Subscribe to changes that should trigger an update to the table's rendered rows. When the
  690. * changes occur, process the current state of the filter, sort, and pagination along with
  691. * the provided base data and send it to the table for rendering.
  692. * @return {?}
  693. */
  694. MatTableDataSource.prototype._updateChangeSubscription = /**
  695. * Subscribe to changes that should trigger an update to the table's rendered rows. When the
  696. * changes occur, process the current state of the filter, sort, and pagination along with
  697. * the provided base data and send it to the table for rendering.
  698. * @return {?}
  699. */
  700. function () {
  701. var _this = this;
  702. // Sorting and/or pagination should be watched if MatSort and/or MatPaginator are provided.
  703. // The events should emit whenever the component emits a change or initializes, or if no
  704. // component is provided, a stream with just a null event should be provided.
  705. // The `sortChange` and `pageChange` acts as a signal to the combineLatests below so that the
  706. // pipeline can progress to the next step. Note that the value from these streams are not used,
  707. // they purely act as a signal to progress in the pipeline.
  708. /** @type {?} */
  709. var sortChange = this._sort ?
  710. (/** @type {?} */ (merge(this._sort.sortChange, this._sort.initialized))) :
  711. of(null);
  712. /** @type {?} */
  713. var pageChange = this._paginator ?
  714. (/** @type {?} */ (merge(this._paginator.page, this._internalPageChanges, this._paginator.initialized))) :
  715. of(null);
  716. /** @type {?} */
  717. var dataStream = this._data;
  718. // Watch for base data or filter changes to provide a filtered set of data.
  719. /** @type {?} */
  720. var filteredData = combineLatest(dataStream, this._filter)
  721. .pipe(map((/**
  722. * @param {?} __0
  723. * @return {?}
  724. */
  725. function (_a) {
  726. var data = _a[0];
  727. return _this._filterData(data);
  728. })));
  729. // Watch for filtered data or sort changes to provide an ordered set of data.
  730. /** @type {?} */
  731. var orderedData = combineLatest(filteredData, sortChange)
  732. .pipe(map((/**
  733. * @param {?} __0
  734. * @return {?}
  735. */
  736. function (_a) {
  737. var data = _a[0];
  738. return _this._orderData(data);
  739. })));
  740. // Watch for ordered data or page changes to provide a paged set of data.
  741. /** @type {?} */
  742. var paginatedData = combineLatest(orderedData, pageChange)
  743. .pipe(map((/**
  744. * @param {?} __0
  745. * @return {?}
  746. */
  747. function (_a) {
  748. var data = _a[0];
  749. return _this._pageData(data);
  750. })));
  751. // Watched for paged data changes and send the result to the table to render.
  752. this._renderChangesSubscription.unsubscribe();
  753. this._renderChangesSubscription = paginatedData.subscribe((/**
  754. * @param {?} data
  755. * @return {?}
  756. */
  757. function (data) { return _this._renderData.next(data); }));
  758. };
  759. /**
  760. * Returns a filtered data array where each filter object contains the filter string within
  761. * the result of the filterTermAccessor function. If no filter is set, returns the data array
  762. * as provided.
  763. */
  764. /**
  765. * Returns a filtered data array where each filter object contains the filter string within
  766. * the result of the filterTermAccessor function. If no filter is set, returns the data array
  767. * as provided.
  768. * @param {?} data
  769. * @return {?}
  770. */
  771. MatTableDataSource.prototype._filterData = /**
  772. * Returns a filtered data array where each filter object contains the filter string within
  773. * the result of the filterTermAccessor function. If no filter is set, returns the data array
  774. * as provided.
  775. * @param {?} data
  776. * @return {?}
  777. */
  778. function (data) {
  779. var _this = this;
  780. // If there is a filter string, filter out data that does not contain it.
  781. // Each data object is converted to a string using the function defined by filterTermAccessor.
  782. // May be overridden for customization.
  783. this.filteredData =
  784. !this.filter ? data : data.filter((/**
  785. * @param {?} obj
  786. * @return {?}
  787. */
  788. function (obj) { return _this.filterPredicate(obj, _this.filter); }));
  789. if (this.paginator) {
  790. this._updatePaginator(this.filteredData.length);
  791. }
  792. return this.filteredData;
  793. };
  794. /**
  795. * Returns a sorted copy of the data if MatSort has a sort applied, otherwise just returns the
  796. * data array as provided. Uses the default data accessor for data lookup, unless a
  797. * sortDataAccessor function is defined.
  798. */
  799. /**
  800. * Returns a sorted copy of the data if MatSort has a sort applied, otherwise just returns the
  801. * data array as provided. Uses the default data accessor for data lookup, unless a
  802. * sortDataAccessor function is defined.
  803. * @param {?} data
  804. * @return {?}
  805. */
  806. MatTableDataSource.prototype._orderData = /**
  807. * Returns a sorted copy of the data if MatSort has a sort applied, otherwise just returns the
  808. * data array as provided. Uses the default data accessor for data lookup, unless a
  809. * sortDataAccessor function is defined.
  810. * @param {?} data
  811. * @return {?}
  812. */
  813. function (data) {
  814. // If there is no active sort or direction, return the data without trying to sort.
  815. if (!this.sort) {
  816. return data;
  817. }
  818. return this.sortData(data.slice(), this.sort);
  819. };
  820. /**
  821. * Returns a paged slice of the provided data array according to the provided MatPaginator's page
  822. * index and length. If there is no paginator provided, returns the data array as provided.
  823. */
  824. /**
  825. * Returns a paged slice of the provided data array according to the provided MatPaginator's page
  826. * index and length. If there is no paginator provided, returns the data array as provided.
  827. * @param {?} data
  828. * @return {?}
  829. */
  830. MatTableDataSource.prototype._pageData = /**
  831. * Returns a paged slice of the provided data array according to the provided MatPaginator's page
  832. * index and length. If there is no paginator provided, returns the data array as provided.
  833. * @param {?} data
  834. * @return {?}
  835. */
  836. function (data) {
  837. if (!this.paginator) {
  838. return data;
  839. }
  840. /** @type {?} */
  841. var startIndex = this.paginator.pageIndex * this.paginator.pageSize;
  842. return data.slice(startIndex, startIndex + this.paginator.pageSize);
  843. };
  844. /**
  845. * Updates the paginator to reflect the length of the filtered data, and makes sure that the page
  846. * index does not exceed the paginator's last page. Values are changed in a resolved promise to
  847. * guard against making property changes within a round of change detection.
  848. */
  849. /**
  850. * Updates the paginator to reflect the length of the filtered data, and makes sure that the page
  851. * index does not exceed the paginator's last page. Values are changed in a resolved promise to
  852. * guard against making property changes within a round of change detection.
  853. * @param {?} filteredDataLength
  854. * @return {?}
  855. */
  856. MatTableDataSource.prototype._updatePaginator = /**
  857. * Updates the paginator to reflect the length of the filtered data, and makes sure that the page
  858. * index does not exceed the paginator's last page. Values are changed in a resolved promise to
  859. * guard against making property changes within a round of change detection.
  860. * @param {?} filteredDataLength
  861. * @return {?}
  862. */
  863. function (filteredDataLength) {
  864. var _this = this;
  865. Promise.resolve().then((/**
  866. * @return {?}
  867. */
  868. function () {
  869. /** @type {?} */
  870. var paginator = _this.paginator;
  871. if (!paginator) {
  872. return;
  873. }
  874. paginator.length = filteredDataLength;
  875. // If the page index is set beyond the page, reduce it to the last page.
  876. if (paginator.pageIndex > 0) {
  877. /** @type {?} */
  878. var lastPageIndex = Math.ceil(paginator.length / paginator.pageSize) - 1 || 0;
  879. /** @type {?} */
  880. var newPageIndex = Math.min(paginator.pageIndex, lastPageIndex);
  881. if (newPageIndex !== paginator.pageIndex) {
  882. paginator.pageIndex = newPageIndex;
  883. // Since the paginator only emits after user-generated changes,
  884. // we need our own stream so we know to should re-render the data.
  885. _this._internalPageChanges.next();
  886. }
  887. }
  888. }));
  889. };
  890. /**
  891. * Used by the MatTable. Called when it connects to the data source.
  892. * @docs-private
  893. */
  894. /**
  895. * Used by the MatTable. Called when it connects to the data source.
  896. * \@docs-private
  897. * @return {?}
  898. */
  899. MatTableDataSource.prototype.connect = /**
  900. * Used by the MatTable. Called when it connects to the data source.
  901. * \@docs-private
  902. * @return {?}
  903. */
  904. function () { return this._renderData; };
  905. /**
  906. * Used by the MatTable. Called when it is destroyed. No-op.
  907. * @docs-private
  908. */
  909. /**
  910. * Used by the MatTable. Called when it is destroyed. No-op.
  911. * \@docs-private
  912. * @return {?}
  913. */
  914. MatTableDataSource.prototype.disconnect = /**
  915. * Used by the MatTable. Called when it is destroyed. No-op.
  916. * \@docs-private
  917. * @return {?}
  918. */
  919. function () { };
  920. return MatTableDataSource;
  921. }(DataSource));
  922. /**
  923. * @fileoverview added by tsickle
  924. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  925. */
  926. /**
  927. * @fileoverview added by tsickle
  928. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  929. */
  930. export { MatTableModule, MatCellDef, MatHeaderCellDef, MatFooterCellDef, MatColumnDef, MatHeaderCell, MatFooterCell, MatCell, MatTable, MatHeaderRowDef, MatFooterRowDef, MatRowDef, MatHeaderRow, MatFooterRow, MatRow, MatTableDataSource, MatTextColumn };
  931. //# sourceMappingURL=table.es5.js.map