【问题标题】:kendo ui grid not showing data剑道ui网格不显示数据
【发布时间】:2013-06-13 03:00:22
【问题描述】:

我正在尝试使这个基本的剑道 ui 具有可扩展的行工作:

<div id="grid"></div>

<script type="text/javascript">
    $(function () {
        $("#grid").kendoGrid({
            columns: [
            {
                field: "ProductId",
                title: "ProductId"
            }
        ],
            dataSource: {
                type: "json",
                transport: {
                    read: '@Url.Action("GetData1", "MockForms")'
                }
            },
            height: 450,
            sortable: true,
            pageable: true,
            detailTemplate: "<h2 style='background-color: yellow;'>Expanded!</h2>",
            detailExpand: function (e) {
                this.collapseRow(this.tbody.find(' > tr.k-master-row').not(e.masterRow));
            }
        });
    });  
</script>

json是这样生成的:

public ActionResult GetData1([DataSourceRequest] DataSourceRequest request)
        {
            var list = new List<Product>
                {
                    new Product {ProductId = 1, ProductType = "SomeType 1", Name = "Name 1", Created = DateTime.UtcNow},
                    new Product {ProductId = 1, ProductType = "SomeType 2", Name = "Name 2", Created = DateTime.UtcNow},
                    new Product {ProductId = 1, ProductType = "SomeType 3", Name = "Name 3", Created = DateTime.UtcNow}
                };

            return Json(list.AsQueryable().ToDataSourceResult(request));
        }

并且似乎发送正常(根据萤火虫)。但是,没有任何约束(没有 javascript 错误)。有什么想法吗?

PS:

OnaBai 的第二条评论帮助我完成了这项工作。我改变了:

return Json(list.AsQueryable().ToDataSourceResult(request));
=>
return Json(list);

产生这个 JSON:

[{"ProductId":1,"ProductType":"SomeType 1","Name":"Name 1","Created":"\/Date(1371022051570)\/"},{"ProductId":1,"ProductType":"SomeType 2","Name":"Name 2","Created":"\/Date(1371022051570)\/"},{"ProductId":1,"ProductType":"SomeType 3","Name":"Name 3","Created":"\/Date(1371022051570)\/"}]

我还是想用:

return Json(list.AsQueryable().ToDataSourceResult(request));

因为这最终会使分页和排序更容易。它目前产生:

{"Data":[{"ProductId":1,"ProductType":"SomeType 1","Name":"Name 1","Created":"\/Date(1371022186643)\/"},{"ProductId":1,"ProductType":"SomeType 2","Name":"Name 2","Created":"\/Date(1371022186648)\/"},{"ProductId":1,"ProductType":"SomeType 3","Name":"Name 3","Created":"\/Date(1371022186648)\/"}],"Total":3,"AggregateResults":null,"Errors":null}

我尝试使用:

field: "Data.ProductId",

代替:

field: "ProductId",

在 JavaScript 代码中无济于事。

【问题讨论】:

  • ProductId全都是1对吗?
  • 拜托,您介意编辑帖子并附上发送日期的样本吗?它应该看起来像 [{"ProductId":1,"ProductType":"SomeType 1","Name":"Name 1","Created":"2013-06-11T18:12:59.565Z"},{"ProductId":1,"ProductType":"SomeType 2","Name":"Name 2","Created":"2013-06-11T18:12:59.565Z"},{"ProductId":1,"ProductType":"SomeType 3","Name":"Name 3","Created":"2013-06-11T18:12:59.565Z"}]

标签: asp.net-mvc kendo-ui


【解决方案1】:

如果您想使用 ToDataSourceResult,您应该使用 ASP.NET MVC 包装器。文档中提供了更多信息:http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding

【讨论】:

  • 谢谢。我明白这一点。您介意将上面的代码重写为 mvc 样式但具有可扩展的行吗?这是我从未通过 mvc 风格工作的东西,这就是我切换回“html 风格”的原因
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多