【问题标题】:jqxgrid not loading datajqxgrid没有加载数据
【发布时间】:2015-01-05 07:20:30
【问题描述】:

我正在尝试从我的控制器引导数据。查询工作正常,但我似乎无法在视图中加载数据。如果有人能看到我的错误,我将不胜感激。

控制器

  public ActionResult GetItemList(int RRGroupID)
        {

          var item = ReportEngineHelper.GetReportingEngine(Session).Generate<ItemListQuery>(new Filter()
            {
                Item=new Item()
                {
                    RRGroupID = RRGroupID,

                }
            }).ToQueryModel<ItemName>();
          var listItemName = new List<ItemName>();


            return Json(item, JsonRequestBehavior.AllowGet);
        }

查看

 var detailsSource =
                            {
                                    url: $.ajax({url: url,
                                                    type: "json",
                                                    data: {RRGroupID:RRGroupID},
                                                                }),
                                    datatype: "json",
                                datafields: [{ name: "ItemID", type: "int" }, { name: "FullItemName" }],
                            };
                            var detailsAdapter = new $.jqx.dataAdapter(detailsSource);
                            $("#jqxgrid").jqxGrid({
                                source: detailsAdapter,
                                autoheight:true,
                                autowidth: true,
                                columns: [
                           { text: 'Item Name', datafield: 'FullItemName', width: 200, editable: false },
                           { text: 'Unit', width: 100, editable: true },
                           { text: 'Beginning Balance', width: 180, editable: true },
                           { text: 'Loss', width: 80, editable: true, cellsalign: 'right' },
                           { text: 'Quantity Recieved', width: 90, editable: true, cellsalign: 'right'},
                           { text: 'DOS', width: 100, editable: true, cellsalign: 'right' },
                           { text: 'Requested Quantity', width: 100, editable: true, cellsalign: 'right'}
                                ],

                            });

【问题讨论】:

  • 您的 ajax 响应是否包含任何数据?你能在开发者控制台中查看它吗...
  • RRGroupID 似乎已传递给控制器​​。这就是我这样使用它的原因

标签: datagridviewcolumn jqxgrid


【解决方案1】:
   //this is your function build grid
   function buildDetail(data){
      var detailsSource:{
              localdata:data,
              datafields: [{ name: "ItemID", type: "int" }, { name: "FullItemName" }],
              type:'json',
           };
           var detailsAdapter = new $.jqx.dataAdapter(detailsSource);
                        $("#jqxgrid").jqxGrid({
                            source: detailsAdapter,
                            autoheight:true,
                            autowidth: true,
                            columns: [
                       { text: 'Item Name', datafield: 'FullItemName', width: 200, editable: false },
                       { text: 'Unit', width: 100, editable: true },
                       { text: 'Beginning Balance', width: 180, editable: true },
                       { text: 'Loss', width: 80, editable: true, cellsalign: 'right' },
                       { text: 'Quantity Recieved', width: 90, editable: true, cellsalign: 'right'},
                       { text: 'DOS', width: 100, editable: true, cellsalign: 'right' },
                       { text: 'Requested Quantity', width: 100, editable: true, cellsalign: 'right'}
                            ],

                        });
  }


 // now get your data with ajax then build grid.
 $(document).ready(function(){
     $.ajax({url: url,
             type: "json",
             data: {RRGroupID:RRGroupID},
            success:function(data){ 
               //now call your build function
               buildDetail(data);
             }
        });
 })

通过这种方式,您无需使用 jqx.ajax 即可加载数据

【讨论】:

  • 我想我找到了问题.. 认为它可能是这样的: url: $.ajax({url: url, type: "json", data: {RRGroupID:RRGroupID}, }) ,........不知道如何解决它。
  • 是的!因为你不需要 $.ajax 方法。像上面的例子一样编辑它。
  • 但我这样做了..这是迄今为止我可以将参数传递给我的控制器的唯一方法:(
  • :) 好的,我了解您的问题。您可以使用 formatUrl 选项,但现在,您可能无法使用此属性,我现在会重新验证。
  • 我可以在控制台 [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object] 上获取 ajax 的值,.. object0: ObjectFullItemName: "Isoniazid - ( INH) 300mg - 片剂"ItemID: 150
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多