如何使用 jQuery 创建 sortable table 行
How to create sortable table rows using jQuery
我正在尝试使用 jQuery 创建 .sortable
table。 fixWidthHelper
class 保留 table 列宽。 (我删除了一些 HTML)
Table HTML:
<table class = "table table-bordered" >
hr content here...
<tbody id = "field_wrapper">
<tr>
<td id = "move">...</td>
<td id = "move">...</td>
</tbody>
</table>
jQuery:
$(function (sort) {
sortable_tables.sorting_field_table();
});
var sortable_tables =
{
sorting_field_table: function(sort)
{
$('#field_wrapper').sortable({
placeholder: "drop",
helper: sortable_tables.fixWidthHelper
}).disableSelection();
}
fixWidthHelper: function(e, ui) {
ui.children().each(function(sort) {
$(this).width($(this).width());
});
return ui;
}
});
CSS:
#move{ margin-left: 0px; padding-right:10px; cursor: move;}
.drop {
outline: thin dashed #CCC !important;
background-color:#CCC;
width:100%;
}
您的代码的第一块只是在 document.ready
上定义了一个函数,但没有在任何地方调用它。
此外,我在这里没有看到任何实际执行任何排序的内容。
我成功了!
jQuery:
$(function() {
$( "#field_wrapper" ).sortable({
placeholder: "drop"
});
$( "#field_wrapper" ).disableSelection();
});
我正在尝试使用 jQuery 创建 .sortable
table。 fixWidthHelper
class 保留 table 列宽。 (我删除了一些 HTML)
Table HTML:
<table class = "table table-bordered" >
hr content here...
<tbody id = "field_wrapper">
<tr>
<td id = "move">...</td>
<td id = "move">...</td>
</tbody>
</table>
jQuery:
$(function (sort) {
sortable_tables.sorting_field_table();
});
var sortable_tables =
{
sorting_field_table: function(sort)
{
$('#field_wrapper').sortable({
placeholder: "drop",
helper: sortable_tables.fixWidthHelper
}).disableSelection();
}
fixWidthHelper: function(e, ui) {
ui.children().each(function(sort) {
$(this).width($(this).width());
});
return ui;
}
});
CSS:
#move{ margin-left: 0px; padding-right:10px; cursor: move;}
.drop {
outline: thin dashed #CCC !important;
background-color:#CCC;
width:100%;
}
您的代码的第一块只是在 document.ready
上定义了一个函数,但没有在任何地方调用它。
此外,我在这里没有看到任何实际执行任何排序的内容。
我成功了!
jQuery:
$(function() {
$( "#field_wrapper" ).sortable({
placeholder: "drop"
});
$( "#field_wrapper" ).disableSelection();
});