ListView Drag and Drop
by OnaBai
HTML
<link rel="stylesheet" href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.default.min.css">
<script src="http://cdn.kendostatic.com/2013.2.716/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<script src="http://demos.kendoui.com/content/shared/js/products.js"></script>
<div class="demo-section">
<div id="listView"></div>
</div>
<script type="text/x-kendo-template" id="template">
<div class="product">
<img src="http://demos.kendoui.com/content/web/foods/#= ProductID #.jpg" alt="#: ProductName # image"/>
<h3>#:ProductName#</h3>
<p>#:kendo.toString(UnitPrice, "c")#</p>
</div>
</script>
CSS
.demo-section {
padding: 30px;
width: 577px;
}
#listView {
padding: 10px;
margin-bottom: -1px;
min-width: 555px;
min-height: 510px;
}
.product {
float: left;
position: relative;
width: 111px;
height: 170px;
margin: 0;
padding: 0;
}
.product img {
width: 110px;
height: 110px;
}
.product h3 {
margin: 0;
padding: 3px 5px 0 0;
max-width: 96px;
overflow: hidden;
line-height: 1.1em;
font-size: .9em;
font-weight: normal;
text-transform: uppercase;
color: #999;
}
.product p {
visibility: hidden;
}
.product:hover p {
visibility: visible;
position: absolute;
width: 110px;
height: 110px;
top: 0;
margin: 0;
padding: 0;
line-height: 110px;
vertical-align: middle;
text-align: center;
color: #fff;
background-color: rgba(0, 0, 0, 0.75);
transition: background .2s linear, color .2s linear;
-moz-transition: background .2s linear, color .2s linear;
-webkit-transition: background .2s linear, color .2s linear;
-o-transition: background .2s linear, color .2s linear;
}
.k-listview:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
JavaScript
var dataSource = new kendo.data.DataSource({
data : products,
pageSize: 10
});
$("#listView").kendoListView({
dataSource: dataSource,
template : kendo.template($("#template").html()),
dataBound : function () {
$(".product").kendoDraggable({
hint: function (element) {
return element.clone();
}
});
}
});
$("#listView").kendoDropTargetArea({
filter: ".product",
drop : function (e) {
var srcUid = e.draggable.element.data("uid");
var dstUid = e.dropTarget.data("uid");
var srcItem = dataSource.getByUid(srcUid);
var dstItem = dataSource.getByUid(dstUid);
// var srcIdx = dataSource.indexOf(srcItem);
var dstIdx = dataSource.indexOf(dstItem);
dataSource.remove(srcItem);
dataSource.insert(dstIdx, srcItem);
e.draggable.destroy();
}
});