Jquery tableDnD - How to create an ajax with ID and position ondrop?
My code:
<script type="text/javascript">
$(document).ready(function() {
// Initialise the table
$('#admintabel').tableDnD({
onDrop: function(table, row) {
}
});
});
</script>
How do I create an ajax call to example /sort
with the parameters position and ID in a has like this: [position, ID]
onDrop? And how should my table be like.
Update:
I am trying to create an array like:
BREDBANDS[id] 1
BREDBANDS[id] 2
BREDBANDS[id] 3
My current test data:
data: {
BREDBANDS: [1, 2, 3] },
And it is posting this:
BREDBANDS[] 1
BREDBANDS[] 2
BREDBANDS[] 3
Which is giving a 500 error.
My Rails action which the data is posted to:
def sort
params[:bredbands].each_with开发者_如何学C_index do |id, index|
Bredband.update_all(['position=?', index+1], ['id=?', id])
end
render :nothing => true
end
It's hard to understand what you're actually asking but making an Ajax request should be done in any of these two ways:
$.ajax({
type: "GET",
url: "/sort?" + $.tableDnD.serialize(),
success: function(){
...
}
});
or
$.ajax({
type: "POST",
url: "/sort",
data: $("tr", "$admintabel").map(function(){
return this.id;
}),
success: function(){
...
}
});
But as it seems you need to provide IDs to your TR
elements. Then you should be able to call this:
$.tableDnD.serialize();
which will serialize data of the table and it's row IDs.
精彩评论