的jqGrid - 如何计算列的jqGrid? [英] jqGrid - How to calculated column to jqgrid?
问题描述
我在ASP MVC 2 application.It工作具有的jqGrid和在网格数据从由控制器返回的JSON对象填充。我的网格有3列UnitNo','区'和'每平方米率。这些列的值从数据库中retrived。现在,我需要的是增加它乘以'区'和'每平方米房价计算出的第4列单价。我怎样才能做到这一点?有什么办法在添加的jqGrid计算列?或者,我可以做计算在我的控制器,并将其添加为行单元格中的新元素?
I am working on an ASP MVC 2 application.It has a jqGrid and data in the grid is populated from the JSON object returned by the controller. My grid has 3 columns 'UnitNo','Area' and 'Rate per sqm'. These column values are retrived from the database. Now what i need is to add a 4th column 'Unit Price' which is calculated by multiplying 'Area' and 'Rate per sqm'. How can i accomplish this? Is there any way to add a calculated column in jqGrid? Or can i do the calculation in my controller and add it as a new element of row cell?
下面是我的控制器code:
Here is my controller code:
public JsonResult GetERVList()
{
var ervRep=new ERVRepository();
IList<ERVMaster> list = ervRep.ListERVData();
int pageSize = 50;
int totalRecords = list.Count();
var totalPages = (int)Math.Ceiling(totalRecords / (float)pageSize);
var jsonData = new
{
total = totalPages,
pageSize,
records = totalRecords,
rows = (from ervdata in list
select new
{
i = ervdata.Id,
cell = new[]
{
ervdata.UnitNo,
ervdata.Area,
ervdata.RatePerSQM
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
和我的jqGrid code是这样
and my jqGrid code is like this
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/ERV/GetERVList/',
datatype: 'json',
mtype: 'GET',
colNames: ['Unit', 'Area', 'Rate per SQM'],
colModel: [ { name: 'UnitNo', index: 'UnitNo' },
{ name: 'Area', index: 'Area' },
{ name: 'RatePerSQM', index: 'RatePerSQM' }],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "Id",
viewrecords: true,
caption: 'My first grid'
});
});
在此先感谢,
Ancy
Thanks in advance, Ancy
推荐答案
我知道,我迟到了,但是这将帮助任何人谁是寻找如何计算派生列
I know , I am late but this will help anybody who is looking for how to calculate derived column
随着应该的jqGrid V4.0工作
Following should work in jQgrid v4.0
改变colNames和colModel配置按以下
change the colNames and colModel config as per following
colNames: ['Unit', 'Area', 'Rate per SQM', 'Unit Price'],
colModel: [ { name: 'UnitNo', index: 'UnitNo' },
{ name: 'Area', index: 'Area' },
{ name: 'RatePerSQM', index: 'RatePerSQM' },
{ name: 'RatePerSQM', index: 'RatePerSQM',
formatter: function (cellvalue, options, rowObject)
{
return rowObject["Area"] * cellvalue
}
}],
这篇关于的jqGrid - 如何计算列的jqGrid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!