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

Refresh dropdownlist's datasource in grid

3 Answers 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 23 Aug 2018, 06:11 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
0
Georgi
Telerik team
answered on 24 Aug 2018, 02:04 PM
Hello Daniel,

Generally speaking, each time a row enters edit mode a new Editable widget is initialized which means that new drop down editor is created. In other words by default each time a row is edited the drop down should request the server for data.

Could you please make sure that the data is available on the server?

Having said that, sharing a demo that clearly replicates the issue would definitely help us fully understand the case and we will be able to provide further assistance to the best of our knowledge.
 

Regards,
Georgi
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:26 PM

Hello Georgi.

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
Georgi
Telerik team
answered on 30 Aug 2018, 07:10 AM
Hello Daniel,

The Edit event fired when the user edits or creates a data item - not when saving. Please make sure you are attaching the handler to the correct event. Furthermore, the BeforeEdit event fires when the user try to edit or create a data item, before the editor is created. In other words, you can access the drop down in the Edit event handler as when BeforeEdit is triggered the editor is not yet  created.

Setting the AutoBind to false of the drop down means that it will not request the remote service after the initialization for data but after the user opens it. However, as in your case cascading drop downs are used, the Autobind should be false as it is necessary to first select the Vendor and depending on the selection send additional parameters to the read request of the ContactName drop down.

Finally you could refresh the drop down via the API of its DataSource - read method.


Regards,
Georgi
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
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or