We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Foreign key column

Thread ID:

Created:

Updated:

Platform:

Replies:

151368 Feb 8,2020 08:17 AM UTC Feb 10,2020 10:57 AM UTC ASP.NET MVC 2
loading
Tags: Grid
Bernard Jurlina
Asked On February 8, 2020 08:17 AM UTC

My foreign key columns are displaying the value from the datasource even there is null value in the datasource from the grid?



The index method of the controller gets the datasource for the dropdowns:

var djel = from d in db.AspNetUsers
                           where d.DjelatnikSuradnik == "D"
                           orderby d.Prezime, d.Ime
                           select new
                           {
                               d.Id,
                               PrezimeIme = d.Prezime + ", " + d.Ime
                           };
                var sur = from d in db.AspNetUsers
                           where d.DjelatnikSuradnik == "S"
                           orderby d.Prezime, d.Ime
                           select new
                           {
                               d.Id,
                               PrezimeIme = d.Prezime + ", " + d.Ime
                           };

ViewBag.dsDjelatnik = djel.ToList();
                ViewBag.dsSuradnik = sur.ToList();

And then the GetPlan methog is getting the data for the grid:

public JsonResult GetPlan (int Godina)
        {
            using (var db = new BilijonEntities())
            {
                var source = from pl in db.Plan
                             join k in db.OsigKuca on pl.OsigKucaID equals k.OsigKucaID
                             join p in db.Proizvod on pl.ProizvodID equals p.ProizvodID into p1
                             from p2 in p1.DefaultIfEmpty()
                             join g in db.ProizvodGrupa on pl.GrupaID equals g.GrupaID into g1
                             from g2 in g1.DefaultIfEmpty()
                             where pl.Godina == Godina
                             orderby k.Naziv, g2.Naziv, p2.Naziv
                             select new
                             {
                                 pl.PlanId,
                                 pl.Godina,
                                 pl.OsigKucaID,
                                 pl.ProizvodID,
                                 pl.GrupaID,
                                 pl.Iznos,
                                 pl.UserId,
                                 pl.UserIdPromjena,
                                 pl.DjelatId,
                                 pl.SuradId,
                                 pl.DjelatnikVlasnik,
                                 pl.AgencijaID,
                                 pl.LokacijaId,
                                 pl.BrojPolica
                             };

                return Json(source.ToList(), JsonRequestBehavior.AllowGet);
            }
        }

And this is the grid:

@(Html.EJ().Grid<object>("gridPlan")
        .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dsPlan)
                .UpdateURL("NormalUpdate")
                .InsertURL("NormalInsert")
                .RemoveURL("NormalDelete")
                .Adaptor(AdaptorType.RemoteSaveAdaptor))
        .AllowPaging()
        .AllowSelection(true)
        .AllowResizing()
        .AllowSorting(true)
        .AllowTextWrap(true)
        .Locale("hr-HR")
        .EditSettings(edit => { edit.AllowAdding().AllowDeleting().ShowDeleteConfirmDialog().AllowEditing(); })
        .AllowFiltering(true)
        .FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
        .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("PlanId").HeaderText("PlanId").IsPrimaryKey(true).IsIdentity(true).Visible(false).TextAlign(TextAlign.Right).Width(75).Add();
                col.Field("Godina").HeaderText("Godina").Visible(false).Width(55).Add();
                col.Field("OsigKucaID").HeaderText("Osig. kuća").ValidationRules(v => v.AddRule("required", true)).ForeignKeyField("OsigKucaID").ForeignKeyValue("Naziv").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>)ViewBag.dsKuce).Width(110).Add();
                col.Field("AgencijaID").HeaderText("Agencija").ForeignKeyField("AgencijaID").ForeignKeyValue("Naziv").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>)ViewBag.dsAgencija).Width(65).Add();
                col.Field("LokacijaId").HeaderText("Lokacija").ForeignKeyField("LokacijaId").ForeignKeyValue("Naziv").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>)ViewBag.dsLokacija).Width(80).Add();
                col.Field("GrupaID").HeaderText("Proizvod grupa").ForeignKeyField("GrupaID").ForeignKeyValue("Naziv").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>)ViewBag.dsGrupe).Width(60).Add();
                col.Field("ProizvodID").HeaderText("Proizvod").ForeignKeyField("ProizvodID").ForeignKeyValue("Naziv").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>)ViewBag.dsProizvodi).Width(80).Add();
                col.Field("DjelatId").HeaderText("Djelatnik").ForeignKeyField("DjelatId").ForeignKeyValue("PrezimeIme").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>)ViewBag.dsDjelatnik).Width(80).Add();
                col.Field("DjelatnikVlasnik").HeaderText("Djelatnik vlasnik").HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Center).DisplayAsCheckbox(true).DefaultValue(false).EditType(EditingType.BooleanEdit).Width("55px").Add();
                col.Field("SuradId").HeaderText("Suradnik").ForeignKeyField("SuradId").ForeignKeyValue("PrezimeIme").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>)ViewBag.dsSuradnik).Width(80).Add();
                col.Field("Iznos").HeaderText("Iznos").TextAlign(TextAlign.Right).Width("60px").Format("{0:N2}").Add();
                col.Field("BrojPolica").HeaderText("Broj").TextAlign(TextAlign.Right).Width("35px").Format("{0:N0}").Add();
                col.Field("UserId").HeaderText("UserId").Visible(false).Width(55).Add();
                col.Field("UserIdPromjena").HeaderText("UserIdPromjena").Visible(false).Width(55).Add();
            }).ClientSideEvents(ev => ev.ActionBegin("gridBegin").ActionComplete("gridComplete"))
)

Thanks!
Bernard.

Bernard Jurlina
Replied On February 8, 2020 08:27 AM UTC

Just to answer on my post, everything is working fine when I set the correct value in the ForeignKeyField for the columns.



B.

Padmavathy Kamalanathan [Syncfusion]
Replied On February 10, 2020 10:57 AM UTC

Hi Bernard, 

We  are happy to hear that your issue has been resolved. 

Please get back to us, if you need further assistance. 

Regards, 
Padmavathy Kamalanathan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon