UNPKG

6.18 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8var __extends = (this && this.__extends) || (function () {
9 var extendStatics = Object.setPrototypeOf ||
10 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
12 return function (d, b) {
13 extendStatics(d, b);
14 function __() { this.constructor = d; }
15 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16 };
17})();
18var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22 return c > 3 && r && Object.defineProperty(target, key, r), r;
23};
24var __metadata = (this && this.__metadata) || function (k, v) {
25 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
26};
27Object.defineProperty(exports, "__esModule", { value: true });
28var utils_1 = require("../../utils");
29var gridOptionsWrapper_1 = require("../../gridOptionsWrapper");
30var context_1 = require("../../context/context");
31var rowNodeBlock_1 = require("../cache/rowNodeBlock");
32var rowRenderer_1 = require("../../rendering/rowRenderer");
33var InfiniteBlock = (function (_super) {
34 __extends(InfiniteBlock, _super);
35 function InfiniteBlock(pageNumber, params) {
36 var _this = _super.call(this, pageNumber, params) || this;
37 _this.cacheParams = params;
38 return _this;
39 }
40 InfiniteBlock.prototype.createBlankRowNode = function (rowIndex) {
41 var rowNode = _super.prototype.createBlankRowNode.call(this, rowIndex);
42 rowNode.uiLevel = 0;
43 this.setIndexAndTopOnRowNode(rowNode, rowIndex);
44 return rowNode;
45 };
46 InfiniteBlock.prototype.setDataAndId = function (rowNode, data, index) {
47 if (utils_1.Utils.exists(data)) {
48 // this means if the user is not providing id's we just use the
49 // index for the row. this will allow selection to work (that is based
50 // on index) as long user is not inserting or deleting rows,
51 // or wanting to keep selection between server side sorting or filtering
52 rowNode.setDataAndId(data, index.toString());
53 }
54 else {
55 rowNode.setDataAndId(undefined, undefined);
56 }
57 };
58 InfiniteBlock.prototype.setRowNode = function (rowIndex, rowNode) {
59 _super.prototype.setRowNode.call(this, rowIndex, rowNode);
60 this.setIndexAndTopOnRowNode(rowNode, rowIndex);
61 };
62 InfiniteBlock.prototype.init = function () {
63 _super.prototype.init.call(this, {
64 context: this.context,
65 rowRenderer: this.rowRenderer
66 });
67 };
68 InfiniteBlock.prototype.getNodeIdPrefix = function () {
69 return null;
70 };
71 InfiniteBlock.prototype.getRow = function (displayIndex) {
72 return this.getRowUsingLocalIndex(displayIndex);
73 };
74 InfiniteBlock.prototype.setIndexAndTopOnRowNode = function (rowNode, rowIndex) {
75 rowNode.setRowIndex(rowIndex);
76 rowNode.rowTop = this.cacheParams.rowHeight * rowIndex;
77 };
78 InfiniteBlock.prototype.loadFromDatasource = function () {
79 var _this = this;
80 // PROBLEM . . . . when the user sets sort via colDef.sort, then this code
81 // is executing before the sort is set up, so server is not getting the sort
82 // model. need to change with regards order - so the server side request is
83 // AFTER thus it gets the right sort model.
84 var params = {
85 startRow: this.getStartRow(),
86 endRow: this.getEndRow(),
87 successCallback: this.pageLoaded.bind(this, this.getVersion()),
88 failCallback: this.pageLoadFailed.bind(this),
89 sortModel: this.cacheParams.sortModel,
90 filterModel: this.cacheParams.filterModel,
91 context: this.gridOptionsWrapper.getContext()
92 };
93 if (utils_1.Utils.missing(this.cacheParams.datasource.getRows)) {
94 console.warn("ag-Grid: datasource is missing getRows method");
95 return;
96 }
97 // check if old version of datasource used
98 var getRowsParams = utils_1.Utils.getFunctionParameters(this.cacheParams.datasource.getRows);
99 if (getRowsParams.length > 1) {
100 console.warn('ag-grid: It looks like your paging datasource is of the old type, taking more than one parameter.');
101 console.warn('ag-grid: From ag-grid 1.9.0, now the getRows takes one parameter. See the documentation for details.');
102 }
103 // put in timeout, to force result to be async
104 setTimeout(function () {
105 _this.cacheParams.datasource.getRows(params);
106 }, 0);
107 };
108 __decorate([
109 context_1.Autowired('gridOptionsWrapper'),
110 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
111 ], InfiniteBlock.prototype, "gridOptionsWrapper", void 0);
112 __decorate([
113 context_1.Autowired('context'),
114 __metadata("design:type", context_1.Context)
115 ], InfiniteBlock.prototype, "context", void 0);
116 __decorate([
117 context_1.Autowired('rowRenderer'),
118 __metadata("design:type", rowRenderer_1.RowRenderer)
119 ], InfiniteBlock.prototype, "rowRenderer", void 0);
120 __decorate([
121 context_1.PostConstruct,
122 __metadata("design:type", Function),
123 __metadata("design:paramtypes", []),
124 __metadata("design:returntype", void 0)
125 ], InfiniteBlock.prototype, "init", null);
126 return InfiniteBlock;
127}(rowNodeBlock_1.RowNodeBlock));
128exports.InfiniteBlock = InfiniteBlock;