text Kendo Grid使用数据服务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Kendo Grid使用数据服务相关的知识,希望对你有一定的参考价值。

var url = getDailyOpnameUrl + "?UserID='" + userID + "'&CentreID='" + centreID + "'";
var dataSource = new kendo.data.DataSource({
    type: "odata",
    transport: {
        read: {
            url: url,
            dataType: "jsonp"
        }
    },
    change: function(e){
      var page = this.page();
      var sort = JSON.stringify(this.sort());
      var filter = JSON.stringify(this.filter());
      var group = JSON.stringify(this.group());

      sessionStorage.setItem("orderStocksPage", page);
      sessionStorage.setItem("orderStocksSort", sort);
      sessionStorage.setItem("orderStocksFilter", filter);
      if (gridGroupable) {
          sessionStorage.setItem("orderStocksGroup", group);
      }
    },
    batch: false,
    pageSize: gridPageSize,
    serverPaging: true,
    serverSorting: true,
    serverFiltering: true,
    sort: { field: "CreatedOn", dir: "desc" },
    schema: {
        model: {
            id: "ID",
            fields: {
                CreatedOn: { type: "date" }, //string, date, boolean, number
                Name: { type: "string" }
            }
        }
    }
});

$("#gridDailyOpname").kendoGrid({
    dataSource: dataSource,
    groupable: gridGroupable,
    pageable: {
        pageSize: gridPageSize,
        pageSizes: gridPageSizes,
        input: gridPageInput,
        refresh: gridRefresh
    },
    sortable: {
        mode: "single",
        allowUnsort: false
    },
    filterable: true,
    scrollable: false,
    columns: [
                { field: "CreatedOn", title: gridTitleCreatedOn, template: '#= formatDate(CreatedOn) #' },
                { field: "Name", title: gridTitleProductName },
                { field: "ID", title: " ", sortable: false, filterable: false, template: '<a href="#=detailStockOpnameUrl#/#=ID#">#=detailText#</a>' }
    ]
});
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Maxi.DataServices {
    public class DailyStocktakeData {
        public Guid ID { get; set; }
        public DateTime CreatedOn { get; set; }
        public string Name { get; set; }
        public string CompletedByUsername { get; set; }
    }
}
<scripts>
   var getOrderStocksUrl = '@Url.Content("~/DataService/GetOrderStocks")?centreID=\'@ViewBag.CentreID\'';
</scripts>

<div class="table-responsive full-height1">
    <div id="gridDailyOpname"></div>
</div>
 [WebGet]
  public IQueryable<DailyStocktakeData> GetDailyStocktakes(string UserID, string CentreID) {
      Guid userID = new Guid(UserID);
      Guid centreID = new Guid(CentreID); 

      var db = new MaxiContext();

      var query1 = from stocktake in db.Stocktakes
                   join dailyStocktakeSetting in db.DailyStocktakeSettings on stocktake.DailyStocktakeSettingID equals dailyStocktakeSetting.ID
                   where stocktake.CreatedByUserID == userID && stocktake.SourceCentreID == centreID
                   select new DailyStocktakeData {
                      ID = stocktake.ID,
                      CreatedOn = stocktake.CreatedOnUTC,
                      Name = dailyStocktakeSetting.Name
                   };

      return query1; 
  }
Sample Url
http://localhost:49423/DataService/NamaMethod?UserID=%277d43a7da-68e6-4ff4-8d5f-a7180147cd8a%27&CentreID=%27ecad2936-9622-4903-9719-a8b200e74ce7%27

Jangan lupa dikasih '' pada parameter

Cek di DataSources.cs

以上是关于text Kendo Grid使用数据服务的主要内容,如果未能解决你的问题,请参考以下文章

范围刷新 + 部分刷新 + Kendo 数据源 + Kendo Grid + WebSync

从下拉列表中选择选项后,Kendo UI Grid 中的下拉菜单显示对象-对象

MVC Kendo Grid 未显示任何数据

Kendo Grid中的服务器端分页?

kendo ui grid 完成服务器端分页和设置总数

如何将 JSON 数据与 Kendo Grid 绑定