Disable Combobox after empty dataquery

2 posts, 1 answers
  1. Christian
    Christian avatar
    31 posts
    Member since:
    Jul 2014

    Posted 16 Aug 2014 Link to this post

    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
  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 18 Aug 2014 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
Back to Top