【发布时间】:2015-07-13 12:10:26
【问题描述】:
我在同一个页面上有两个剑道网格,上面的网格包含“父”记录,下面的网格在单击父时显示父的“子”。
当我对父级执行操作时,我想 a) 更新数据库(父记录和子记录都受到影响),b) 重新加载父网格中的数据,然后 c) 重新加载子网格中的数据.
我可以做 a) 和 b),但 c) 不起作用。
这是我的功能:
// Restore a Soft-Deleted person
var processRestoreURL = crudServiceBaseUrl + '?method=restorePerson';
function restorePerson(id, row){
if (confirm('#getResource("person.detail.confirmrestore")#')) {
$.ajax({
type: 'POST',
url: processRestoreURL,
data: {
PERS_KY: id
},
success: function (data){
// Refresh the datasource so the row updates itself
$("#list").data("kendoGrid").dataSource.read();
// TO DO: Make the Organisation tab reload with the restored data
$("#organisationGrid").data("kendoGrid").dataSource.read();
// doesn't work :-(
// Seems to execute BEFORE the datasource refresh
// Maybe I just need to reload the tab here, no need to reread the datasource?
},
error: function (xhr, textStatus, errorThrown){
alert("Error while restoring person"+ "\n"+ xhr + "\n"+ textStatus + "\n" + errorThrown);
}
});
}
}
如何让#organisationGrid 刷新?
编辑
//on dataBound event
// 1: Change search operator to contain for every 'string' type
// 2: restore previous selected rows
// 3: Save person filter information in cookie
function dataBoundFunction(){
//Search change
setTimeout(function(){
var header;
$('.k-header').each(function(i){
if ($(this).data('kendoColumnMenu')) {
header = $(this).data('kendoColumnMenu');
if (header.filterMenu) {
header.menu.bind('open', function(e){
if ($(e.item).is('.k-filter-item')) {
header = $('.k-header:eq(' + i + ')').data('kendoColumnMenu');
var popup = header.filterMenu.popup;
if (!$(popup.element).data('alreadyOpened')) {
var select = this.element.find('select:first');
var option = select.children('option:contains("Contains")');
if (option.length > 0) {
select.data('kendoDropDownList').select(option.index());
header.filterMenu.filterModel.set("filters[0].operator", "contains");
}
$(popup.element).data('alreadyOpened', true);
}
}
});
header.filterMenu.form.bind('reset', function(){
$(this).parent().data('kendoFilterMenu').popup.element.data('alreadyOpened', false);
});
}
}
else
if ($(this).data('kendoFilterMenu')) {
header = $(this).data('kendoFilterMenu');
header.popup.bind('open', function(){
if (!$(this.element).data('alreadyOpened')) {
header = $('.k-header:eq(' + i + ')').data('kendoFilterMenu');
var select = this.element.find('select:first');
var option = select.children('option:contains("Contains")');
if (option.length > 0) {
select.data('kendoDropDownList').select(option.index());
header.filterModel.set("filters[0].operator", "contains");
}
$(this.element).data('alreadyOpened', true);
}
});
header.form.bind('reset', function(){
$(this).parent().data('kendoFilterMenu').popup.element.data('alreadyOpened', false);
});
}
});
}, 1);
//selected row
var view = gridList.dataSource.view();
var currentSelection = gridList.wrapper.data('currentSelection');
for(var i = 0; i < view.length;i++){
if(checkedIds[view[i].id]){
gridList.table.find("tr[data-uid='" + view[i].uid + "']")
.find("input[type=checkbox]")
.attr("checked","checked");
}
}
if(currentSelection) {
gridList.select('[data-uid=' + gridList.dataSource.get(currentSelection).uid + ']');
}
}
【问题讨论】:
-
您是否尝试过使用父网格上的数据绑定事件来刷新子网格?如果不是这可能是要走的路,那么在父网格的数据源中发生的任何更改都应该触发为您重新绑定子网格的请求。如果您需要示例,我很乐意提供。
-
错误...是的,请!那太好了!
-
实际上,关于 dataBound 的事情,父网格已经有一个 dataBound 属性,它调用一个单独的函数 dataBoundFunction(),它做了一大堆其他的事情。 (你会猜到我现在正在处理遗留代码)。该功能在我原来的帖子的编辑中。也许您可以建议对其进行更改以刷新我的#organisationGrid?
标签: kendo-ui kendo-grid