Grid foreign key column doesn't show DDL neither Validation message

2 Answers 79 Views
DropDownList Grid
Cristian
Top achievements
Rank 1
Iron
Cristian asked on 13 Sep 2022, 02:42 PM | edited on 13 Sep 2022, 02:47 PM

Dears

I'm facing this problem: in an MVC Grid, setted with InCell editing, I have a Foreign Key column. When I edit the FK cell the DDL is not showed.

I checked the documentation and for me it is all ok. 

Here some details:

[GRID DEFINITION]

        @(Html.Kendo().Grid<MCP310.Models.MCP_Detail>()
            .Name("Grid_MCP_Detail_" + Model.id)
            .ToolBar(toolbar =>
            {
                toolbar.Create();
                toolbar.Save();
            })
            .Columns(columns =>
            {
                columns.Bound(c => c.id).Hidden(true);
                columns.Command(command => command.Destroy().IconClass("k-icon k-i-delete").Text(" ")).Width(56).MinResizableWidth(56);
                columns.Bound(c => c.codiceInterno).Width(200).Sticky(true);
                columns.Group(g => g
                    .Title("A cura del personale Marketing o dei Service Specialist Supervisor")
                    .Columns(mkss =>
                    {
                        mkss.Bound(c => c.descrizione).Width(300);
                        mkss.ForeignKey(c => c.UMBase, ds => ds.Read(r => r.Action("unitaMisura", "MCPDetailGrid")), "idMSEHI", "descrMSEHL").Width(300);
                        //mkss.Bound(c => c.UMBase).Width(300);
                        mkss.Bound(c => c.gruppoMerci).Width(300);
                        mkss.Bound(c => c.lineaProdotto).Width(300);
                        mkss.Bound(c => c.codiceTipo).Width(300);
                        mkss.Bound(c => c.voceCE).Width(300);
                        mkss.Bound(c => c.codiceValore).Width(300);
                        mkss.Bound(c => c.gestLottiMatricola).Width(300);
                        mkss.Bound(c => c.codiceEDMA).Width(150);
                        mkss.Bound(c => c.nomeFornitore).Width(150);
                        mkss.Bound(c => c.codiceProdottoFornitore).Width(150);
                        mkss.Bound(c => c.codiceCategoriaFornitore).Width(150);
                        mkss.Bound(c => c.pezziConf).Width(150);
                        mkss.Bound(c => c.infiammabile).Width(150);
                        mkss.Bound(c => c.ghiaccioSecco).Width(150);
                        mkss.Bound(c => c.ggMinEntrata).Width(150);
                        mkss.Bound(c => c.ggMinUscita).Width(150);
                        mkss.Bound(c => c.UMVendita).Width(150);
                        mkss.Bound(c => c.rapportoUMBV).Width(150);
                        mkss.Bound(c => c.royalty).Width(150);
                    }));
                columns.Group(g => g
                    .Title("A cura del Controllo di Gestione")
                    .Columns(ctgs =>
                    {
                        ctgs.Bound(c => c.costoAcquisto).Title("Costo acquisto").Width(150);
                        ctgs.Bound(c => c.valutaFatturazione).Title("Valuta di fatturazione").Width(150);
                        ctgs.Bound(c => c.codValuta).Title("Cod. Valuta").Width(150);
                        ctgs.Bound(c => c.prezzoMinimo).Title("Prezzo Minimo").Width(150);
                        ctgs.Bound(c => c.percProvvMinima).Title("% Provv minima").Width(150);
                        ctgs.Bound(c => c.prezzoSuggerito).Title("Prezzo Suggerito").Width(150);
                    }));

                columns.Group(g => g
                    .Title("A cura del MKTG o dei SSS")
                    .Columns(mkss =>
                    {
                        mkss.Bound(c => c.costoAcquisto).Title("Costo acquisto").Width(150);
                        mkss.Bound(c => c.valutaFatturazione).Title("Valuta di fatturazione").Width(150);
                        mkss.Bound(c => c.codValuta).Title("Cod. Valuta").Width(150);
                        mkss.Bound(c => c.prezzoMinimo).Title("Prezzo Minimo").Width(150);
                        mkss.Bound(c => c.percProvvMinima).Title("% Provv minima").Width(150);
                        mkss.Bound(c => c.prezzoListino).Title("Prezzo Listino").Width(150);
                        mkss.Bound(c => c.percProvvMassima).Title("% Provv max").Width(150);
                    }));

                columns.Group(g => g
                    .Title("A cura di AAT")
                    .Columns(aat =>
                    {
                        aat.Bound(c => c.codiceWindSat).Title("Cod. Winsat").Width(150);
                    }));
                columns.Bound(c => c.idStato).Title("Stato").Width(150);
                })
            .Editable(editable => {
                editable.Mode(GridEditMode.InCell);
                editable.CreateAt(GridInsertRowPosition.Bottom);
            })
            .Sortable()
            .Scrollable()
            .Resizable(resizable => resizable.Columns(true))
            .Filterable()
            .DataSource(dataSource => dataSource
                .Ajax()
                .Batch(true)
                .ServerOperation(false)
                .Events(events => events.Error("error_handler"))
                .Model(model => model.Id(p => p.id))
                .Read(action => action.Action("Read", "MCPDetailGrid", new { idHeader = Model.id }))
                .Create(action => action.Action("Create", "MCPDetailGrid", new { idHeader = Model.id }))
                .Update(action => action.Action("Update", "MCPDetailGrid"))
                .Destroy(action => action.Action("Destroy", "MCPDetailGrid"))
            )
            .NoRecords("Nessun prodotto presente")
            .Navigatable()
        )}

 

[~/Views/Shared/EditorTemplates/GridForeignKey.cshtml]

@(
 Html.Kendo().DropDownListFor(m => m)
        .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
        .ValuePrimitive(true)
)

I tried with/without  ValuePrimitive and with/without @model object

 

[Models]

Where the data are used:

    [MetadataType(typeof(MCP_DetailMetaData))]
    public partial class MCP_Detail: IDisposable
    {
        private MCPEntities MCPDB = new MCPEntities();

        public class MCP_DetailMetaData
        {
            public int id { get; set; }

            public int idMCP { get; set; }
            
            [Required, MaxLength(10), DisplayName("Codice Interno")]
            public string codiceInterno { get; set; }

            [Required, MaxLength(40), DisplayName("Descrizione")]
            public string descrizione { get; set; }

            [Required, DisplayName("U.M. Base")]
            public string UMBase { get; set; }

            [Required, MaxLength(3), DisplayName("Gr. Merci")]

....

Where the data come from:

    public partial class MCP_Unita_Misura
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public MCP_Unita_Misura()
        {
            this.MCP_Detail = new HashSet<MCP_Detail>();
        }

        public string idMSEHI { get; set; }
        public string idMSEH3 { get; set; }
        public string idMSEH6 { get; set; }
        public string MSEHT { get; set; }
        public string descrMSEHL { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<MCP_Detail> MCP_Detail { get; set; }
    }

 

[Other]

The FK exists also in the DB and in the Model        

 

 

Thanks in advance

 

Cristian

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 16 Sep 2022, 07:47 AM

Hi Cristian,

 

Thank you for writing to us.

Can you try resolving this issue by replacing the ForeignKey column with Bound.ClientTemplate approach and let me know about the result?

https://www.telerik.com/forums/dropdownlist-in-kendogrid-cell-is-not-working-fine

 

Regards,
Eyup
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Cristian
Top achievements
Rank 1
Iron
answered on 20 Sep 2022, 12:42 PM

Hi Eyup

Thanks for your reply

I solved the problem in 2 different ways.

 

[1] in the declaration of the FK column I use a view data instead of call a method:

mkss.ForeignKey(c => c.UMBase, (System.Collections.IEnumerable)ViewData["uniMisura"], "codice", "descrizione").Width(250);

in this way the default client template (GridForeignKey.cshtml) works fine

 

[2] if i what to get the FK data calling a method I have to use explicitly a client template like this:

 

@model MCP310.Models.MCP_Unita_Misura
@(Html
    .Kendo()
    .DropDownListFor(m => m)
    .OptionLabel("Selezionare un valore....")
    .DataValueField("codice")
    .DataTextField("descrizione")
                .DataSource(source => source
                      .Custom()
                      .ServerFiltering(true)
                      .Transport(transport => transport
                        .Read(read =>
                        {
                            read.Action("unitaMisura", "MCPDetailGrid");//.Data("filterProducts");
                        }))
                )
    .ValuePrimitive(true))

 

For my case I choose solution [1] because I don't want to made unnecessary call to the database

 

BR


Cristian

Eyup
Telerik team
commented on 23 Sep 2022, 10:05 AM

Hi Cristian,

I am glad that you have managed to find a suitable solution for your case and thank you for sharing it with our community!

Tags
DropDownList Grid
Asked by
Cristian
Top achievements
Rank 1
Iron
Answers by
Eyup
Telerik team
Cristian
Top achievements
Rank 1
Iron
Share this question
or