Mar 15, 2020, 4:11 PM
How to show table with foreigh key?
Hello! I have some problem with GridPanel.
Column Brigade in table Request is a foreigh key. How to show
I try to set
RequestsGrid.cshtml
Column Brigade in table Request is a foreigh key. How to show
m.Brigade.BrigadeName
in a grid? And also i want to change a value in a combobox.I try to set
.ColumnFor(Model, m => m.Brigade)
- this is shown nothing.ColumnFor(Model, m => m.Brigade.BrigadeID)
- this is shown id value.ColumnFor(Model, m => m.Brigade.BrigadeName)
- this is shown nothingRequestsGrid.cshtml
@using GeoSystem.Db.ViewModel;
@model IEnumerable<GeoSystem.Models.Request>
@(Html.X().Store()
.ID("BrigadeStore")
.Model(Html.X().Model()
.Fields(
new ModelField("id", ModelFieldType.Int) { Mapping = "BrigadeID" },
new ModelField("name", ModelFieldType.String) { Mapping = "BrigadeName" }
)
)
.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("GetBrigades"))
.Reader(Html.X().JsonReader().RootProperty("data"))
)
)
@(Html.X().GridPanel()
.ID("GridPanel1")
.Store(
Html.X().StoreForModel().ID("Store1")
)
.Icon(Icon.Table)
.Frame(true)
.Title("Бригады")
.Height(430)
.Width(500)
.StyleSpec("margin-top: 10px;")
.ColumnModel(
Html.X().ColumnFor(Model, m => m.RequestID)
.ToBuilder<Column.Builder>()
.Width(40)
.Renderer("return record.phantom ? '' : value;"),
Html.X().ColumnFor(Model, m => m.RequestName)
.ToBuilder<Column.Builder>()
.Flex(1)
.Editor(
Html.X().TextField().AllowBlank(false)
),
Html.X().ColumnFor(Model, m => m.Start)
.ToBuilder<Column.Builder>()
.Flex(1)
.Editor(
Html.X().TextField().AllowBlank(false)
),
Html.X().ColumnFor(Model, m => m.Brigade.BrigadeID)
.ToBuilder<Column.Builder>()
.Flex(1)
.Editor(
Html.X().ComboBox()
.QueryMode(DataLoadMode.Remote)
.TriggerAction(TriggerAction.All)
.StoreID("BrigadeStore")
.ValueField("id")
.DisplayField("name")
)
)
)
Controller [ChildActionOnly]
public ActionResult ShowAllRequests()
{
IEnumerable<Request> list = requestRepository.GetAll();
return PartialView("RequestsGrid", list);
}
public ActionResult GetBrigades()
{
return this.Store(brigadeRepository.GetAll());
}
Models public class Request
{
[Field(FieldType = typeof(Ext.Net.Hidden))]
public int RequestID { get; set; }
[Field(FieldType = typeof(Ext.Net.Hidden))]
public int BrigadeID { get; set; }
[Display(Name = "Ðазвание")]
public string RequestName { get; set; }
[Display(Name = "Комментарий")]
public string Comment { get; set; }
[Display(Name = "Дата начала")]
public DateTime Start { get; set; }
[Display(Name = "Дата окончаниÑ")]
public DateTime End { get; set; }
[Display(Name = "Закрыто")]
public bool IsDone { get; set; }
[UIHint("Brigade")]
public virtual Brigade Brigade { get; set; }
}
public class Brigade
{
[Field(FieldType = typeof(Ext.Net.Hidden))]
public int BrigadeID { get; set; }
[Required]
[Display(Name = "Ðазвание")]
public string BrigadeName { get; set; }
public virtual ICollection<Request> Requests { get; set; }
}