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

No Results Found Text when Result Set is Empty

1 Answer 121 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 12 Jun 2014, 02:55 AM
I am looking for functionality like the Multiselect below: US State Select -> type x = 'No Results found for x'

http://harvesthq.github.io/chosen/ 

I have built a work around providing data from the back end and on select if the id is 'noresults' I set the value of the click to forget about the selection. However I find it hard to believe that there is no option for this as it seems to be a common use case. Is there a better way to handle this than I described as my work around? I am using the MVC Helpers for the majority of this code.

Thanks in advance,

- Josh

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 13 Jun 2014, 03:21 PM
Hello Josh,

I am afraid that this scenario is currently not supported out of the box. I would recommend using the following approach as a workaround:
  1. Subscribe to the RequestEnd event of the MultiSelect's DataSource
  2. Once the event is triggered check whether there are any items in the response argument
  3. If there are not any, then add one, with the desired message in the text field. For example: 
    function onRequestEnd(e) {
        var ms = $("#products").getKendoMultiSelect();
        if (!e.response.length) {
            e.response.push({ ProductName : "No results", ProductID : 0 });
        }
    }
  4. Subscribe to the Change event of the MultiSelect and check whether the selected item text matches the "No results" one
  5. If it does, call the event's preventDefault method: 
    function onSelect(e) {
        if (e.item.text() == "No results") {
            e.preventDefault();
        }
    }


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
MultiSelect
Asked by
Joshua
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or