JqGrid not displaying data MVC

后端 未结 3 1196
难免孤独
难免孤独 2020-12-12 07:07

please check the jqgrid I am having, it just displays blank grid, my json is according to the expected format of grid. I am using jqGrid 4.4.4



        
相关标签:
3条回答
  • 2020-12-12 07:27

    Did you inspect the result from the server in debugger ? Is there any issue show in the console ?

    If not, may be try to remove "ToArray()" in the jsonData block.

                var jsonData = new
            {
                total = myList .Count,
                page = 1,
                records = 10,
                rows = (
                  from d in myList 
                  select new
                  {
                      id = d.CP,
                      cell = new string[] {
                      d.CP.ToString(),
                      d.Val1.ToString(),
                      d.Val2.ToString(),
                      d.Val3.ToString()
                      }
                  })
            };
    
    0 讨论(0)
  • 2020-12-12 07:44

    What I suggest in my comment is that:

      {
    "total": 1,
    "page": 1,
    "records": 25,
    "rows": [["AUSD    ", "0.000000", "0.72315000", "0.000000"], 
             ["2", "PPFF    ", "0.000000", "1.10288000", "0.000000"],
             ["XTYU    ", "0.000000", "1.41479000", "0.000000"]
    

    ] }

    I alreay get issues with multiple grid regarding JSON result and it solved them.

    0 讨论(0)
  • 2020-12-12 07:51

    JqGrid does not accept any json in rows it needs the json formatted in name values pairs which matches the name field in column model.

    Here JsFiddle Sample

    {
        "total": 1,
        "page": 1,
        "records": 25,
        "rows": [
            {CP: "Val1    ", Val1: "0.000000", Val2:"0.72315000", Val3: "0.000000"},
            {CP: "Val12    ",Val1: "0.000000", Val2: "1.10288000",Val3: "0.000000"},
            .....
    
        ]
    }
    

    To get that json you need to update your action method as follows

     public JsonResult GetData()
            {
                List<Rate> myList = CallProcedure<Rate>("getVal").ToList();
    
    
                var jsonData = new
                {
                    total = myList .Count,
                    page = 1,
                    records = 10,
                    rows = (
                      from d in myList 
                      select new
                      {
                         id = d.CP,
                         CP = d.CP.ToString(),
                         Val1= d.Val1.ToString(),
                         Val2 = d.Val2.ToString(),
                         Val3=  d.Val3.ToString()
                      }).ToArray()
                };
    
    
    
                return Json(jsonData, JsonRequestBehavior.AllowGet);
            }
    
    0 讨论(0)
提交回复
热议问题