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

Selecting All Items with a button click function

8 Answers 422 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Safak
Top achievements
Rank 1
Safak asked on 09 Aug 2012, 02:52 AM
Hi,

Is there a way to select all items in the listview?

I am able to select a row with .select method:

ListView.select();


Thanks
Safak

8 Answers, 1 is accepted

Sort by
0
Accepted
John DeVight
Top achievements
Rank 1
answered on 09 Aug 2012, 05:56 PM
Hi Safak,

The .select function will take an array of items.  Here is an example of calling the .select function and passing in all the listview items in the listview dataBound event handler:

var _listView = $("#listView").kendoListView({
    dataSource: dataSource,
    selectable: "multiple",
    template: kendo.template($("#template").html()),
    dataBound: function(e) {
        _listView.select(_listView.element.children());
    }
}).data("kendoListView");

Attached is a working example.

Regards,

John DeVight
0
srinivas
Top achievements
Rank 1
answered on 10 Aug 2012, 06:53 AM
Hi John DeVight,


The post was useful.My question is how can i select multiple list views with out clicking ctrl button.
I want to use list view.select() method. can i able to select the list view based on the index or id of
the list view.Here i am getting the index and id on selecting the check box in the list view.
Then i want to select the multiple list views on selecting the check box in each list view 
Hope you will understand my question 




Thanks and Regards,
Srinivas
0
Safak
Top achievements
Rank 1
answered on 10 Aug 2012, 07:16 AM
Hi John,

Thank you very much for your answer. It worked well as you explained.




Hi Srinivas,

I'm using the below codes with databound trigger to select some items with a button click. I hope it will help...


I have #ID for DIV in template:
<script type="text/x-kendo-tmpl" id="template">
        <div class="product" id="${ProductID}">
            <img src="../../uploads/Products/56X84/${ImagePath}" alt="${Name} image" />
            <h3>${Name}</h3>
        </div>
    </script>

function onDataBound(arg) {
 
            var getListView = $("#listView").data("kendoListView");
                 
                    var Selected = $("#selecteditems").val();
                                     
                    lines = SelectedItems .split(/\n/);
                    lines = jQuery.unique(lines);
                    lines.sort();
 
                        for(var i in lines) {
                            row = $("#listView").find("#" + lines[i]).eq(0);
                            getListView.select(row);
                        }                
            }

Finally giving the product IDs in the textbox as HTML
<textarea id="selecteditems" name="selecteditems" class="k-textbox">
518080
518081
518082
</textarea>
0
srinivas
Top achievements
Rank 1
answered on 10 Aug 2012, 09:37 AM
Hi safak,


Thank you for the post.
Is there any method to select the list view using the index or id of the listview.
Like listview.select(1);



Thanks and Regards,
Srinivas
0
Safak
Top achievements
Rank 1
answered on 13 Aug 2012, 01:54 AM
Hi srinivas,

Yes, you can use ListView.select(row);

Use div #id in your div:

<div class="product" id="5">


Define the row that will be selected:
row = $("#listView").find("#5").eq(0);

Select the item:
ListView.select(row);

0
srinivas
Top achievements
Rank 1
answered on 14 Aug 2012, 12:24 PM
Hi safak,

Thank you very much safak.The code worked perfectly.
Now i am able to select the listview using index.




Regards,
Srinivas
0
Lee
Top achievements
Rank 1
Iron
Iron
Iron
answered on 08 May 2020, 05:25 PM
I have a connected list box and this doesn't work. Instead I get cannot read property 'select' of undefined at init.dataBound.
0
Alex Hajigeorgieva
Telerik team
answered on 13 May 2020, 11:20 AM

Hello, Lee,

This thread is for the ListView but if you wish to do the same for the ListBox - select all items on dataBound, you can use this snippet:

dataBound: function(e) {
  this.select(this.items());
}

https://dojo.telerik.com/@bubblemaster/OCuBeSiK/2

Regards,
Alex Hajigeorgieva
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
ListView
Asked by
Safak
Top achievements
Rank 1
Answers by
John DeVight
Top achievements
Rank 1
srinivas
Top achievements
Rank 1
Safak
Top achievements
Rank 1
Lee
Top achievements
Rank 1
Iron
Iron
Iron
Alex Hajigeorgieva
Telerik team
Share this question
or