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

Disable Combobox after empty dataquery

4 Answers 216 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 16 Aug 2014, 11:54 AM
Hi there,

I have 2 cascading comboboxes in my form: CompanyId --> TaskId

When I select a company and there are no tasks linked to it the TaskId combobox should become disabled.
Just like it becomes disabled when I clear the CompanyId combobox.

This is what I do in the controller action:
       
01.public JsonResult Autocomplete(string query, int companyId) {
02.           var ret = Dao.Task.GetMany(i => i.CompanyId == companyId);
03. 
04.           if (!string.IsNullOrEmpty(query)) {
05.               query = query.ToLower();
06.               ret = ret.Where(i => i.Subject.ToLower().Contains(query));
07.           }
08. 
09.           var res = ret.Select(i => new {
10.               id = i.Id,
11.               name = i.Subject
12.           });
13. 
14.           return Json(res, JsonRequestBehavior.AllowGet);
15. 
16.       }


How can I do that?

many thanks,
Chris

4 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 18 Aug 2014, 04:18 PM
Hello Chris,

I would suggest you wire the dataBound event of the widget using DataBound fluent method. Then in the dataBound event handler you can disable the widget if the data source component is empty:
function dataBound(e) {
    var widget = e.sender;
 
    if (widget.dataSource.view().length === 0) {
        widget.enable(false);
    }
}

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ingerid
Top achievements
Rank 1
Veteran
answered on 16 Sep 2020, 08:19 AM

Hello,

I know this question is a really long one, but I'm having the same problem, and your solution doesn't work properly. It does indeed disable the combobox when no data is found, but it also disables it when I cross out the selected option. Do you have a suggestion for how I can fix this?

0
Martin
Telerik team
answered on 18 Sep 2020, 07:02 AM

Hello Ingerid,

Could you please share a Dojo example where I can observe the issue you are experiencing? I will test it and find an appropriate solution.

Looking forward to your reply.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Ingerid
Top achievements
Rank 1
Veteran
answered on 21 Sep 2020, 12:09 PM
Thanks, but I figured it out. I thought the databound event was called immediately after data was loaded, but it seems like the data is filtered first. In my code, filtering would trigger a call to a function that would reset the datasource, so no wonder it didn't work for me. Weirdly enough, I couldn't find a way to get the datasource before filtering, but I worked my way around it.
Tags
ComboBox
Asked by
Christian
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Ingerid
Top achievements
Rank 1
Veteran
Martin
Telerik team
Share this question
or