views:

33

answers:

0

Hi All,

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?

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);

}

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'
    });
});

Thanks in advance, Ancy