剑道UI格不填充后调用读 [英] Kendo UI Grid not populating after call to read

查看:147
本文介绍了剑道UI格不填充后调用读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定我有另外一个,我敢肯定,我失去了一些东西简单了。填充剑道电网与json的结果集。负载是通过从剑道DropDownList控件选择触发。我可以看到的数据是从我的WebAPI返回并转换成JSON结果。但数据不显示在网格中。

什么我失踪做错了吗?

下面是电网如何看待加入:

 < D​​IV ID =messageGridArea>
    @ Html.Partial(消息)
< / DIV>
 

下面是DropDownList的定义:

  @(Html.Kendo()。DropDownList的()
    。名称(importDates)
    .CascadeFrom(客户)
    .OptionLabel(选择导入日期...)
    .DataSource(来源=> {
        source.Read(读=>
        {
            read.Action(GetDistinctImportDates,家)的数据(filterImportDates)。
        })
        .ServerFiltering(真正的);
     })
     .AutoBind(假)
     .Enable(假)
     .Events(E => e.Change(OnImportDatesChanged))
)
 

下面是过滤器电网参数:

 函数filterGridMessages(){
    返回{importdate:$(#importDates)VAL()};
}
 

下面是事件来填充网格:

 函数OnImportDatesChanged(五){
    VAR电网= $(#clientMessages)的数据(kendoGrid)。
    grid.dataSource.read();
}
 

下面是网格的定义:

  @(Html.Kendo()电网< Pulse.Data.Model.ImportHeader>()
    。名称(clientMessages)
    .AutoBind(假)
    .Filterable()
    .Groupable()
    .Sortable()
    .Pageable()
    .Scrollable()
    .DataSource(数据源=>数据源
        阿贾克斯()
        。型号(型号=> model.Id(P => p.ImportId))
        .ServerOperation(假)
        .Read(读=>
            read.Action(GetImportMessages,家庭)。数据(filterGridMessages)
         )
    )
    .Columns(列=>
    {
        columns.Bound(ImportStatus)标题(I)宽度(3%)。;
        columns.Bound(ImportTime)标题(进口时间)。
        columns.Bound(RECORDSTATUS)标题(状态)过滤的(真).Sortable(真).WIDTH(7%)。;
        columns.Bound(RecordState)标题(国家)过滤的(真).Sortable(真).WIDTH(7%)。;
        columns.Bound(RecordAction)标题(行动)过滤的(真).Sortable(真).WIDTH(7%)。;
    })
)
 

和终于在这里是控制器code读取数据:

 公共JsonResult GetImportMessages(字符串importdate)
{
    IEnumerable的< ImportHeader>消息=无效;
    VAR封邮件= client.GetStringAsync(的String.Format(API / importheaders $过滤器=记录来源EQ{0}?,importdate))结果。
    如果(!string.IsNullOrWhiteSpace(消息))
        消息= JsonConvert.DeserializeObject< IEnumerable的< ImportHeader>>(消息);
    返回JSON(信息,JsonRequestBehavior.AllowGet);
}
 

解决方案

一个电网需要一个DataSourceResult。

您应该得到这样的事情(没有测试过):

 公共JsonResult GetImportMessages([DataSourceRequest] DataSourceRequest要求,串importdate)
{
    IEnumerable的< ImportHeader>消息=无效;

    VAR封邮件= client.GetStringAsync(的String.Format(API / importheaders $过滤器=记录来源EQ{0}?,importdate))结果。
    如果(!string.IsNullOrWhiteSpace(消息))
        消息= JsonConvert.DeserializeObject< IEnumerable的< ImportHeader>>(消息);

    返回JSON(messages.ToDataSourceResult(要求),JsonRequestBehavior.AllowGet);
}
 

OK I have another and I'm sure I'm missing something simple again. Populating the Kendo Grid with a json result set. The load is triggered by a selection from a kendo dropdownlist control. I can see the data is returned from my webapi and converted to the json result. But the data is not displayed in the grid.

What I'm missing doing wrong?

Here is how grids view is added:

<div id="messageGridArea">
    @Html.Partial("Messages")
</div>

Here is dropdownlist definition:

@(Html.Kendo().DropDownList()
    .Name("importDates")
    .CascadeFrom("clients")
    .OptionLabel("Select Import Date...")
    .DataSource(source => {
        source.Read(read =>
        {
            read.Action("GetDistinctImportDates", "Home").Data("filterImportDates");
        })
        .ServerFiltering(true); 
     })
     .AutoBind(false)
     .Enable(false)
     .Events(e => e.Change("OnImportDatesChanged"))
)

Here is filter for grid parameters:

function filterGridMessages() {
    return { importdate: $("#importDates").val() };
}

Here is event to populate the grid:

function OnImportDatesChanged(e) {
    var grid = $("#clientMessages").data("kendoGrid");
    grid.dataSource.read();
}

Here is the grid definition:

@(Html.Kendo().Grid<Pulse.Data.Model.ImportHeader>()
    .Name("clientMessages")
    .AutoBind(false)
    .Filterable()
    .Groupable()
    .Sortable()
    .Pageable()
    .Scrollable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(p => p.ImportId))
        .ServerOperation(false)
        .Read(read =>
            read.Action("GetImportMessages", "Home").Data("filterGridMessages")
         )
    )
    .Columns(columns =>
    {
        columns.Bound("ImportStatus").Title("I").Width("3%");
        columns.Bound("ImportTime").Title("Import Time");
        columns.Bound("RecordStatus").Title("Status").Filterable(true).Sortable(true).Width("7%");
        columns.Bound("RecordState").Title("State").Filterable(true).Sortable(true).Width("7%");
        columns.Bound("RecordAction").Title("Action").Filterable(true).Sortable(true).Width("7%");                
    })
)

And finally here is the controller code to read the data:

public JsonResult GetImportMessages(string importdate)
{
    IEnumerable<ImportHeader> messages = null;
    var msgs = client.GetStringAsync(string.Format("api/importheaders?$filter=RecordSource eq '{0}'", importdate)).Result;
    if (!string.IsNullOrWhiteSpace(msgs))
        messages = JsonConvert.DeserializeObject<IEnumerable<ImportHeader>>(msgs);
    return Json(messages, JsonRequestBehavior.AllowGet);
}

解决方案

A grid requires a DataSourceResult.

You should get something like this (have not tested it):

public JsonResult GetImportMessages([DataSourceRequest] DataSourceRequest request, string importdate)
{
    IEnumerable<ImportHeader> messages = null;

    var msgs = client.GetStringAsync(string.Format("api/importheaders?$filter=RecordSource eq '{0}'", importdate)).Result;
    if (!string.IsNullOrWhiteSpace(msgs))
        messages = JsonConvert.DeserializeObject<IEnumerable<ImportHeader>>(msgs);

    return Json(messages.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

这篇关于剑道UI格不填充后调用读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆