Kendo grid refresh issue in mobile

一世执手 提交于 2019-12-11 17:14:44

问题


I refresh the kendo grid for every 10 seconds, I used following code and I used the 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");
        }

This code gives me the output like following screenshot in system chrome,

But in mobile [All devices]

It appends with the old grid, instead of rebinding like following screenshot

I dont know what is problem here, I have googled and used $("#grid").data("kendoGrid").refresh(); this code too. Nothing happend, Any help will be highly appreciable.

Thanks, Guna


回答1:


@gitsitgo 's comment, I changed the code as following way, for avoid the re initialization of the grid, and now its working fine.

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");
    }

Thanks, Guna



来源:https://stackoverflow.com/questions/24576331/kendo-grid-refresh-issue-in-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!