@(Html.EJ().Grid("Grid_Item")
.Datasource(ds => ds.Json((IEnumerable
)ViewBag.datasourceItem).UpdateURL("../Parameters/itemUpdate").InsertURL("../Parameters/itemInsert").RemoveURL("../Parameters/itemRemove").Adaptor(AdaptorType.RemoteSaveAdaptor))
.AllowSorting()
.AllowFiltering()
.AllowSearching()
.FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
.AllowPaging()
.PageSettings(p => { p.PageSize(14); })
.IsResponsive()
.EnableHeaderHover()
.EnableAltRow()
.EditSettings(edit => {
edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Normal).ShowDeleteConfirmDialog().AllowEditOnDblClick(false);
})
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
items.AddTool(ToolBarItems.Search);
});
})
.Columns(col =>
{
col.Field("PK_ID").HeaderText("PK_ID").IsPrimaryKey(true).Visible(false).TextAlign(TextAlign.Center).Width(100).Add();
col.Field("FK_ID_Family").HeaderText(Resources.Parameters.ItemView_Family_HeaderText).ForeignKeyField("PK_ID").ForeignKeyValue("Wording").DataSource((IEnumerable)ViewBag.dataSourceFamily).TextAlign(TextAlign.Center).Width(100).Add();
col.Field("FK_ID_Sub_Family").HeaderText(Resources.Parameters.ItemView_SubFamily_HeaderText).ValidationRules(v
=> v.AddRule("required",
true)).ForeignKeyField("PK_ID").ForeignKeyValue("Wording").DataSource((IEnumerable)ViewBag.dataSourceSubFamily).TextAlign(TextAlign.Center).Width(100).Add();
col.Field("Wording").HeaderText(Resources.Parameters.ItemView_Wording_HeaderText).Width(100).ValidationRules(v
=> v.AddRule("required", true)).TextAlign(TextAlign.Left).Add();
col.Field("Price").HeaderText(Resources.Parameters.ItemView_Price_HeaderText).TextAlign(TextAlign.Right).Format("{0:N}").EditType(EditingType.NumericEdit).Format("{0:N}").NumericEditOptions(new
Syncfusion.JavaScript.Models.EditorProperties() { DecimalPlaces = 2
}).Width(50).Add();
})
Thanks for your help ! :)
Hi Johann,
Thanks for contacting Syncfusion Support.
We have checked your query and while using Foreign key Data, foreign-key-field has some limitations such as sort/group/ Search
operations on column will happen based on “field” property instead of foreign-key-field”. When you search by using Employee ID, it
will filter corresponding records related to the id not using value which was
the behavior when we bind foreign key column. To overcome this, we suggested
you to used Foreign Key Adaptor on Load
event of the Grid. In the code example, you have used remoteSaveAdaptor to
bind the Data’s grid and on the Load event of the Grid we have changed the
adaptor type to ForeignkeyAdaptor.
Please refer to the documentation and Online Demo Link:-
https://mvc.syncfusion.com/demos/web/grid/foreignkey
Please get back to us if you need any further assistance.
Regards,
Farveen sulthana T
|
<script type="text/javascript">
var familyObj = [
{
dataSource: familyData,
foreignKeyField: "PK_ID",
field: "FK_ID_Family",
foreignKeyValue: "Wording"
},
{
dataSource: subFamilyData,
foreignKeyField: "PK_ID",
field: "FK_ID_Sub_Family",
foreignKeyValue: "Wording"
}
];
function onLoad(args){
this.model.dataSource.adaptor = new ej.ForeignKeyAdaptor(familyObj, "remoteSaveAdaptor");
}
</script> |
Hi Johann,
We can reproduce your reported problem at our end. To
overcome this problem we suggested you to define the DataSource for the ForeignKey column which should be in the form of
text and pair value. Otherwise you
can define it on the DropDownEditOptions of the Grid.
Please refer to the code example:-
|
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds =>{
ds.Json((IEnumerable<object>)ViewBag.datasource)
.UpdateURL("/Grid/ForeignKeyUpdate")
.InsertURL("/Grid/ForeignKeyInsert")
.RemoveURL("/Grid/ForeignKeyDelete") .Adaptor(AdaptorType.RemoteSaveAdaptor); }) .AllowPaging()
.AllowFiltering()
.AllowSorting()
.Columns(col => {
col.Field("OrderID").HeaderText("Order
ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Add(); col.Field("EmployeeID_FirstName").HeaderText("First
Name") .DataSource((IEnumerable<object>)ViewBag.datasource).Add(); .
. . . }) ) |
Please get back to us if you need any further assistance.
Regards,
Farveen sulthana T
|
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds =>{
ds.Json((IEnumerable<object>)ViewBag.datasource)
.UpdateURL("/Grid/ForeignKeyUpdate")
.InsertURL("/Grid/ForeignKeyInsert")
.RemoveURL("/Grid/ForeignKeyDelete")
.Adaptor(AdaptorType.RemoteSaveAdaptor);
})
. .
.Columns(col =>
{
col.Field("EmployeeID_FirstName").HeaderText("First Name").EditType(EditingType.Dropdown).DataSource((IEnumerable<object>)ViewBag.datasource2).DropDownEditOptions(new DropDownListProperties() { DropDownListFields = { Text = "FirstName", Value = "EmployeeID" } })
.Width(90)
.Add();
})
.ClientSideEvents(eve =>
{
eve.Load("onLoad");
})
)
<script type="text/javascript">
var foreignData = @Html.Raw(Json.Encode(ViewBag.foreignCol));
var foreignObj = [
{
dataSource: foreignData,
foreignKeyField: "EmployeeID", //Property in the Grid's main dataSource
field: "EmployeeID", //Property in foreignkey dataSource
foreignKeyValue: "FirstName" //Property in foreignkey dataSource
}
];
function onLoad(args){
this.model.dataSource.adaptor = new ej.ForeignKeyAdaptor(foreignObj, "remoteSaveAdaptor");
}
</script>
Server side:-
public ActionResult GridFeatures()
{
BindDataSource();
var datasource = order.ToList();
ViewBag.datasource = datasource;
var DataSource1 = new NorthwindDataContext().EmployeeViews.ToList();
ViewBag.datasource2 = DataSource1;
ViewBag.foreignCol = new NorthwindDataContext().EmployeeViews.ToList();
return View();
} |
|
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds =>{
ds.Json((IEnumerable<object>)ViewBag.datasource)
.UpdateURL("/Grid/ForeignKeyUpdate")
.InsertURL("/Grid/ForeignKeyInsert")
.RemoveURL("/Grid/ForeignKeyDelete")
.Adaptor(AdaptorType.RemoteSaveAdaptor);
})
. .
.Columns(col =>
{
col.Field("EmployeeID_FirstName").HeaderText("First Name").EditType(EditingType.Dropdown).DataSource((IEnumerable<object>)ViewBag.datasource2).DropDownEditOptions(new DropDownListProperties() { DropDownListFields = { Text = "FirstName", Value = "EmployeeID" } })
.Width(90)
.Add();
})
.ClientSideEvents(eve =>
{
eve.Load("onLoad");
})
)
<script type="text/javascript">
var foreignData = @Html.Raw(Json.Encode(ViewBag.foreignCol));
var foreignObj = [
{
dataSource: foreignData,
foreignKeyField: "EmployeeID", //Property in the Grid's main dataSource
field: "EmployeeID", //Property in foreignkey dataSource
foreignKeyValue: "FirstName" //Property in foreignkey dataSource
}
];
function onLoad(args){
this.model.dataSource.adaptor = new ej.ForeignKeyAdaptor(foreignObj, "remoteSaveAdaptor");
}
</script>
Server side:-
public ActionResult GridFeatures()
{
BindDataSource();
var datasource = order.ToList();
ViewBag.datasource = datasource;
var DataSource1 = new NorthwindDataContext().EmployeeViews.ToList();
ViewBag.datasource2 = DataSource1;
ViewBag.foreignCol = new NorthwindDataContext().EmployeeViews.ToList();
return View();
} |
|
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds =>{
ds.Json((IEnumerable<object>)ViewBag.datasource)
.UpdateURL("/Grid/ForeignKeyUpdate")
.InsertURL("/Grid/ForeignKeyInsert")
.RemoveURL("/Grid/ForeignKeyDelete")
.Adaptor(AdaptorType.RemoteSaveAdaptor);
})
. .
.Columns(col =>
{
col.Field("EmployeeID_FirstName").HeaderText("First Name").EditType(EditingType.Dropdown).DataSource((IEnumerable<object>)ViewBag.datasource2)
.DropDownEditOptions(new DropDownListProperties() { DropDownListFields = { Text = "FirstName", Value = "EmployeeID" } })
.Width(90)
.Add();
})
.ClientSideEvents(eve =>
{
eve.Load("onLoad");
})
)
Server side:-
public ActionResult GridFeatures()
{
BindDataSource();
var datasource = order.ToList();
ViewBag.datasource = datasource;
var DataSource1 = new NorthwindDataContext().EmployeeViews.ToList();
ViewBag.datasource2 = DataSource1;
ViewBag.foreignCol = new NorthwindDataContext().EmployeeViews.ToList();
return View();
} |
The call is ambiguous between the following methods or properties: 'Syncfusion.MVC.EJ.JavaScriptExtension.EJ<dynamic>(System.Web.Mvc.HtmlHelper<dynamic>)'and
'Syncfusion.MVC.EJ.JavaScriptExtension.EJ<dynamic>(System.Web.Mvc.HtmlHelper<dynamic>)'