【问题标题】:Kendogrid not refreshingKendogrid 不刷新
【发布时间】:2016-10-25 16:07:42
【问题描述】:

我有一个从服务器提取数据并填充它的 kendogrid。好吧,我在每行末尾显示的客户端模板中有一个自定义按钮。当我修改这一行时,更改是在数据库中进行的,但不会反映在网格中。

最奇怪的是,当我第二次点击按钮时,它确实起作用了。

代码如下:

$('#custom-generic-modal.modal-content').off('click', '#btnSave').on('click', '#btnSave', function () {

var permissions = $('#divNav .k-state-selected').attr('data-permissionid');
var currentPage = grid.dataSource.page();

$.ajax({
    //global: false,
    type: 'GET',
    url: 'Allergy/AllergiesTab?permissions=' + permissions,
    async: 'false',
    success: function (page) {
        $("#PageDiv").html(page);
        console.log('success')
    },
    complete: function () {
        $.get("Page/PageTab?permissions=" + permissions, function(page) {
            $("#PageDiv").html(page);
            helpers.notify("Retraction successful.", "success");
        }).done(function() {
            var grid = $("#Grid").data("kendoGrid");
            grid.dataSource.page(currentPage);
            grid.refresh();
            console.log('complete')
        });
    }
});

});

这是我的网格:

@(Html.Kendo().Grid(Model.grid)
           .Name("Grid")
           .ClientDetailTemplateId("template")
           .HtmlAttributes(new { style = "height: 450px;" })
           .Columns(c =>
               {
                   c.Bound(x => x.IsAllergy).Title("").Width("13%").ClientTemplate(@"<span class='#if(IsRetracted){#strike-through#}#'>#if (IsAllergy){#<span><b> Allergy </b></span>#}# #if (!IsAllergy){#<span><b> Sensitivity </b></span>#}# </span>");
                   c.Bound(x => x.AllergyDescription).Title("Allergen/Sensitivity").Width("24%").ClientTemplate(@"<span class='#if(IsRetracted){#strike-through#}#'>#if (AllergyDescription != null){#<span><b> #= AllergyDescription # </b></span>#}# #if (AllergyDescription == null){#<span><b> N/A </b></span>#}# </span>");
                   //AllergyType(Food,drug,ev)
                   c.Bound(x => x.AllergySeverityDescription).Title("Severity").Width("13%").ClientTemplate(@"<span class='#if(IsRetracted){#strike-through#}#'>#if (AllergySeverityDescription != null){#<span> #= AllergySeverityDescription # </span>#}# #if (AllergySeverityDescription == ''){#<span> N/A </span>#}# </span>");
                   c.Bound(x => x.AllergyReactionDescription).Title("Reaction").Width("13%").ClientTemplate(@"<span class='#if(IsRetracted){#strike-through#}#'>#if (AllergyReactionDescription != null){#<span> #= AllergyReactionDescription # </span>#}# #if (AllergyReactionDescription == ''){#<span> N/A </span>#}# </span>");
                   c.Bound(x => x.TreatmentComments).Title("Treatment Comments").Width("24%").ClientTemplate(@"<span class='#if(IsRetracted){#strike-through#}#'>#if (TreatmentComments != null){#<span> #= TreatmentComments # </span>#}# #if (TreatmentComments == null){#<span> N/A </span>#}# </span>");
                   c.Template(@<text></text>)
                       //.ClientTemplate(@" #if(!IsActive) {#<a class='notes-btn'><span class='glyphicon glyphicon-pencil'></span></a> #if(!IsRetracted) {#<a class='notes-btn' onclick='retractAllergyInit(#= PersonAllergyId #)'><span class='glyphicon glyphicon-minus-sign'></span></a>#}}#")
                    .ClientTemplate(@" #if(!IsActive) {#<a class='notes-btn'><span class='glyphicon glyphicon-pencil'></span></a> #if(!IsRetracted) {#<a class='notes-btn modal-link' href='Retract/Retract?typeId=#= PersonAllergyId #&retractType=5' data-ajax='true' data-ajax-method='GET' data-ajax-mode='replace'><span class='glyphicon glyphicon-minus-sign'></span></a>#}}#")
                   .Title("Actions").Width("12%");
               }
           )
           .Pageable(pager => pager.Messages(m => m.Empty("No Results Found")))
           .DataSource(dataSource => dataSource
                                         .Ajax()
                                         .PageSize(10)
                                         .ServerOperation(false))
           )

【问题讨论】:

    标签: javascript jquery ajax kendo-ui


    【解决方案1】:

    grid.refresh() "使用当前数据项呈现所有表格行。" http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-refresh

    我没有看到任何导致数据源从服务器重新读取的代码。

    试试看

     grid.dataSource.read();
    

    相反,它将始终重新命中在 dataSource.transport.read 中配置的服务器操作。

    您应该提供您的网格配置代码以提供更多详细信息。

    【讨论】:

      【解决方案2】:

      使用读取将从服务器请求数据并更新网格后面的数据源。使用 read 方法不会对 UI 进行任何更改。刷新将从当前数据源重新渲染网格中的项目。两者都需要查看网格中的变化。

      【讨论】:

        猜你喜欢
        • 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
        相关资源
        最近更新 更多