Select Listview item by text

1 Answer 58 Views
ListView
Katie
Top achievements
Rank 1
Katie asked on 11 Feb 2022, 04:34 PM
How do I select an item in my listview by the text displayed?

1 Answer, 1 is accepted

Sort by
0
Georgi Denchev
Telerik team
answered on 16 Feb 2022, 09:56 AM

Hi, Katie,

You can use the dataItems() method to retrieve all listView models. Then you can filter them by a particular field and select only the ones that match the criteria.

      	$("#select").on("click", function() {
          let listView = $("#listView").data("kendoListView");
          let products = ["Chai", "Ikura"];
          
          let items = listView.dataItems().filter(function(i) {
            return products.indexOf(i.ProductName) !== -1;
          });
          
          items.forEach(function(x) {
            let element = listView.element.find("[data-uid="+x.uid+"]");
            listView.select(element);
          });
        });

Dojo:

https://dojo.telerik.com/@gdenchev/eDAhaJUs 

Let me know if you have any questions.

Best Regards,
Georgi Denchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ListView
Asked by
Katie
Top achievements
Rank 1
Answers by
Georgi Denchev
Telerik team
Share this question
or