2016-12-08 40 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/