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

Refresh dropdownlist's datasource in grid

3 Answers 1716 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 23 Aug 2018, 05:55 AM

Hello.

I have a dropdownlist for Contact Name in a kendo grid as shown in the attachment.

When I click on the Manage Contacts button, I get a pop up which has a grid where I insert contacts.

After inserting/updating contacts and closing the popup, the Contact Name dropdownlist should display the new contacts which have just been inserted when I click on Edit for that particular row.

But this not happening. 

The code for the Contact Name editor template is as follows:

@(Html.Kendo().DropDownList()
.Name("ContactName")
.ValuePrimitive(true)
.DataValueField("ContactName")
.DataTextField("ContactName")
.OptionLabel(" ")
.DataSource(source =>
{
    source.Read(read =>
    {
        read.Action("GetVendorContacts", "VendorCont")
        .Data("filterContactName");
    })
    .ServerFiltering(true);
})
    //.AutoBind(false)
    .CascadeFrom("Vendor")
)

Is there a way to refresh the dropdown list when I click on the Edit button on the row or when I click on the dropdown list to select contacts?

I have tried to refresh the dropdownlist using the BeforeEdit and Save events, but it did not work.

This is very urgent and any help will be greatly appreciated.

 

Thanks and Regards

 

3 Answers, 1 is accepted

Sort by
1
Veselin Tsvetanov
Telerik team
answered on 24 Aug 2018, 02:26 PM
Hi Daniel,

In case you are adding the new Contact items to the remote DropDownList source, then you should be able to force read the new data for that widget. To do that you could handle the edit event of the Grid:
function onEdit(e) {
  var container = e.container;
  var dropdown = container.find('[name="ContactName"]').getKendoDropDownList();
   
  dropdown.dataSource.read()
}

Regards,
Veselin Tsvetanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Daniel
Top achievements
Rank 1
answered on 28 Aug 2018, 02:25 PM

Hello Veselin.

Thanks a lot for helping out.

Unfortunately the onEdit event does not solve my issue.

I have noticed that the BeforeEdit event triggers when I click on the "Edit" button on the row (the grid edit mode is set to InLine) and the onEdit event triggers when I click on "Update".

Is there a way to access the dropdownlist in the BeforeEdit event?

I have also noticed that the dropdownlist refreshes when I add a new contact, then edit the row. But when I add a second contact, the dropdownlist does not refresh.

Do I need to set AutoBind(true) for the dropdownlist? Currently it has been set to false.

Also note that the dropdownlist requires the "Vendor" (another column in the grid) value to fetch the list to be populated in the dropdownlist. Is it because Vendor is not being changed that the dropdownlist is not refreshing? If this is correct, then how I can refresh the dropdownlist?

 

Thanks and Regards

 

0
Veselin Tsvetanov
Telerik team
answered on 30 Aug 2018, 01:25 PM
Hi Daniel,

Attached you will find a small MVC sample based on the described scenario. The Grid on the page is in InLine edit mode. Its Edit event handler is configured to force read on the DropDownList DataSource and is executed upon entering in edit mode.

May I ask you to modify the attached, so it reproduces the issue observed at your end and send it back to us? This way we will be able to troubleshoot the problem locally and to provide you with the most appropriate assistance on this case.

Regards,
Veselin Tsvetanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
DropDownList
Asked by
Daniel
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or