【问题标题】:Kendo Grid doesn't show any data despite having data within DataSource尽管 DataSource 中有数据,但 Kendo Grid 不显示任何数据
【发布时间】:2017-03-31 12:38:52
【问题描述】:

所以,我正在尝试使用剑道制作一个显示数据的现成网格,但无论我做什么,数据都不会显示。

The grid looks like this

这是代码:

    $("#Materials")
        .kendoGrid({
            dataSource: {
                data: [],
                schema: {
                    model: {
                        id: "ID",
                        fields: {
                            ID: { type: "number", editable: false },
                            Code: { type: "string", editable: false },
                            Name: { type: "string", editable: false },
                            ExtDeviceCode: { type: "string", editable: false , nullable: true },
                            BaseUomLOVString: { type: "string", editable: false }
                        }
                    }
                },
                pageSize: 20
            },
            filterable: {
                extra: true
            },
            pageable: true,
            columns: [
                { field: "Code", title:"Code"},
                { field: "Name", title: "Name"},
                { field: "ExtDeviceCode", title:"External device code"},
                { field: "BaseUomLOVString", title: "UnitsOfMeasure" }
            ],
            editable: false
        });

这会生成一个没有数据的空网格,我稍后会使用 Ajax 调用对其进行填充。如上图所示,网格包含数据,但不显示。 dataSource looks like this. 或 Json 内的数据:

[{
    "ID": 21150,
    "Code": "3",
    "ExtDeviceCode": null,
    "Name": "Avio benzin",
    "BaseUomLOVString": "Kilogram"
}, {
    "ID": 21400,
    "Code": "5003",
    "ExtDeviceCode": null,
    "Name": "Bencin 95",
    "BaseUomLOVString": "Litre"
}]

编辑 1:我正在使用这样的 Ajax 调用填充数据:

            $.ajax({
                url: '@SimpleUrlHelper.UrlObjectToRoot(Url)/FuelPointMaterialTankMask/LookupMaterials',
                data: {
                    //Send list of IDs
                    'materialIDs': materialList
                },
                type: "POST",
                success: function (response) {

                    var tmp = [];
                    if (typeof response !== "undefined" && 
                    response !== null) {
                        response.forEach(function(item) {
                            tmp.push(item);
                        });
                    }
                    grid = $("#Materials").data("kendoGrid");
                    originalMaterialDataSource = grid.dataSource;
                    originalMaterialDataSource.data(tmp);
                    originalMaterialDataSource._destroyed = [];
                    originalMaterialDataSource.pageSize(pageSize);
                    originalMaterialDataSource.page(1);
                    originalMaterialDataSource._total = tmp.length;
                    grid.pager.refresh();
                }
            });

【问题讨论】:

  • ajax 调用后如何填充网格?
  • 抱歉回复晚了!将上面的 Ajax 调用代码添加到“编辑”段落中。

标签: kendo-ui grid datasource display


【解决方案1】:

您可以在调用 ajax 后在 dataSource 中设置数据。

var dataArray = [{
    "ID": 21150,
    "Code": "3",
    "ExtDeviceCode": null,
    "Name": "Avio benzin",
    "BaseUomLOVString": "Kilogram"
}, {
    "ID": 21400,
    "Code": "5003",
    "ExtDeviceCode": null,
    "Name": "Bencin 95",
    "BaseUomLOVString": "Litre"
}];

使用.data()设置:

$("#Materials").data('kendoGrid').dataSource.data(dataArray );

【讨论】:

  • 我确实尝试在创建网格后立即用您的代码填充数据,结果是相同的。 dataSource.data() 中包含数据,但 $('#Materials').data('kendoGrid').dataSource.view() 始终为空,并且不显示任何内容。就像网格被折叠了一样。
【解决方案2】:

好吧,经过几天的努力,我终于找到了答案。

与我的想法一致:

var grids = $('.k-grid');
for (var i = 0; i < grids.length; i++) {
        ....
grid.dataSource.filter().filters[0] = {
       logic: "or",
       filters: filters
}
        ....

所以基本上我在所有网格上都放置了过滤器而不排除这个,这只是我的一个错误。

【讨论】:

    猜你喜欢
    • 2018-11-13
    • 2015-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    相关资源
    最近更新 更多