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

Limiting the number of items allowed in a listview sortable

1 Answer 156 Views
Sortable
This is a migrated thread and some comments may be shown as answers.
Luke
Top achievements
Rank 1
Luke asked on 28 Nov 2014, 11:13 AM
Hi,

I have two listviews that are linked together as linked list sortables. The drag and drop functionality is working really well but I need to be able to limit the number of items in the second listview so that when a user tries to drag an item into the second listview it cancels the move event and displays a message. I can't find an example of this anywhere.

Thanks in advance,
Luke

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 02 Dec 2014, 09:15 AM
Hi Luke,

Thank you for contacting us.

In order to achieve this you may hook up to the beforeMove event and call the preventDefault method.
function beforeMove(e) {
  if (e.list.element.attr("id") === "sortable-left" && e.sender.items().length >= 4) { //if the items is greater than 4
    e.preventDefault(); //cancel the move action
    $("h4").text("Maximum number of items in the list is reached").css("color", "red"); //alert the user
  }
}

For your convenience I prepared a small example: http://dojo.telerik.com/@valchev/oseYa

I hope this information will help.

Regards,
Alexander Valchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Sortable
Asked by
Luke
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or