Hello,
I've built a hierarchy grid, but the problem is the foreign key on the detail grid that is not match the name on master grid, and the detail grid has another key with same name as the master grid, so they bind in wrong pair of the keys.
@{
var ComponentGrid = new Grid()
{
DataSource = new DataManager
{
Url = Url.Content("~/componentdata/datasource"),
InsertUrl = Url.Content("~/componentdata/add"),
UpdateUrl = Url.Content("~/componentdata/update"),
RemoveUrl = Url.Content("~/componentdata/delete"),
Adaptor = "UrlAdaptor",
},
QueryString = "Id",//this is the Id I need to search in master grid
EditSettings = new GridEditSettings
{
AllowAdding = true,
AllowDeleting = true,
AllowEditing = true,
Mode = EditMode.Dialog,
},
Toolbar = new List<string> { "Add", "Edit", "Delete", "Update", "Cancel" },
ActionBegin = "componentActionBegin",
ActionFailure = "actionFailure",
Columns = new List<GridColumn>
{
new GridColumn(){ Field="ContainerId",HeaderText="ContainerId", ForeignKeyField="Id", AllowEditing=false},
new GridColumn(){ Field="Id",IsPrimaryKey=true, HeaderText="#", Width="90", TextAlign=TextAlign.Right,AllowEditing=false },
new GridColumn(){ Field="Name",HeaderText="Container Name",ValidationRules="@(new { required=true})",Width="150"},
new GridColumn(){ Field="ComponentType",HeaderText="Type",Width="150"},
new GridColumn(){ Field="Active",HeaderText="Active",Template="#activeTemplate",EditType="booleanedit",TextAlign=TextAlign.Center,Type="boolean",Width="90"},
new GridColumn(){ Field="CreateTime",HeaderText="Create Time",EditType="datetimepickeredit",Format="yy-MM-dd h:mm:ss",Width="180",Type="date"},
new GridColumn(){ Field="CreateUserName",HeaderText="Create User",Width="120"},
new GridColumn(){ Field="UpdateTime",HeaderText="Update Time",EditType="datetimepickeredit",Format="yy-MM-dd h:mm:ss",Type="date",Width="180"},
new GridColumn(){ Field="UpdateUserName",HeaderText="Update User",Width="120"},
new GridColumn(){ Field="Note",HeaderText="Note",Width="200"},
}
};
}
<div class="control-section">
<ejs-grid id="Grid" childGrid="ComponentGrid" actionFailure="actionFailure" actionBegin="actionBegin" allowReordering="true" allowResizing="true" allowFiltering="true" allowSorting="true" allowExcelExport="true" allowPdfExport="true" showColumnChooser="true" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Update", "Cancel", "ColumnChooser" })">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"></e-grid-editSettings>
<e-grid-filterSettings type="Menu"></e-grid-filterSettings>
<e-grid-groupsettings showGroupedColumn="true"></e-grid-groupsettings>
<e-grid-pagesettings pageSizes="true"></e-grid-pagesettings>
<e-data-manager url='@Url.Content("~/containerdata/datasource")' insertUrl='@Url.Content("~/containerdata/add")' updateUrl='@Url.Content("~/containerdata/update")' removeUrl='@Url.Content("~/containerdata/delete")' adaptor="UrlAdaptor"></e-data-manager>
<e-grid-columns>
<e-grid-column field="Id" allowEditing="false" headerText="#" foreignKeyField="ContainerId" isPrimaryKey="true" textAlign="Right" width="90"></e-grid-column>
<e-grid-column field="Name" headerText="Container Name" validationRules="@(new { required=true})" width="150"></e-grid-column>
<e-grid-column field="ContainerType" headerText="Type" width="150"></e-grid-column>
<e-grid-column field="AppId" foreignKeyField="Key" headerText="App." foreignKeyValue="Name" dataSource="ViewBag.AppNames" width="150"></e-grid-column>
<e-grid-column field="Active" headerText="Active" template="#activeTemplate" editType="booleanedit" textAlign="Center" type="boolean" width="90"></e-grid-column>
<e-grid-column field="CreateTime" headerText="Create Time" editType="datetimepickeredit" format='yy-MM-dd h:mm:ss' width="180" type="date"></e-grid-column>
<e-grid-column field="CreateUserName" headerText="Create User" width="120"></e-grid-column>
<e-grid-column field="UpdateTime" headerText="Update Time" editType="datetimepickeredit" format='yy-MM-dd h:mm:ss' type="date" width="180"></e-grid-column>
<e-grid-column field="UpdateUserName" headerText="Update User" width="120"></e-grid-column>
<e-grid-column field="Note" headerText="Note" width="200"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
Hi Richard,
Greetings from Synfusion support.
Based on your query, you want to use different field name between parent and child grid. We have already discussed about this in the below forum.
Forum: https://www.syncfusion.com/forums/135567/primary-key-to-foreign-key-relationship-for-child-grid
Please refer the above forum and revert for more details.
Regards,
Joseph I.
I have a further question on this hierarchy, I've solved the the connection between the master and detail grid issue, but right now I found that I can't add or edit any record in the detail grid. The adding or updating window pops up, but nothing happen if click the save button, that does not invoke the backend curd method.
The master grid works fine on all edit and add methods.
Is adding or editing doable on the detail grid. May I have some sample if it doable.
Thank you,
Richard Bao
Hi Richard,
Thanks for your update.
Based on your query, you are not able to add or edit the records in the childgrid, but you are able to add or edit the records in the parent grid. We created a sample based on the provided information and the code example and we were able to reproduce the reported behavior. We are validating the issue from our side. We will provide further details on or before 31st May, 2022. We appreciate your patience until then.
Regards,
Joseph I.
Hi Richard,
Thanks for your patience.
We have created a sample, based on the provided information, but we were not able to reproduce the reported issue from our side. We have shared the sample for your reference.
Please share the below details so that we would be able to provide a better solution ASAP.
Please get back to us for further details.
Regards,
Joseph I.
Hello Joseph,
Attached code and the detail what I want to implemented.
Thank you,
Hi Richard,
Thanks for your update.
We have created a sample, based on the provided information, but we were not able to reproduce the reported issue from our side. We have shared the sample for your reference.
Please share the below details so that we would be able to provide a better solution ASAP.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/urladaptor-core873167191
Video: https://www.syncfusion.com/downloads/support/directtrac/general/ze/CHILDC~1220529255
Please get back to us for further details.
Regards,
Joseph I.
Hello Joseph,
I found the error:
new GridColumn(){ Field="Name",HeaderText="Container Name",ValidationRules="@(new { required=true})",Width="150"},
the validation Rules should not have the quotation mark.
Thank you,
Richard Bao
Hi Richard,
Thanks for your update.
We are glad that your issue has been resolved.
Please get back to us for further details.
Regards,
Joseph I