开发者

jqgrid does not display rows

开发者 https://www.devze.com 2023-02-18 11:35 出处:网络
i used this link to build a basic jqgrid: http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx

i used this link to build a basic jqgrid: http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx

this my code:

<script type="text/javascript">
jQuery(document).ready(function () {
    jQuery("#list").jqGrid({
        url: '/Home/GridData/',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['ProductID', 'ProductName'],
        colModel: [
      { name: 'ProductID', index: 'ProductID', width: 40, align: 'left' },
      { name: 'ProductName', index: 'ProductName', width: 40, align: 'left'}],

        pager: jQuery('#pager'),
        rowNum: 10,
        rowList: [5, 10, 20, 50],
        sortname: 'Id',
        sortorder: "desc",
        viewrecords: true,
        imgpath: '/scripts/th开发者_高级运维emes/coffee/images',
        caption: 'My first grid'
    });
}); 

   public ActionResult GridData(string sidx, string sord, int page, int rows)
    {
        List<Product> listProducts = new List<Product>(){new Product(){ProductName = "koekies",ProductID = 1},
        new Product(){ProductName = "snoepjes",ProductID = 2}};
        return Json(listProducts, JsonRequestBehavior.AllowGet);
    }


Did you read the entire post that you linked? His returning json looks a lot different than what you are returning.

public ActionResult GridData(string sidx, string sord, int page, int rows) {
  var jsonData = new {
    total = 1, // we'll implement later 
    page = page,
    records = 3, // implement later 
    rows = new[]{
      new {id = 1, cell = new[] {"1", "-7", "Is this a good question?"}},
      new {id = 2, cell = new[] {"2", "15", "Is this a blatant ripoff?"}},
      new {id = 3, cell = new[] {"3", "23", "Why is the sky blue?"}}
    }
  };
  return Json(jsonData, JsonRequestBehavior.AllowGet);
}

That id field is important, jsgrid likes to know the row number that you are adding.

0

精彩评论

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