Kendo UI Grid帖子呈现或发布数据绑定事件?

问题描述 投票:23回答:2

有没有办法在通过ajax重新加载网格后触发事件?

我看到了RequestEnd事件。但这似乎发生在请求返回时,但在网格刷新之前。

我也看到了DataBound事件。但这比RequestEnd更早发生, 当我实现DataBound事件时,我的标题消失了..

我不得不诉诸这个黑客

function requestEnd(o) {
    console.debug('request ended.', o);
    setTimeout(refreshEditable, 500); // enough time to render the grid
}
function refreshEditable() {
    // perform my actions on controls within grid content
}

作为旁注..我很难找到可靠的kendo grid mvc API参考。当我谷歌为它,我得到这个:http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/migration/widgets/grid这是一个小方法和一些“事件”的集合,但那些不符合我在razor intelisense看到的。

更新:添加数据绑定定义

    $('#grid').kendoGrid({
        dataBound: function(e) {
            console.debug('data bound..');
        }
    });

这里是网格ajax的定义

   .Ajax().Read(read => read
        .Action("FilesRead", "SomeController")
        .Data("readData"))

 function readData() {
    return {
        IncludeChildren: $("#IncludeChildren").is(':checked'),
        SearchString: $('input[id=SearchString]').val()
    };
 }

我可以看到在进行ajax调用时触发DataBound,而不是在它返回后触发。

更新

更正了DataBound事件挂钩。

在dataBound函数中,我正在尝试获取对新渲染模板的引用。

function dataBound(o) {
  console.debug($('span.editable').length);                    // returns 0 
  setTimeout("console.debug($('span.editable').length)", 500); // returns 4
}

使用客户端模板添加跨度

.ClientTemplate(@"<span class=""editable"" ... >#=DOCUMENT_DATE_FORMATTED#</span>");

明白了吗?数据绑定发生在网格呈现之前

javascript kendo-ui telerik kendo-grid telerik-grid
2个回答
11
投票

有关如何使用MVC包装器绑定事件处理程序,请参阅documentation(关于事件的API文档是here)的示例代码:

@(Html.Kendo().Grid(Model)
      .Name("grid")
      .Events(e => e
          .DataBound("grid_dataBound")
          .Change("grid_change")
      )
)
<script>
function grid_dataBound() {
    //Handle the dataBound event
}

function grid_change() {
    //Handle the change event
}
</script>

如果要在JavaScript中绑定处理程序,则需要像这样访问网格:

var grid = $("#grid").data("kendoGrid");
grid.bind("dataBound", function(e) {});

当你在这里这样做:

$('#grid').kendoGrid({
    dataBound: function(e) {
        console.debug('data bound..');
    }
});

你实际上创建了一个新的网格实例。


0
投票

你可以用这种方式:

 transport: {
           read: {
           url: searchUrl,
           type: "POST",
           dataType: "json",
           data: additionalData,
           complete: function () {
              //code here :)
           }
        },                   
     },
© www.soinside.com 2019 - 2024. All rights reserved.