我有一個劍道電網,目前我們創建作爲數據源:我們可以在Kendo Grid中讀取複雜對象嗎?
var gridDataSource = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Action("GetData", "Report")',
dataType: "json"
}
},
group: [
{ field: "Name" },
],
pageSize: 20,
serverPaging: false,
serverFiltering: false,
sort: { field: "Date", dir: "desc" },
schema: {
......
model: {
fields: {
Date: { type: "date" },
Name: { type: "string" },
Version: { type: "string" },
Count: { type: "number" }
}
}
}
});
它調用的GetData報告中獲取數據。返回的數據是具有日期,名稱,版本和計數的類ReportRow的列表。
在後端,這個報告將保存在DocumentDB,該做的GetData是:
public async Task<ContentResult> GetData()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = string.Empty;
try
{
// this json has the time stamp attribute and Rows (array, which is what the grid shows)
json = await _reportRepository.FindDocumentByQueryStringAsync(".....");
if (!string.IsNullOrEmpty(json))
{
// convert the json
....
List<ReportRow> rowList = new List<ReportRow>();
...
{
// parse the json, get results
rowList = reportResults.Rows;
}
...
string ojson = serializer.Serialize(rowList);
return this.Content(ojson, "application/json");
}
}
catch (Exception ex)
{
_log.LogError("...");
}
return this.Content(json, "application/json");
}
當我們表現出的報告,我們要顯示在報表的時間戳記。我的想法是:我們可以在_reportRepository中創建另一個方法來返回報告時間戳,在控制器中調用它並傳遞給視圖。但同事問道:既然我們在GetData中得到了時間戳,是否有一種方法可以使用它,這樣我們就不必更改_reportRepository並再次打電話了?
所以,我的問題是:如果在GetData中,我們直接將json傳遞給Kendo網格,我應該如何在gridDataSource中進行更改?我們如何在模式中定義模型?或者,劍道的模型必須是簡單的類型,即字符串,數字,日期......?如果我們能做到這一點,我應該在閱讀事件中改變什麼?
我搜索了,但找不到答案。
感謝
讓我看看我是否明白你的意思:你想獲得並使用'read'請求中的信息作爲其他目的?如果是的話,我知道你是如何做到的。 – DontVoteMeDown
可否請您詳細說明您的場景或提供一些截圖以瞭解需求? –