Created
April 17, 2014 14:43
-
-
Save trailmax/10988824 to your computer and use it in GitHub Desktop.
Kendo Sortable submit to server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
var sortableList = $('.sortable-list').kendoSortable({ | |
hint: function(element){ | |
return element.clone().addClass('sortable-list-hint'); | |
}, | |
cursor: "n-resize" | |
}); | |
$('#sortable-submit').on('click', function (e) { | |
e.preventDefault(); | |
var items = sortableList.data('kendoSortable').items(); | |
var data = $.map(items, function (item, index) { | |
var id = $(item).data('id'); | |
return { | |
'Id': id, | |
'ListOrder': index | |
}; | |
}); | |
var dataToBeSubmitted = JSON.stringify(data); | |
$.ajax({ | |
url: $('.sortable-list').data('submit-url'), | |
type: 'POST', | |
data: dataToBeSubmitted, | |
dataType: "json", | |
contentType: "application/json; charset=utf-8", | |
error: function () { | |
alert("There is a communication error with updating"); | |
}, | |
success: function (result) { | |
if (result.Success) { | |
window.location = $('.sortable-list').data('success-url'); | |
} | |
} | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="sortable-list" data-submit-url="/items/listOrder" data-success-url="/items/index"> | |
@foreach (var item in Model) | |
{ | |
<li data-id="@item.Id"> | |
<span class="glyphicon glyphicon-resize-vertical"></span> | |
@item.Name | |
</li> | |
} | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment