2

I keep getting this error in Firebug:
d is undefined [Break On This Error] randId:function(d){return(d?d:b.jgrid....(i,d);if(g)return d;return d.length>

I use JqGrid Version: 4.3.1

My controller method looks like this :

public JsonResult CategoryList(int page)
    {
        List<CategoryDTO> categories = ServiceUtil.AuctionService.ListCategories();
        List<dynamic> json = new List<dynamic>();

        if (categories != null && categories.Count > 0)
        {
            foreach (CategoryDTO cat in categories)
            {
                json.Add(new { Id = cat.Id, Name = cat.Name, Update = cat.LastUpdate, Regex = cat.ValidationXSD });
            }
        }

        var result = new
        {
            total = 1,
            page = page,
            records = categories == null ? 0 : categories.Count,
            rows = (from cat in categories.Take(10)
                    select
                        new { Id = cat.Id, Name = cat.Name, Update = cat.LastUpdate, Regex = cat.ValidationXSD }
                    ).ToArray()
        };

        return Json(result, JsonRequestBehavior.AllowGet);

    }

The view like this :

$(document).ready(function () {
    $("#jqgridListCategory").jqGrid({
        url: '/Admin/ManageCategory/CategoryList',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['Id', 'Name', 'LastUpdate', 'RegularExpression'],
        colModel: [{ name: 'Id', index: 'Id', width: 40, align: 'left' }, { name: 'Name', index: 'Name', width: 400, align: 'left' }, { name: 'LastUpdate', index: 'LastUpdate', width: 40, align: 'left' }, { name: 'RegularExpression', index: 'RegularExpression', width: 40, align: 'left'}],
        pager: jQuery('#pager'),
        rowNum: 10,
        rowList: [5, 10, 20, 50],
        sortname: 'Id',
        sortorder: "desc",
        viewrecords: true,
        caption: 'Categories'
    });
}); 

I cannot figure out what is wrong, any ideas?

Edit 1: Use latest jquery version 1.7.2.

Edit 2: I do not expect Regex from controller to be nothing but a string in View

radu florescu
  • 4,315
  • 10
  • 60
  • 92

1 Answers1

1

The CategoryList action produce the data in the wrong format. Either you have to use jsonReader or change the code of CategoryList action.

The standard format of items from the rows part of the server response should be like the following

{"id" :"1", "cell": ["cell11", "cell12", "cell13"]}

If the first column Id is unique and can be used as the id of the row you can use just array or strings instead:

rows = (from cat in categories.Take(10)
        select new[] {
            cat.Id.ToString(),
            cat.Name,
            cat.LastUpdate.ToString(),
            cat.ValidationXSD
        }).ToArray()

In the jqGrid you should add key: true to the list of the properties of the column 'Id' and add the following jqGrid option

jsonReader: { cell: "" }

I recommend you to play with the demo project from my old answer or with it's modification from another answer.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • 1
    @Floradu88: You are welcome! Is the problem which you described in your question still exist after the changes which I suggest in my answer? – Oleg Dec 26 '11 at 20:45
  • i have to do some changes, to revert some of the changes i did, will accept answer if it works – radu florescu Dec 26 '11 at 20:47
  • 1
    @Floradu88: OK, if you will have any problem you can just write here a comment. – Oleg Dec 26 '11 at 20:53