我正在使用带有asp.net的Obout Grid c#我们有一个嵌套的Obout Grid我正在编辑Details Grid后我们想要刷新Master Grid并且在刷新之后我们想保持我的网格更新的扩展
<obout:Grid ID="GrdVendor" runat="server" AutoGenerateColumns="false" AutoPostBackOnSelect="false"
AllowSorting="false" ShowFooter="false" AllowPaging="false" Width="100%" Height="370px"
PageSize="0" AllowAddingRecords="false" AllowPageSizeSelection="false">
<ScrollingSettings ScrollHeight="500" />
<Columns>
<obout:Column DataField="ORG_ID" Visible="false" HeaderText="Org ID">
</obout:Column>
<obout:Column DataField="VENDOR_ID" Visible="false" HeaderText="VENDOR ID">
</obout:Column>
<obout:Column DataField="ORGANIZATION_NAME" Visible="true" HeaderText="Organization Name"
Width="33%">
</obout:Column>
<obout:Column DataField="outstanding_amt" Visible="true" HeaderText="Outstanding Amt"
Width="33%" HeaderAlign="right" Align="right">
</obout:Column>
<obout:Column DataField="OUTSTANDING_REQ_AMT" Visible="true" HeaderText="Outstanding Req Amt"
Width="33%" HeaderAlign="right" Align="right">
</obout:Column>
</Columns>
<MasterDetailSettings LoadingMode="OnCallback" />
<DetailGrids>
<obout:DetailGrid runat="server" ID="GrdCategoryDetails" ForeignKeys="VENDOR_TYPE_LOOKUP_CODE,VENDOR_ID,ORG_ID"
AllowSorting="false" DataSourceID="vendor_Details" PageSize="10" AllowPaging="true"
Width="98%" AllowAddingRecords="false" AllowPageSizeSelection="true" AutoGenerateColumns="false"
ShowCollapsedGroups="false" ShowFooter="true" AllowDataAccessOnServer="true"
OnUpdateCommand="GrdCategoryDetails_UpdateCommand">
<ScrollingSettings ScrollHeight="250" />
<ClientSideEvents OnClientUpdate="onCommand" ExposeSender="true" />
<Columns>
<obout:Column DataField="ORG_ID" Visible="false" HeaderText="Org ID" ReadOnly="true">
</obout:Column>
<obout:Column DataField="VENDOR_ID" Visible="false" HeaderText="Vendor ID" ReadOnly="true">
</obout:Column>
<obout:Column DataField="VENDOR_TYPE_LOOKUP_CODE" Visible="true" HeaderText="Broker Type"
ReadOnly="true" Width="33%">
</obout:Column>
<obout:Column DataField="OUTSTANDING_AMT" Visible="true" HeaderText="Outstanding Amt"
HeaderAlign="right" Align="right" ReadOnly="true" Width="33%">
</obout:Column>
<obout:Column DataField="OUTSTANDING_REQ_AMT" Visible="true" HeaderText="Outstanding Req Amt"
HeaderAlign="right" Align="right" Width="33%">
</obout:Column>
<obout:Column ID="Column1" AllowEdit="true" HeaderText="Edit" Width="100" runat="server">
</obout:Column>
</Columns>
<DetailGrids>
<obout:DetailGrid runat="server" ID="GrdvendorDetailsGrid" ForeignKeys="VENDOR_TYPE_LOOKUP_CODE,VENDOR_ID,ORG_ID"
AutoGenerateColumns="false" AllowSorting="false" DataSourceID="Vendor_Details1"
PageSize="10" AllowPaging="true" Width="98%" AllowAddingRecords="false">
<Columns>
<obout:Column DataField="ORG_ID" Visible="false" HeaderText="Org ID" ReadOnly="true">
</obout:Column>
<obout:Column DataField="VENDOR_ID" Visible="false" HeaderText="Vendor ID" ReadOnly="true">
</obout:Column>
<%--<obout:Column DataField="VENDOR_TYPE_LOOKUP_CODE" Visible="true" HeaderText="Broker Type"
ReadOnly="true" Width="25%">
</obout:Column>--%>
<obout:Column DataField="VENDOR_NAME" Visible="true" HeaderText="Vendor Name" ReadOnly="true"
Width="33%">
</obout:Column>
<obout:Column DataField="OUTSTANDING_AMT" Visible="true" HeaderText="Outstanding Amt"
HeaderAlign="right" Align="right" ReadOnly="true" Width="33%">
</obout:Column>
<obout:Column DataField="OUTSTANDING_REQ_AMT" Visible="true" HeaderText="Outstanding Req Amt"
HeaderAlign="right" Align="right" Width="33%">
</obout:Column>
</Columns>
<DetailGrids>
<obout:DetailGrid runat="server" ID="GrdInvoiceDetailsGrid" AutoGenerateColumns="false"
AllowAddingRecords="false" AllowSorting="false" AllowPaging="true" PageSize="10"
ForeignKeys="VENDOR_TYPE_LOOKUP_CODE,VENDOR_ID,ORG_ID" Width="98%" DataSourceID="SqlDataSource_InvoiceDetails">
<Columns>
<obout:Column DataField="INVOICE_ID" HeaderText="Invoice ID" ReadOnly="true" Visible="false">
</obout:Column>
<obout:Column DataField="ORG_ID" HeaderText="ORG_ID" ReadOnly="true" Visible="false">
</obout:Column>
<obout:Column DataField="ORGANIZATION_NAME" HeaderText="Organization Name" Wrap="true"
ReadOnly="true" Width="18%">
</obout:Column>
<obout:Column DataField="PROJECT_DESCRIPTIONS" HeaderText="Project" Wrap="true" Width="12%"
ReadOnly="true">
</obout:Column>
<obout:Column DataField="INVOICE_NUM" HeaderText="Invoice Num" Wrap="true" ReadOnly="true"
Width="12%">
</obout:Column>
<obout:Column DataField="INVOICE_DATE" HeaderText="Invoice Date" Wrap="true" ReadOnly="true"
Width="13%" DataFormatString="{0:MM/dd/yyyy}">
</obout:Column>
<obout:Column DataField="INVOICE_AMT" HeaderText="Invoice Amt" Wrap="true" ReadOnly="true"
HeaderAlign="right" Align="right" Width="13%">
</obout:Column>
<obout:Column DataField="OUTSTANDING_AMT" HeaderText="Outstanding Amt" Wrap="true"
HeaderAlign="right" Align="right" Width="15%" ReadOnly="true">
</obout:Column>
<obout:Column DataField="OUTSTANDING_REQ_AMT" HeaderText="Outstanding Req Amt" Wrap="true"
HeaderAlign="right" Width="15%" Align="right">
</obout:Column>
</Columns>
</obout:DetailGrid>
</DetailGrids>
</obout:DetailGrid>
</DetailGrids>
</obout:DetailGrid>
</DetailGrids>
</obout:Grid>
<script type="text/javascript">
function onCommand(sender, record) {
var masterGrid = getMasterGrid(sender.ID, null);
window.setTimeout(masterGrid.ID + '.refresh();', 250);
}
function getMasterGrid(detailGridId, currentGrid) {
if (!currentGrid) {
currentGrid = GrdVendor;
}
if (currentGrid.DetailGrids) {
for (var i = 0; i < currentGrid.DetailGrids.length; i++) {
if (currentGrid.DetailGrids[i].ID == detailGridId) {
return currentGrid;
} else {
var masterGrid = getMasterGrid(detailGridId, currentGrid.DetailGrids[i]);
if (masterGrid != null) {
return masterGrid;
}
}
}
}
return null;
}
</script>
答案 0 :(得分:0)
我重新创建了你的例子,这是我的回答:
<script type="text/javascript">
var expandedDetailsIndexes = '';
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function () {
if (oldonload) {
oldonload();
}
func();
}
}
}
function AttachEvents() {
oboutGrid.prototype.manageDetailGridsExpandedState_old = oboutGrid.prototype.manageDetailGridsExpandedState;
oboutGrid.prototype.manageDetailGridsExpandedState = function (obj) {
var currentRow = obj.parentNode.parentNode.parentNode.parentNode;
this.manageDetailGridsExpandedState_old(obj);
storeExpandedDetails(this.ID, this.getElementIndex(currentRow));
}
}
function storeExpandedDetails(gridId, rowIndex) {
var expandedDetails = expandedDetailsIndexes;
var existingElement = false;
if (expandedDetails != '') {
var arrExpandedDetails = expandedDetails.split(',');
var gridBaseId = gridId;
if (gridBaseId.indexOf('_') != -1) {
gridBaseId = gridId.substr(0, gridId.indexOf('_'));
}
for (var i = 0; i < arrExpandedDetails.length; i += 2) {
if (arrExpandedDetails[i].indexOf(gridBaseId) == 0) {
arrExpandedDetails[i] = gridId;
arrExpandedDetails[i + 1] = rowIndex;
existingElement = true;
}
}
} else {
var arrExpandedDetails = new Array();
}
if (!existingElement) {
arrExpandedDetails.push(gridId);
arrExpandedDetails.push(rowIndex);
}
expandedDetailsIndexes = arrExpandedDetails.join(',');
}
function restoreExpandedDetails(tempExpandedDetails) {
if (tempExpandedDetails != '') {
var arrExpandedDetails = tempExpandedDetails.split(',');
var gridId = arrExpandedDetails.shift();
var rowIndex = arrExpandedDetails.shift();
try {
var grid = eval(gridId);
grid.getExpandCollapseDetailsButtonForRow(grid.GridBodyContainer.firstChild.firstChild.childNodes[1].childNodes[rowIndex]).onclick();
tempExpandedDetails = arrExpandedDetails.join(',');
} catch (ex) {
}
window.setTimeout(function () { restoreExpandedDetails(tempExpandedDetails); }, 500);
}
}
function onCommand(sender, record) {
var masterGrid = getMasterGrid(sender.ID, null);
eval(masterGrid.ID + '.refresh();');
window.setTimeout(function () {
restoreExpandedDetails(expandedDetailsIndexes);
}, 250);
}
function getMasterGrid(detailGridId, currentGrid) {
if (!currentGrid) {
currentGrid = GrdVendor;
}
if (currentGrid.DetailGrids) {
for (var i = 0; i < currentGrid.DetailGrids.length; i++) {
if (currentGrid.DetailGrids[i].ID == detailGridId) {
return currentGrid;
} else {
var masterGrid = getMasterGrid(detailGridId, currentGrid.DetailGrids[i]);
if (masterGrid != null) {
return masterGrid;
}
}
}
}
return null;
}
addLoadEvent(function () {
AttachEvents();
});
</script>