2017-04-11 144 views
0

我正在準備示例報告屏幕, 用戶將從dropdownBox中選擇報告並填寫一些特殊選項。 點擊搜索按鈕(Sorgula)後,它從ReportController中點擊讀取操作。Telerik網格顯示不存在的列ASP.NET MVC

這個控制器返回列表(不管你嘩嘩)爲JSON

現在這個工作。 但Telerik Grid添加了我從未添加過的不同列。

我沒有定義網格的列。因爲列必須根據JSON發生導致

現在我的網格創建查詢

$("#ReportResult").kendoGrid({ 
     selectable: "multiple cell", 
     allowCopy: true, 
     height: 550, 
     groupable: true, 
     pageable: true, 
     sortable: true, 

     pageable: { 
      input: true, 
      numeric: false 
     }, 

     dataSource: new kendo.data.GanttDataSource({ 
      pageSize: 20, 
      serverPaging: true, 
      serverFiltering: true, 
      serverSorting: true, 
      transport: { 
      read: { 
       url: '<%= Url.Action("Read", "Report") %>', 
       dataType: "json", 
       type: "POST", 
       data: { 
        ReportID: 1, 
        OrganizationID: 2, 
        StartDate: "22", 
        EndDate: "11", 
        UserName:"dds", 
       }, 
      }, 
     }, 

     }), 


    }); 

讀取動作

public ActionResult Read([DataSourceRequest] DataSourceRequest request, int ReportID,int OrganizationID,string StartDate,string EndDate,string UserName) 
    { 

     List<COnsumersReport> lis = new List<COnsumersReport>(); 
     for (int i = 0; i < 99; i++) 
     { 
      COnsumersReport cc = new COnsumersReport(); 
      cc.ID = i; 
      cc.name = "semih"; 
      cc.sirname = "Yıldız"; 
      cc.Borc =i*20.5; 
      lis.Add(cc); 
     } 


     return Json(lis); 
    } 

以及檢測結果。當你看到id,parentId,orderId,Title vs還沒有被我定義。

enter image description here

public class COnsumersReport 
    { 
     public int ID { get; set; } 
     public string name { get; set; } 
     public string sirname { get; set; } 
     public double Borc { get; set; } 
    } 
+0

http://stackoverflow.com/questions/41942205/stop-kendo-from-auto-generating-grid-columns –

+0

謝謝@PierreLebon 但是這不適合我。因爲我不知道哪個列名將來自數據源。 此網格應顯示對象的所有列表 –

+0

COnsumersReport對象是否具有所有這些額外屬性?如果是這樣,那麼當你調用新的COnsumersReport()時,你正在定義它們。使用不同的對象進行綁定,只包含所需的字段。 – Seano666

回答

0

的原因是網格的數據源。我已經習慣了kendo.data.GanttDataSource grand datasource添加自動列。

當我嘗試使用kendo.data.DataSource問題是固定的。

dataSource: new kendo.data.DataSource({ 
     pageSize: 100, 
     serverPaging: true, 
      transport: { 
       read: { 
        url: '<%= Url.Action("Read", "Report") %>', 
        dataType: "json", 
        type: "GET", 
        data: { 
         ReportID: $('#Rapor').val(), 
         OrganizationID: $('#Organizations').val(), 
         StartDate: $('#datepicker').val(), 
         EndDate: $('#datepickerEndDate').val(), 
         UserName: $('#userName').val(), 
        },       
       },      
      }, 
     error: function (req, textStatus, errorThrown) { 
      console.log("Error Verdi" + textStatus + ' ' + errorThrown); 
     }, 
     schema: { 
      total: function (response) { 
      return ResultCount; 
      } 
     } 
     }), 
相關問題