开发者

jqgrid sort and paging problem

I am implementing a jqgrid based on online example. The data is coming up but the sort/page is not working I narrowed down the problem which is: parse error because of special characters (in my case '(' ) in the json开发者_如何转开发.responsetext so I tried to include jquerySpecialCharHandler.js in my page but that did not help. I will include my in here my page and my controller action/function.

jQuery(document).ready(function() {
    jQuery("#list").jqGrid({
        url: '/Home/DynamicGridData/',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['Policy', 'Policy Rule','Alert Status','Alert Code',
                   'Message','Category'],
        colModel: [
            { name: 'Policy', index: 'Policy', sortable: true, sorttype: 'text',
              align: 'left', resizable: true },
            { name: 'Policy Rule', index: 'Policy Rule', sortable: true,
              sorttype: 'text', align: 'left', resizable: true },
            { name: 'Alert Status', index: 'AlertStatus', sortable: true,
              align: 'left', resizable: true },
            { name: 'Alert Code', index: 'AlertCode', sortable: true,
              align: 'left', resizable: true },
            { name: 'Message', index: 'Message', sortable: true,
              align: 'left', resizable: true },
            { name: 'Category', index: 'Category', sortable: true,
              align: 'left', resizable: true}],
        pager: $("#pager"),
        rowNum: 10,
        rowList: [5, 10, 20, 50, 100],
        scroll: true,
        sortname: 'Policy',
        sortorder: 'acs',
        autowidth: true,
        viewrecords: true,
        imgpath: '/scripts/themes/coffee/images',
        caption: 'Nebo System Alerts'
    });
}); 

and my function is :

public ActionResult DynamicGridData(string sidx, string sord, int page, int rows){
    var context = new AlertsManagementDataContext();
    int pageIndex = Convert.ToInt32(page) - 1;
    int pageSize = rows;
    int totalRecords = context.Alerts.Count();
    int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
    IQueryable<Alert> alerts = null;
    try
    {
        alerts =  context.Alerts.
                  OrderBy(sidx + " " + sord).
                  Skip(pageIndex * pageSize).
                  Take(pageSize);
    }catch(ParseException ex){
        Response.Write(ex.Position + ex.Message);
    }
    var jsonData = new {
        total = totalPages,
        page = page,
        records = totalRecords,
        rows = (
            from alert in context.Alerts
            select new {
                id = alert.AlertId,
                cell = new string[] {
                    alert.Policy.Name.ToString(),alert.PolicyRule.ToString(),
                    alert.AlertStatus.Status.ToString(), alert.Code.ToString(),
                    alert.Message.ToString(),alert.Category.Name.ToString()
                }
            }).ToArray()
    };
    return Json(jsonData);
}

the exact error message that I recieve during debug is:

A first chance exception of type 'System.Linq.Dynamic.ParseException' occurred in Dynamic.DLL Microsoft JScript compilation error: Expected ')'

and the break is highlighting a jquery.jqgrid.js command which is this :

addJSONData(eval("("+JSON.responseText+")"),ts.grid.bDiv)

needless to say I have gone through several examples but the special characters that I have in my data seems to be the issue and is not being handled, I appreciate any help/advise.


Given System.Linq.Dynamic.ParseException it looks to me like the bug is in the enumeration of alerts in your C# code. Try watching those results -- and, in particular, the results of .ToArray() during debug. I doubt this is a JavaScript issue.


ok I found the problem the context.alerts in the json should be alerts, the alerts is the set of data that is being affected by the sort and paging, I thought to put the answer so if someone else faces the same issue might be helpful for them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜