移动设备中的Kendo网格刷新问题

时间:2014-07-04 14:20:46

标签: javascript jquery html kendo-ui kendo-grid

我每隔10秒刷新一次kendo网格,我使用了以下代码并使用了kendo.all.min.js

$(document).ready(function () {
            loadData();
            intervalManager(true, TableStatus, 10000);
        });
        var TableStatus = function () {
            loadData();
        }
        var refreshorderplacedgrid;
        function intervalManager(flag, animate, time) {
            if (flag)
                refreshorderplacedgrid = setInterval(animate, time);
            else
                clearInterval(refreshorderplacedgrid);
        }
        function loadData() {
            var grid = $("#grid").kendoGrid({
                dataSource: {
                    data: [
                            { ID: '1001', FirstName: 'Alphy', LastName: 'LastName', category: 'A', Markable: true },
                            { ID: '1002', FirstName: 'Betty', LastName: 'LastName', category: 'B', Markable: true}],
                    schema: {
                        model: {
                            fields: {
                                FirstName: { type: "string" },
                                LastName: { type: "string" }
                            }
                        }
                    },
                    sort: {
                        field: "FirstName",
                        dir: "asc"
                    },
                    pageSize: 10
                },
                scrollable: true,
                sortable: true,
                selectable: true,
                columns: [
                {
                    field: "FirstName",
                    title: "First Name"
                },
                {
                    field: "LastName",
                    title: "Last Name"
                },
                { template: kendo.template($("#isCancel-template").html()) }
            ]
            }).data("kendoGrid");
        }

此代码为我提供了类似系统镶边的截图

的输出

enter image description here

但在移动设备[所有设备]

它附加旧网格,而不是像后面的屏幕截图那样重新绑定

enter image description here

我不知道这里有什么问题,我用Google搜索并使用了$("#grid").data("kendoGrid").refresh();此代码。没有任何事情发生,任何帮助都会非常明显。

谢谢, 古娜

1 个答案:

答案 0 :(得分:2)

@gitsitgo的评论,我按照以下方式更改了代码,以避免重新初始化网格,现在它的工作正常。

var myDataSource = new kendo.data.DataSource({
        data: [
                        { ID: '1001', FirstName: 'Alphy', LastName: 'LastName', category: 'A', Markable: true },
                        { ID: '1002', FirstName: 'Betty', LastName: 'LastName', category: 'B', Markable: true },
                        { ID: '1003', FirstName: 'Betty', LastName: 'LastName', category: 'B', Markable: true}],
        schema: {
            model: {
                fields: {
                    FirstName: { type: "string" },
                    LastName: { type: "string" }
                }
            }
        },
        sort: {
            field: "FirstName",
            dir: "asc"
        },
        pageSize: 10
    });

    $(document).ready(function () {
        initGrid();
        loadData();
        intervalManager(true, TableStatus, 10000);            
    });
    var TableStatus = function () {
        loadData();
    }
    var refreshorderplacedgrid;
    function intervalManager(flag, animate, time) {
        if (flag)
            refreshorderplacedgrid = setInterval(animate, time);
        else
            clearInterval(refreshorderplacedgrid);
    }
    function loadData() {
        $("#grid").data("kendoGrid").setDataSource(myDataSource);
        $("#grid").data("kendoGrid").refresh();
    }
    function initGrid() {
        var grid = $("#grid").kendoGrid({
            dataSource: myDataSource,
            scrollable: true,
            sortable: true,
            selectable: true,
            columns: [
            {
                field: "FirstName",
                title: "First Name"
            },
            {
                field: "LastName",
                title: "Last Name"
            },
            { template: kendo.template($("#isCancel-template").html()) }
        ]
        }).data("kendoGrid");
    }

谢谢, 古纳