我有一个jsGrid,它是使用数据库查询的JSON结果构建的。 数据库返回字段Amount1和Amount2(例如)。
我想将这些字段加到字段中以创建一个将在网格中显示的新字段。类似的东西:
fields: [{
name: "Amount1",
type: "text",
title: "bla",
width: 45
},
{
name: "Amount2",
type: "text",
title: "blabla",
width: 60
},
{
name: "Sum",
type: "text"
},
{
itemTemplate: function(Sum) {
return Amount1.value + Amount2.value {
someformatting
};
},
我怎样才能实现这一目标?
答案 0 :(得分:0)
我怎样才能实现这一目标?
itemTemplate
函数内部有两个参数value
和item
。
您可以使用item.Amount1+item.Amount2
<强>样本强>
$("#jsGrid").jsGrid({
width: "100%",
data: [{
Amount1: 10,
Amount2: 12
}, {
Amount1: 156,
Amount2: 125
}, {
Amount1: 101,
Amount2: 122
}],
fields: [{
width: 80,
align:'center',
name: "Amount1",
type: "number"
}, {
width: 80,
align:'center',
name: "Amount2",
type: "number",
}, {
width: 80,
align:'center',
headerTemplate: function() {
return "<th class='jsgrid-header-cell'>Sum</th>";
},
itemTemplate: function(value, item) {
return item.Amount1+item.Amount2;
}
}]
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" />
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>
<div id="jsGrid"></div>