This is a migrated thread and some comments may be shown as answers.

DropDownList InCell editing.

1 Answer 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 06 Jun 2017, 04:44 PM

Hi,

I have this error Uncaught ReferenceError: TypeMontant is not defined When i tried to display the editor Inline.

When clicking on Add new record, for the field TypeMontant, it's suppose to display a dropDownList, but this error appear.

I followd this tutorial : http://demos.telerik.com/aspnet-mvc/grid/editing-custom to achieved that

 

Here the view

@using EDC.NAVComptable.WebUi.Infrastructure.Configuration
@using EDC.NAVComptable.WebUi.Ressources
@using Kendo.Mvc.UI
@(Html.Kendo().Grid<EDC.NAVComptable.WebUi.ViewModel.Core.PosteComptableTypeMontantViewModel>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(e => e.PosteComptbCd).Width(110).Title(Layouts.PosteComptable).Filterable(filterable => filterable.UI("typeMontant").Multi(true));
            columns.Bound(e => e.TypeMontant).Width(110).Title(Layouts.TypeMontant).ClientTemplate("#=TypeMontant.RefrncCibleCd#");
            columns.Bound(e => e.DtDebutVersion).Width(110).Title(Layouts.DtDebutVersion).ClientTemplate("#= (DtDebutVersion == null) ? '' : kendo.toString(DtDebutVersion, 'yyyy-MM-dd') #");
            columns.Bound(e => e.DtFinVersion).Width(110).Title(Layouts.DtFinVersion).ClientTemplate("#= (DtFinVersion == null) ? '' : kendo.toString(DtFinVersion, 'yyyy-MM-dd') #");
            columns.Bound(e => e.DtsSupprm).Width(110).Title(Layouts.DtsSupprm).ClientTemplate("#= (DtsSupprm == null) ? '' : kendo.toString(DtsSupprm, 'yyyy-MM-dd') #");
            columns.Bound(e => e.IndVersionCournt).Width(110).Title(Layouts.IndVersionCournt);
            columns.Bound(e => e.LoadDts).Width(110).Title(Layouts.LoadDts).ClientTemplate("#= (LoadDts == null) ? '' : kendo.toString(LoadDts, 'yyyy-MM-dd') #");
            columns.Command(command => command.Destroy()).Title("Supprimer").Width(150);
        })
        .ToolBar(toolbar =>
        {
            toolbar.Save().SaveText("Sauvegarde").CancelText("Annuler");
            toolbar.Excel();
            toolbar.Create();
        })
        .Excel(excel => excel.FileName("PosteComptableTypeMontant.xlsx"))
        .Editable(editable => editable.Mode(GridEditMode.InCell))
        .Groupable()
        .Sortable()
        .Pageable()
        .Scrollable()
        .Filterable(filterable => filterable
        .Extra(false)
        .Operators(operators => operators
            .ForString(str => str.Clear()
                .StartsWith("Starts with")
                .IsEqualTo("Is equal to")
                .IsNotEqualTo("Is not equal to")
            ))
        )
        .HtmlAttributes(new { style = "height:600px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(WebConfigFile.PageSizeList)
            .Model(
                model =>
                {
                    model.Id(p => p.PosteComptbTypeMontantSqn);
                    model.Field(p => p.PosteComptbTypeMontantSqn).Editable(false);
                    model.Field(p => p.TypeMontant).DefaultValue(ViewData["TypeMontant"] as EDC.NAVComptable.WebUi.ViewModel.Core.TypeMontantViewModel);
                    model.Field(p => p.PosteComptbCd).DefaultValue(ViewData["PosteComptbCd"] as EDC.NAVComptable.Model.Core.PosteComptable);
                }
            )

            .Read(read => read.Action("PosteComptableTypeMontant", "Reference"))
            .Update("Editing_Update", "Grid")
            .Create(update => update.Action("EditingPopup_Create", "Reference"))
        )
)

 

here the Controller

 public ActionResult Index()
        {
            var dateComptable = _dateCalendrierRepository.GetdateComptable();
            InitDropDown();
            return View(new DateCalendrierViewModel {DtCalndr = dateComptable.DtCalndr});
        }

        public ActionResult TypeMontantDistinct()
        {
            return Json(_typeMontantRepository.GetDistinct().Select(e=>e.RefrncCibleCd), JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult EditingPopup_Create([DataSourceRequest] DataSourceRequest request, PosteComptableTypeMontant model)
        {
            if (model != null && ModelState.IsValid)
            {
                _referenceRepository.Save(model);
            }

            return Json(new[] { model }.ToDataSourceResult(request, ModelState));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult PosteComptableTypeMontant([DataSourceRequest] DataSourceRequest request)
        {
            var posteComptableTypeMontant = _referenceRepository.GetAll().Select( x=> new PosteComptableTypeMontantViewModel
            {
                TypeMontant = new TypeMontantViewModel { RefrncCibleCd = x.TypeMontant},
                PosteComptbCd = x.PosteComptbCd,
                DtDebutVersion = x.DtDebutVersion,
                PosteComptbTypeMontantSqn = x.PosteComptbTypeMontantSqn,
                DtFinVersion = x.DtFinVersion,
                DtsSupprm = x.DtsSupprm,
                LoadCycleId = x.LoadCycleId,
                IndVersionCournt = x.IndVersionCournt,
                LoadDts = x.LoadDts
            }).ToList();

            var nouveauPosteComptable = _posteComptableRepository.GetNew().Select(x => new PosteComptableTypeMontantViewModel
            {
                PosteComptbCd = x.PosteComptbCd,
            }).ToList();

            foreach (var posteComptable in nouveauPosteComptable)
            {
                posteComptableTypeMontant.Add(new PosteComptableTypeMontantViewModel
                {
                    PosteComptbCd = posteComptable.PosteComptbCd,
                });
            }

            return Json(posteComptableTypeMontant.OrderBy(x => x.TypeMontant.RefrncCibleCd).ToDataSourceResult(request));
        }

        private void InitDropDown()
        {
            var typeMontant = _typeMontantRepository.GetDistinct()
                .Select(element => new TypeMontantViewModel{ RefrncCibleCd= element.RefrncCibleCd})
                .ToList();

            //var posteComptable = _posteComptableRepository.GetDistinct()
            //    .Select(element => new PosteComptable { PosteComptbCd = element.PosteComptbCd })
            //    .ToList();

            //ViewData["PosteComptbCd"] = posteComptable;
            //ViewData["DefaultPosteComptbCd"] = posteComptable.First();
            ViewData["TypeMontant"] = typeMontant;
            ViewData["DefaultTypeMontant"] = typeMontant.First();

        }

 

Here the model

public class PosteComptableTypeMontantViewModel
    {
        public PosteComptableTypeMontantViewModel()
        {
            TypeMontant = new TypeMontantViewModel();    
        }

        public int PosteComptbTypeMontantSqn { get; set; }
        public string PosteComptbCd { get; set; }
        public TypeMontantViewModel TypeMontant { get; set; }

        [UIHint("Date")]
        public DateTime DtDebutVersion { get; set; }
        [UIHint("Date")]
        public DateTime? DtFinVersion { get; set; }
        [UIHint("Date")]
        public DateTime? DtsSupprm { get; set; }
        public bool IndVersionCournt { get; set; }
        [UIHint("Date")]
        public DateTime LoadDts { get; set; }
        public int LoadCycleId { get; set; }
    }

public class TypeMontantViewModel
    {
        public string RefrncCibleCd { get; set; }
    }

 

Thank for your help

Anthony

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 08 Jun 2017, 10:25 AM
Hello Anthony,

I see that you are setting a collection as DefaultValue for the TypeMontant field in the model of the DataSource. Could you please try to set the DefaultTypeMontant instead and see if the issue will persist:
model.Field(p => p.TypeMontant).DefaultValue(ViewData["DefaultTypeMontant"] as EDC.NAVComptable.WebUi.ViewModel.Core.TypeMontantViewModel);

Hope this helps.


Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Anthony
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or