更新或删除后无法重新加载kendo网格

时间:2016-04-20 06:25:59

标签: jquery kendo-ui

我有kendo网格我可以更新或删除它上面的行。但问题是我无法在更新或删除行后立即刷新kendo网格,但是当点击f5重新加载时效果很好。我尝试了许多不起作用的方法。

    $.post(LogstimeEditConstants.urlLogstimeEditRead, { projectId: projectid,  userId: userid },
            function (result) {
                objdata = eval(result.data);
                defaultProjectId = result.defaultProjectId;
            });
        var dslogstime = new kendo.data.DataSource({
            data: objdata,
            schema: {
                model: {
                    id: "Id",
                    fields: {
                        Id: { required: true },
                        ProjectID: { defaultValue: defaultProjectId },
                        WorkDate: { type: "date", defaultValue: dateselect },
                        TaskId: { defaultValue: defaultTaskId },
                        WorkHours: { type: "number", defaultValue: "0.5" },
                        Description: {},
                        IsDelete: { type: "boolean", defaultValue: false }
                    }
                }
            },
            sort: [{ field: "ProjectID", dir: "asc" }]
        });
        timelogGrid = $("#tleditgrid").kendoGrid({
            dataSource: dslogstime,
            scrollable: true,
            editable: "inline",
    });

$("#savebutton").click(function (e){
// Remove Logstime
        $.ajaxSetup({ async: false });
        for (var i = 0; i < deleteTimeLogsData.length; i++) {
            if (deleteTimeLogsData[i].IsDelete === true) {
                var timelogsId = deleteTimeLogsData[i].Id;
                $.post(LogstimeEditConstants.urlLogstimeDelete, { logstimeId: timelogsId },
                    function (result) {
                            $.post(LogstimeEditConstants.urlLogstimeEditRead, { editType: edittype, projectId: projectid, selectDay: selectday, selectMonth: selectmonth, userId: userid },
                            function (result) {
                                objdata = eval(result.data);
                                defaultProjectId = result.defaultProjectId;
                            });
                            timelogGrid.dataSource.read();
                            timelogGrid.refresh();
                        }
                    });
            }
        }
});

请帮帮我,谢谢。

1 个答案:

答案 0 :(得分:0)

试试$ .post(LogstimeEditConstants,... 重新分配timelogGrid.dataSource.data = objdata; 在刷新之前。 这意味着您必须将下两行放在响应中

timelogGrid.dataSource.read(); timelogGrid.refresh();