Created
June 27, 2013 14:38
-
-
Save venblee/5876954 to your computer and use it in GitHub Desktop.
Re-Order Tables
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
<h1>Sorting A Table With jQuery UI</h1> | |
<a href='http://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/'>Make table rows sortable with jQuery UI</a> | |
<table id="sort" class="grid" title="Kurt Vonnegut novels"> | |
<thead> | |
<tr><th class="index">No.</th><th>Year</th><th>Title</th><th>Grade</th></tr> | |
</thead> | |
<tbody> | |
<tr><td class="index">1</td><td>1969</td><td>Slaughterhouse-Five</td><td>A+</td></tr> | |
<tr><td class="index">2</td><td>1952</td><td>Player Piano</td><td>B</td></tr> | |
<tr><td class="index">3</td><td>1963</td><td>Cat's Cradle</td><td>A+</td></tr> | |
<tr><td class="index">4</td><td>1973</td><td>Breakfast of Champions</td><td>C</td></tr> | |
<tr><td class="index">5</td><td>1965</td><td>God Bless You, Mr. Rosewater</td><td>A</td></tr> | |
</tbody> | |
</table> |
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
// Java Script | |
var fixHelperModified = function(e, tr) { | |
var $originals = tr.children(); | |
var $helper = tr.clone(); | |
$helper.children().each(function(index) { | |
$(this).width($originals.eq(index).width()) | |
}); | |
return $helper; | |
}, | |
updateIndex = function(e, ui) { | |
$('td.index', ui.item.parent()).each(function (i) { | |
$(this).html(i + 1); | |
}); | |
}; | |
$("#sort tbody").sortable({ | |
helper: fixHelperModified, | |
stop: updateIndex | |
}).disableSelection(); |
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
// SAve Click | |
var array = [] ; | |
$('#sort').has('td').each(function() { | |
arrayItem ={} ; | |
var arrayItem = {} : // New Object | |
$('td'.$(this)).each(function (index,item){ | |
arrayItem[$(item).attr('id').toString()] = $.trim($(item).text()); | |
}); | |
array.push(arrayitem); | |
}); | |
var b = JSON.stringify ({cart : array}) | |
$.ajax ({ | |
url: @Url.Action() , | |
type: 'POST' , | |
dataType : 'json' , | |
contentType : 'application/json; charset=utf-8' , | |
data: p , | |
success : function(data){ | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
at line no 29, data: p
shouldn't it be data: b ?