UNPKG

3.76 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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
9 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11 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;
12 return c > 3 && r && Object.defineProperty(target, key, r), r;
13};
14var __metadata = (this && this.__metadata) || function (k, v) {
15 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16};
17Object.defineProperty(exports, "__esModule", { value: true });
18var context_1 = require("../context/context");
19var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
20var expressionService_1 = require("../valueService/expressionService");
21var ValueFormatterService = (function () {
22 function ValueFormatterService() {
23 }
24 ValueFormatterService.prototype.formatValue = function (column, rowNode, $scope, value) {
25 var formatter;
26 var colDef = column.getColDef();
27 // if floating, give preference to the floating formatter
28 if (rowNode && rowNode.rowPinned) {
29 formatter = colDef.pinnedRowValueFormatter ? colDef.pinnedRowValueFormatter : colDef.valueFormatter;
30 }
31 else {
32 formatter = colDef.valueFormatter;
33 }
34 var result = null;
35 if (formatter) {
36 var params = {
37 value: value,
38 node: rowNode,
39 data: rowNode ? rowNode.data : null,
40 colDef: column.getColDef(),
41 column: column,
42 api: this.gridOptionsWrapper.getApi(),
43 columnApi: this.gridOptionsWrapper.getColumnApi(),
44 context: this.gridOptionsWrapper.getContext()
45 };
46 // originally we put the angular 1 scope here, but we don't want the scope
47 // in the params interface, as other frameworks will see the interface, and
48 // angular 1 is not cool any more. so we hack the scope in here (we cannot
49 // include it above, as it's not in the interface, so would cause a compile error).
50 // in the future, when we stop supporting angular 1, we can take this out.
51 params.$scope = $scope;
52 result = this.expressionService.evaluate(formatter, params);
53 }
54 else if (colDef.refData) {
55 return colDef.refData[value];
56 }
57 // if we don't do this, then arrays get displayed as 1,2,3, but we want 1, 2, 3 (ie with spaces)
58 if ((result === null || result === undefined) && Array.isArray(value)) {
59 result = value.join(', ');
60 }
61 return result;
62 };
63 __decorate([
64 context_1.Autowired('gridOptionsWrapper'),
65 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
66 ], ValueFormatterService.prototype, "gridOptionsWrapper", void 0);
67 __decorate([
68 context_1.Autowired('expressionService'),
69 __metadata("design:type", expressionService_1.ExpressionService)
70 ], ValueFormatterService.prototype, "expressionService", void 0);
71 ValueFormatterService = __decorate([
72 context_1.Bean('valueFormatterService')
73 ], ValueFormatterService);
74 return ValueFormatterService;
75}());
76exports.ValueFormatterService = ValueFormatterService;