2016-12-08 39 views
0

我想在我的MVC项目中使用jsGrid,因为客户端想要内联编辑和过滤。 但是,我无法让它将我的JSON源加载到表中。 我的JS加载该表看起来像这样:jsGrid不会呈现JSON数据

$("#jsGrid").jsGrid({ 
      height: "50%", 
      width: "100%", 

      filtering: true, 
      inserting: true, 
      editing: true, 
      sorting: true, 
      paging: true, 
      autoload: true, 

      pageSize: 10, 
      pageButtonCount: 5, 

      deleteConfirm: "Do you really want to delete client?", 

      controller: { 
       loadData: function (filter) { 
        return $.ajax({ 
         type: "GET", 
         url: "RICInstrumentCode/GetData", 
         data: filter, 
         dataType: "json" 
        }); 
       }, 

       insertItem: function (item) { 
        return $.ajax({ 
         type: "CREATE", 
         url: "/api/RICInsrumentCodeTable", 
         data: item, 
         dataType: "json" 
        }); 
       }, 

       updateItem: function (item) { 
        return $.ajax({ 
         type: "UPDATE", 
         url: "/api/RICInsrumentCodeTable/" + item.ID, 
         data: item, 
         dataType: "json" 
        }); 
       }, 

       deleteItem: $.noop 

       //deleteItem: function (item) { 
       // return $.ajax({ 
       //  type: "DELETE", 
       //  url: "/api/data/" + item.ID, 
       //  dataType: "json" 
       // }); 
       //} 
      }, 

      fields: [ 
       { name: "Code", type: "text", title: "RIC Instrument Code", width: 150 }, 
       { name: "Descr", type: "text", title:"RIC Instrument Code Description", width: 200 }, 
       { name: "RICInstrumentGroupId", type: "select", title: "RIC Instrument Group", items: countries, valueField: "Id", textField: "Name" }, 
       { name: "Active", type: "checkbox", title: "Is Active", sorting: true }, 
       { type: "control" } 
      ] 
     }); 

    }); 

的loadData是我一直在工作。

和JSON的是从获取数据返回看起来像这样:

[{"Id":1,"Code":"test1","Descr":"first code test","RICInstrumentGroupId":2,"Active":true},{"Id":2,"Code":"APP","Descr":"Apples and bananas","RICInstrumentGroupId":4,"Active":true},{"Id":3,"Code":"1","Descr":"1","RICInstrumentGroupId":1,"Active":true},{"Id":4,"Code":"3","Descr":"3","RICInstrumentGroupId":3,"Active":false}] 

到目前为止,我已经证实,Ajax是射击,改变了我的阵列标题以匹配的调用,并确保返回是在有效的JSON中,我还能做什么?

我不能为我的生活找出为什么这不起作用。 任何帮助将不胜感激。 先进的感谢, Jaidon Rymer

+0

任何控制台错误? – madalinivascu

+0

一点都没有,这是什么让它很难修复 – jjr2000

+0

是ajax触发? – madalinivascu

回答

1

我太傻了, ,设置表格高度设置为100%,在一个div是没有高度的位,这是导致该表主体渲染高度为0px,将高度属性更改为自动修复它,因为数据一直存在。

感谢您的建议,但!

+0

谢谢!我有确切的问题,疯了! – Francis

0

我不知道是否需要,但是当我看演示示例(OData服务)。 网格loadData函数看起来有点不同于你的。

loadData: function() { 
    var d = $.Deferred(); 

    $.ajax({ 
     url: "http://services.odata.org/V3/(S(3mnweai3qldmghnzfshavfok))/OData/OData.svc/Products", 
     dataType: "json" 
    }).done(function(response) { 
     d.resolve(response.value); 
    }); 

    return d.promise(); 
} 

是接受承诺而不是ajax函数。让自己成为问题

演示在这里:http://js-grid.com/demos/