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

Kendo Grid inline dropdownlist shows ValueField during onChange instead of TextField

11 Answers 869 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ajith
Top achievements
Rank 1
ajith asked on 04 May 2015, 05:59 AM

I have a Kendo Grid with dropdownlist for inline Batch updte.When i change the Dropdown list thevalue changes and when it loses the focus , the value of the selected item is displayed in the grid instead of the TextField to be displayed in the grid's dropdownlist. I am using EditorTemplateName for displaying the dropdownlist in the grid.Can you please help me what is wrong and help me correct this issue. I have searched Telerik forum but still couldnt find any help.

 

 

EditorTemplate:
 
@using System.Collections
 
@(Html.Kendo().DropDownList()
    .BindTo((IEnumerable)ViewData["AllTitlesList"])
    .Name("MagTitle")
    .DataValueField("MagDescID")
    .DataTextField("MagTitle")
    .OptionLabel("- Select Title - ")
)
 

Kendo Grid Code: 

 
@(Html.Kendo().Grid<ARMS_WebApi.ViewModel.AncillaryCodes>()
      .Name("grid")
      .Columns(columns =>
      {
          columns.Bound(ac => ac.AncillaryCodeID).Width(75).Title("Id");
          //columns.Bound(ac => ac.MagDescID).Width(150).EditorTemplateName("MagazineTitleTemplate").Title("Title").ClientTemplate("#:MagTitle#");
       
          columns.ForeignKey(ac => ac.MagTitle, (IEnumerable)ViewData["AllTitlesList"], "MagDescID", "MagTitle").ClientTemplate("#:MagTitle#").
             EditorTemplateName("_AllTitlesKendoComboBoxTemplate").Title("Title").Width(100);
          columns.Bound(ac => ac.AncillaryCode).Width(75).Title("Ancillary Code");
          columns.Bound(ac => ac.AncillaryCodeDescription).Width(150).Title("Ancillary Code Description");
          columns.Command(commands =>
          {
              commands.Destroy();
          }).Width(50);
      })
      .ToolBar(toolbar =>
      {
          toolbar.Create();
          toolbar.Save();
          toolbar.Custom().Text("Delete selection")
                   .HtmlAttributes(new { onclick = "deleteSelection(event)" });
      })
              .Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Top))
                  .Pageable()
                            .Sortable()
                            .Scrollable(scr => scr.Height(300))
                     .Filterable(
                     filterable => filterable
                  .Extra(false)
                   .Operators(operators => operators
                    .ForString(str => str.Clear()
                    .StartsWith("Starts with")
                    .IsEqualTo("Is equal to")
                  .IsNotEqualTo("Is not equal to")
                  .Contains("Contains")
         )))
            .Resizable(resize => resize.Columns(true))
            .Reorderable(reorder => reorder.Columns(true))
              .DataSource(dataSource =>
          dataSource.Ajax()
            .Batch(true)
            .Model(model =>
            {
                model.Id(ac => ac.AncillaryCodeID);
                model.Field(ac => ac.AncillaryCodeID).Editable(false);
            })
                     .Create(create => create.Action("AncillaryCode_Create", "AncillaryCode"))
                     .Read(read => read.Action("AncillaryCode_Read", "AncillaryCode"))
                     .Update(update => update.Action("AncillaryCode_Update", "AncillaryCode"))
                     .Destroy(destroy => destroy.Action("AncillaryCode_Destroy", "AncillaryCode"))
      ))

 

 

 

    

I have a Kendo Grid with dropdownlist for inline Batch updte.When i change the Dropdown list thevalue changes and when it loses the focus , the value of the selected item is displayed in the grid instead of the TextField to be displayed in the grid's dropdownlist. I am using EditorTemplateName for displaying the dropdownlist in the grid.

Can you please help me what is wrong and help me correct this issue. I have searched Telerik forum but still couldnt find any help.

I have a Kendo Grid with dropdownlist for inline Batch updte.When i change the Dropdown list thevalue changes and when it loses the focus , the value of the selected item is displayed in the grid instead of the TextField to be displayed in the grid's dropdownlist. I am using EditorTemplateName for displaying the dropdownlist in the grid.

Can you please help me what is wrong and help me correct this issue. I have searched Telerik forum but still couldnt find any help.

11 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 05 May 2015, 03:50 PM

Hello Ajith,

In this case I would suggest setting the DropDownList (editor template) DataValueField to "MagTitle" just like the DataTextField. 

Also you can use the @(Html.Kendo().DropDownListFor() instead of @(Html.Kendo().DropDownList(). This way it will generate automatically the drop down list element id value to the model property you are binding the drop down list to. 

 

Regards,
Boyan Dimitrov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
ajith
Top achievements
Rank 1
answered on 07 May 2015, 02:21 AM

Hi Boyan,

i changed the EditorTemplate as follows by setting boththe value and text field as MagTitle. But this is showing incorrect id when saving during update. Does this mean i can update only using the MagTitle as where condition during update since i am not getting the Actual id of the changed data in the dropdown list  ?? . I am getting the previous Id of the selected item .  

 

 

0
ajith
Top achievements
Rank 1
answered on 07 May 2015, 02:23 AM

Hi Boyan,i changed the EditorTemplate as follows by setting boththe value and text field as MagTitle. But this is showing incorrect id when saving during update. Does this mean i can update only using the MagTitle as where condition during update since i am not getting the Actual id of the changed data in the dropdown list  ?? . I am getting the previous Id of the selected item .       

    .DataValueField("MagTitle")
    .DataTextField("MagTitle")

 When updating i am getting he newly selected TextField but the value field which had the MagId is showing old id. How to resolve this. 

0
Boyan Dimitrov
Telerik team
answered on 08 May 2015, 04:02 PM

Hello Ajith,

Please find attached a sample project that implements foreign key column scenario. Please let us know if you need any further assistance. 

Regards,
Boyan Dimitrov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
ajith
Top achievements
Rank 1
answered on 10 May 2015, 10:08 AM

Hi,

 

Thanks for the sample. I found out what my mistake was. I added the Editor Templates in my Shared folder. That di the trick. But however, i have another issue now.

In my Kendo grid, when i click on add new button, a new row comes on top of the grid.This new row has dropdown ad the first column and two text box columns. for the new row,when i select something from the dropdown and click on the next textbox(the next column) the first column with the dropdown becomes blank without anything. If i click onthe cell, the dropdown appears. but however, if a choose anything from the dropdown the cell is empty. what is the issue.

It would be great if you can share any sample with this bulk edit along with foreighnkey dropdown columns  along with ass new row as well as bulk delete option with kendo grid in mvc.

 

 

Regards,

Ajith

0
ajith
Top achievements
Rank 1
answered on 10 May 2015, 10:09 AM
Hi,
 
Thanks for the sample. I found out what my mistake was. I added the
Editor Templates in my Shared folder. That did the trick. But however, i
have another issue now.
In my Kendo grid, when i click on add new button, a new row comes on
top of the grid.This new row has dropdown ad the first column and two
text box columns. for the new row,when i select something from the
dropdown and click on the next textbox(the next column) the first column
with the dropdown becomes blank without anything. If i click onthe
cell, the dropdown appears. but however, if a choose anything from the
dropdown the cell is empty. what is the issue.
It would be great if you can share any sample with this bulk edit
along with foreighnkey dropdown columns  along with ad new row as well
as bulk delete option with kendo grid in mvc.
 
 
Regards,
Ajith
0
Boyan Dimitrov
Telerik team
answered on 12 May 2015, 03:34 PM

Hello Ajith,

I am glad to hear that you have resolved the problem. 

The project from my last response demonstrates how to implement foreign key column scenario. The create (add new item) functionality works fine. Please note that the foreign key columns is "EmployeeID". 

Regards,
Boyan Dimitrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Harish
Top achievements
Rank 1
answered on 15 May 2015, 01:46 AM

Hello Ajith,

Just wondering if you have got solution for your issue. I am also running into same problem, can you please respond if you have got solution for that. 

Issue: 

I found out what my mistake was. I added the Editor Templates in my Shared folder. That di the trick. But however, i have another issue now.In my Kendo grid, when i click on add new button, a new row comes on top of the grid.This new row has dropdown ad the first column and two text box columns. for the new row,when i select something from the dropdown and click on the next textbox(the next column) the first column with the dropdown becomes blank without anything. If i click onthe cell, the dropdown appears. but however, if a choose anything from the dropdown the cell is empty. what is the issue.

 

0
Boyan Dimitrov
Telerik team
answered on 18 May 2015, 10:50 AM

Hello Harish,

Since I am not able to replicate the described problem I would suggest you to open a support ticket and attach isolated runnable example. This way we can investigate the case in detail and provide a proper solution. 

Regards,
Boyan Dimitrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
ajith
Top achievements
Rank 1
answered on 19 May 2015, 03:03 AM

Hello Harish,

 

I have posted my code below. Hope this helps you. Let me know if you need anything else. Currently it is working for me.

 

@(Html.Kendo().Grid<ARMS_WebApi.ViewModel.AncillaryCodes>()
              .Name("EditAncillaryCodesGrid")
      .Columns(columns =>
      {
          columns.Template(x => { }).ClientTemplate("<input type='checkbox' id='chkSelect_#= AncillaryCodeID#' userId='#= AncillaryCodeID#' />").Width(20);
          columns.Bound(ac => ac.AncillaryCodeID).Hidden(true);
          columns.ForeignKey(ac => ac.MagDescID, (IEnumerable)ViewData["AllTitlesList"], "MagDescID", "MagTitle").Width(100);          
          columns.Bound(ac => ac.AncillaryCode).Width(75).Title("Ancillary Code");
          columns.Bound(ac => ac.AncillaryCodeDescription).Width(150).Title("Ancillary Code Description");
          columns.Command(commands =>
          {
              commands.Destroy();
          }).Width(50);
      })
      .ToolBar(toolbar =>
      {
          toolbar.Create();
          toolbar.Save();
          toolbar.Excel();
          toolbar.Custom().Text("Delete selection")
                   .HtmlAttributes(new { onclick = "deleteSelection(event)" });
      })
              .Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Top))
                  .Pageable()
                            .Sortable()
                            .Scrollable(scr => scr.Height(300))
                     .Filterable(
                     filterable => filterable
                  .Extra(false)
                   .Operators(operators => operators
                    .ForString(str => str.Clear()
                    .StartsWith("Starts with")
                    .IsEqualTo("Is equal to")
                  .IsNotEqualTo("Is not equal to")
                  .Contains("Contains")
         )))
            .Resizable(resize => resize.Columns(true))
            .Reorderable(reorder => reorder.Columns(true))
              .DataSource(dataSource =>
          dataSource.Ajax()
            .Batch(true)
            .Model(model =>
            {
                model.Id(ac => ac.AncillaryCodeID);
                model.Field(ac => ac.AncillaryCodeID).Editable(false);
                model.Field(ac => ac.MagDescID).DefaultValue(0);
            })
                     .Create(create => create.Action("AncillaryCode_Create", "AncillaryCode"))
                     .Read(read => read.Action("AncillaryCode_Read", "AncillaryCode"))
                     .Update(update => update.Action("AncillaryCode_Update", "AncillaryCode"))
                     .Destroy(destroy => destroy.Action("AncillaryCode_Destroy", "AncillaryCode"))
      ))

 

 

This is the code for my kendo grid. 

In my editor template i have this partial view GridForeignKey.cshtml

I copied the EditorTemplates from the sample projectshared by Boyan. I just added the  "Please Select" line in the editor template.

 

@model object
           
@(
 Html.Kendo().DropDownListFor(m => m)
     .OptionLabel(" - Please Select -")  
        .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
)

 

0
Harish
Top achievements
Rank 1
answered on 25 May 2015, 11:49 PM
Thanks for update Ajith. I figured out the issue by comparing my code with yours. I appreciate your time!
Tags
Grid
Asked by
ajith
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
ajith
Top achievements
Rank 1
Harish
Top achievements
Rank 1
Share this question
or