我在同一页面上有两个Kendo网格,上面的网格包含“父母”网格'记录,下方网格显示“孩子们”。单击父级时的父级。
当我对父项执行操作时,我想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 + ']');
}
}
答案 0 :(得分:0)
这是一个简单的演示,希望向您展示如何执行此操作:
重要位是第一个网格中的这个位:
dataBound: function (e) {
console.log(e);
reboundTimes = reboundTimes + 1;
$('#newConsole').html('<strong>rebinding child grid now: have done this: ' + reboundTimes + ' time(s)</strong>');
$('#grid2').data('kendoGrid').dataSource.read();
},
所有这一切都是因为一旦DataBound事件被触发它正在记录到控制台(只是为了显示事件已完成的事情)以及递增一个计数器以显示这是关闭事件。
一旦这已经启动它然后调用第二个网格然后触发dataSource上的读取事件。
任何问题都让我知道。