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

ListView multiple select without control key pressed?

10 Answers 804 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Joon
Top achievements
Rank 1
Joon asked on 27 Aug 2012, 06:21 AM
Hi,
Would it be possible to select multiple selection without the control key pressed? This will be useful on touch based screens such as tablets and smart phones. Any suggestions? Thanks.

10 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 27 Aug 2012, 09:48 AM
Hi Joon,

If the described behavior takes place, the user will be never able to deselect an item.

You can try adding some additional way to select on touch devices, e.g. by including checkboxes inside the items.

All the best,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Joon
Top achievements
Rank 1
answered on 29 Aug 2012, 04:42 AM
Thanks Dimo,
I understand what you mean and I thought clicking the item again to de-select would be ok for the mouse clicks. Anyways, good to know that it's not implmented by design. I will use the checkboxes as you suggested.

Cheers,

Joon Choi
0
John
Top achievements
Rank 1
answered on 25 Sep 2012, 09:50 PM
I have the same issue - would like to be able to use multi-select by simply clicking/touching each item to toggle.

Does anybody have some example code of how to implement this "add a checkbox" idea?

Seems messy to me though, I would like to see the ListView be able to support this in the future especially for when used on a Tablet with touch.
0
xu
Top achievements
Rank 1
answered on 08 Oct 2012, 08:11 AM
I have the same issue!
0
Bill
Top achievements
Rank 1
answered on 26 Oct 2012, 06:07 PM
We need it too.

If a user has a large list of selections and they forget to hold Ctrl, they will destroy their selection list.

This is effectively a beautiful checkbox mechanism.  We need it.
0
victorantos
Top achievements
Rank 2
answered on 10 Nov 2012, 08:15 PM
is it possible to select again the previous selected ones on the following event?

 function onChange(e) {
       
        var data = dataSource.view(),
            newSelected = $.map(this.select(), function (item) {
                return data[$(item).index()];
            });

}
0
Jonathan
Top achievements
Rank 1
answered on 30 Mar 2021, 03:57 AM

I came across this issue, and came up with the following solution, after searching and not finding a solution.  This allows for multiple selection and deselect without the control key.  Hope it helps someone.

var listView = $("#listView").data("kendoListView");
listView.on("click", ".listview-item", function (e) {
var selected = listView.select();
var isSelected = false;
for (i = 0; i < selected.length; i++) {
if ($(selected[i]).attr("id") == $(e.target).attr("id")) {
isSelected = true;
selected.splice(i, 1);
}
}
if (isSelected == false) {
selected.push(e.target);
}
setTimeout(function () {
listView.clearSelection();
listView.select(selected);
}, 1);
});

or for listbox:

var listBox = $("#ListBox").data("kendoListBox");
        listBox.wrapper.find(".k-list").on("click", ".k-item", function (e) {
            var selected = listBox.select();
            var isSelected = false;
            for (i = 0; i < selected.length; i++) {
                if ($(selected[i]).attr("id") == $(e.target).attr("id")) {
                    isSelected = true;
                    selected.splice(i, 1);
                }
            }
            if (isSelected == false) {
                selected.push(e.target);
            }
            setTimeout(function () {
                listBox.clearSelection();
                listBox.select(selected);
            }, 1);
        });

0
Anton Mironov
Telerik team
answered on 01 Apr 2021, 12:35 PM

Hi Jonathan,

Thank you for sharing your approach and code implementation with the community.

If assistance for anything else is needed, do not hesitate to contact me and the team.

 

Kind Regards,
Anton Mironov
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.

0
Jonathan
Top achievements
Rank 1
answered on 17 Apr 2021, 03:51 AM

My previous solution was a little unreliable, so I edited it a bit and came up with this, which is working very well:

var listBox = $("#SelectMultipleListBox").data("kendoListBox");
        listBox.dataSource.read();
        listBox.wrapper.find(".k-list").on("click", ".k-item", function (e) {
            if ($(e.target).closest(".k-item").hasClass("was-selected")) {
                $(e.target).closest(".k-item").removeClass("was-selected");
            } else {
                $(e.target).closest(".k-item").addClass("was-selected");
            }
            var items = listBox.wrapper.find(".k-list").find(".k-item");
            var selected = [];
            for (i = 0; i < items.length; i++) {
                if ($(items[i]).hasClass("was-selected")) {
                    selected.push(items[i]);
                }
            }
            setTimeout(function () {
                listBox.clearSelection();
                listBox.select(selected);
            }, 50);
        });

0
Anton Mironov
Telerik team
answered on 21 Apr 2021, 10:51 AM

Hi Jonathan,

Thank you for the new code snippet.

If assistance for anything else is needed, do not hesitate to contact me and the team.

Best Regards,
Anton Mironov
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/.

Tags
ListView
Asked by
Joon
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Joon
Top achievements
Rank 1
John
Top achievements
Rank 1
xu
Top achievements
Rank 1
Bill
Top achievements
Rank 1
victorantos
Top achievements
Rank 2
Jonathan
Top achievements
Rank 1
Anton Mironov
Telerik team
Share this question
or