我有一个使用详细信息模板的网格。默认情况下,所有详细信息行都将关闭。
当我展开其中一个并执行编辑时,我希望网格在主 - 行打开的情况下重新加载。
在我的更新功能中,我这样做。重要的是大写:
$.ajax({
type: 'POST',
url: actionUrlSanc,
data: $form.serialize(),
success: function (data) {
objData = JSON.parse(data); // CF gives us back a serialised struct, so deserialise it!
if (objData.BSUCCESS == true) {
// REMOVE THE POP-UP EDITOR WINDOW
kendoWindow.close().destroy();
// RELOAD THE DATASOURCE
$('##offencesGrid').data('kendoGrid').dataSource.read();
// OPEN THE MASTER-ROW OF THE JUST-EDITED DETAIL ROW
// WHAT DO I DO HERE???...
} else {
alert(objData.SZERRMSG);
return false;
}
},
error: function (xhr, textStatus, errorThrown) {
alert(errorMsgSanc + "\n" + xhr + "\n" + textStatus + "\n" + errorThrown);
}
});
我知道在网格的数据绑定节点中,我可以使用以下内容扩展所有主行:
this.expandRow(this.tbody.find("tr.k-master-row"));
我可以通过这样做来扩展第一个主行:
this.expandRow(this.tbody.find("tr.k-master-row").first());
但我想我需要一些方法将主行从我的更新函数传递到expandRow()函数。
有人可以提供建议吗?
$(document).ready(function () {
$("##offencesGrid").kendoGrid({
detailInit: sanctionDetail
[the grid code... cut out for clarity/brevity]
});
function sanctionDetail(e) {
masterRow = e.masterRow;
[the dataRow code... cut out for clarity/brevity]
}
});
$.ajax({
type: 'POST',
url: actionUrlSanc,
data: $form.serialize(),
success: function (data) {
objData = JSON.parse(data); // CF gives us back a serialised struct, so deserialise it!
if (objData.BSUCCESS == true) {
// REMOVE THE POP-UP EDITOR WINDOW
kendoWindow.close().destroy();
// RELOAD THE DATASOURCE
$('##offencesGrid').data('kendoGrid').dataSource.read(); // New data is returned from database to datasource
// OPEN THE MASTER-ROW OF THE JUST-EDITED DETAIL ROW
console.log(masterRow); // Yep! I see the row, no problem!
try {
$("##offencesGrid").data("kendoGrid").expandRow(masterRow); // Nothing happens, dammit!!!
console.log("no error"); // This prints to console
} catch(err) {
console.log(err); // We do not arrive here, therefore no error
}
} else {
alert(objData.SZERRMSG);
return false;
}
},
error: function (xhr, textStatus, errorThrown) {
alert(errorMsgSanc + "\n" + xhr + "\n" + textStatus + "\n" + errorThrown);
}
});
$.ajax({
type: 'POST',
url: actionUrlSanc,
data: $form.serialize(),
success: function (data) {
objData = JSON.parse(data); // CF gives us back a serialised struct, so deserialise it!
if (objData.BSUCCESS == true) {
// REMOVE THE POP-UP EDITOR WINDOW
kendoWindow.close().destroy();
// RELOAD THE DATASOURCE
$('##offencesGrid').data('kendoGrid').dataSource.read(); // New data is returned from database to datasource
// OPEN THE MASTER-ROW OF THE JUST-EDITED DETAIL ROW
var grid = $("##offencesGrid").data("kendoGrid");
console.log(grid.tbody.find("tr.k-master-row")); // No problem. Three children in the object
console.log(grid.tbody.find("tr.k-master-row"):nth-child(1)); // ERROR. "Uncaught SyntaxError: missing ) after argument list"
//grid.data("kendoGrid").expandRow(masterRow);
} else {
alert(objData.SZERRMSG);
return false;
}
},
error: function (xhr, textStatus, errorThrown) {
alert(errorMsgSanc + "\n" + xhr + "\n" + textStatus + "\n" + errorThrown);
}
});
$.ajax({
type: 'POST',
url: actionUrlSanc,
data: $form.serialize(),
success: function (data) {
objData = JSON.parse(data); // CF gives us back a serialised struct, so deserialise it!
if (objData.BSUCCESS == true) {
// REMOVE THE POP-UP EDITOR WINDOW
kendoWindow.close().destroy();
// RELOAD THE DATASOURCE
$('##offencesGrid').data('kendoGrid').dataSource.read(); // New data is returned from database to datasource
// OPEN THE MASTER-ROW OF THE JUST-EDITED DETAIL ROW
var grid = $("##offencesGrid").data("kendoGrid");
var masterRow=1;
console.log(grid.tbody.find("tr.k-master-row:nth-child("+masterRow+")")); // The row prints
grid.expandRow(grid.tbody.find("tr.k-master-row:nth-child("+masterRow+")")); // The masterRow expands momentarily, then instantly collapses again
} else {
alert(objData.SZERRMSG);
return false;
}
},
error: function (xhr, textStatus, errorThrown) {
alert(errorMsgSanc + "\n" + xhr + "\n" + textStatus + "\n" + errorThrown);
}
});
$.ajax({
type: 'POST',
url: actionUrlSanc,
data: $form.serialize(),
success: function (data) {
objData = JSON.parse(data); // CF gives us back a serialised struct, so deserialise it!
if (objData.BSUCCESS == true) {
// REMOVE THE POP-UP EDITOR WINDOW
kendoWindow.close().destroy();
// RELOAD THE DATASOURCE
$('##offencesGrid').data('kendoGrid').dataSource.read(); // New data is returned from database to datasource
// DO NOT TRY TO OPEN THE MASTER-ROW OF THE JUST-EDITED DETAIL ROW HERE
// THE CODE NEEDS TO BE IN THE DATABOUND NODE OF THE GRID (see below)
} else {
alert(objData.SZERRMSG);
return false;
}
},
error: function (xhr, textStatus, errorThrown) {
alert(errorMsgSanc + "\n" + xhr + "\n" + textStatus + "\n" + errorThrown);
}
});
$(document).ready(function () {
$("##offencesGrid").kendoGrid({
detailInit: sanctionDetail
, dataBound: function (e) {
// OPEN THE MASTER-ROW OF THE JUST-EDITED DETAIL ROW
var grid = $("##offencesGrid").data("kendoGrid");
if (typeof masterRowIndex != 'undefined') {
grid.expandRow(grid.tbody.find("tr.k-master-row:nth-child("+masterRowIndex+")"));
// Destroy masterRowIndex after use so it doesn't persist if we move to a different agreement
delete masterRowIndex;
}
}
[the rest of the grid code... cut out for clarity/brevity]
});
function sanctionDetail(e) {
// DETERMINE THE INDEX OF THE MASTER-ROW
var objAllMasterRows = $("##offencesGrid").data("kendoGrid").tbody.find("tr.k-master-row");
// Loop objAllMasterRows and discern the masterRowIndex
$.each(objAllMasterRows, function(key, value) {
if (value == e.masterRow[0]) {
masterRowIndex = key+1;
return false;
}
});
[the rest of the dataRow code... cut out for clarity/brevity]
}
});