계산 필드
다른 필드값에 의해 자동으로 값이 계산되는 Calculate Field는 DataField.calculateExpression과 calculateCallback로 구현할 수 있습니다.
예제 화면의 PriceTotal컬럼은 calculateExpression으로 Discounted컬럼은 calculateCallback방식으로 구현하였습니다.
pivot, grid, 피벗, 필터, filter
pivot, export
pivot, style, callback, styleCallback
pivot, value, getCellValue
pivot, pivotFields, getPivotFields
(Only JS Support)자동으로 계산될 필드는 calculateExpression를 사용해서 calculateField로 설정할 수 있습니다.
Calculate Field와 연결된 컬럼은 readOnly가 됩니다.
※ 자기 자신 필드를 calculateExpression에 사용할 수 없습니다.
1
2
3
4
5
6
7
8
9
10
11
var fields = [{
fieldName: "Quantity",
dataType: "number"
}, {
fieldName: "UnitPrice",
dataType: "number"
}, {
fieldName: "Price",
dataType: "number",
calculateExpression: "values['Quantity'] * values['UnitPrice']"
}]
계산식으로 표현하기 어려운 경우 calculateCallback함수를 통해 값을 구할 수 있습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var fields = [{
fieldName: "Quantity",
dataType: "number"
}, {
fieldName: "UnitPrice",
dataType: "number"
}, {
fieldName: "Price",
dataType: "number",
calculateCallback: function (dataRow, fieldName, fieldNames, values) {
var quantity = values[fieldNames.indexOf("Quantity")];
var unitprice = values[fieldNames.indexOf("UnitPrice")];
if (isNaN(quantity) || isNaN(unitprice))
return undefined;
else
return quantity >= 1000 ? Math.round(quantity * unitprice * 0.95) : quantity * unitprice;
}
}]