【发布时间】:2019-06-14 06:31:47
【问题描述】:
我用过jquery dataTable,我有如下要求:
- 如果我拖动行 (
- BRAND NAME:....),那么它应该只在行之间拖动,并且包含所有内容。 - 如果我拖动行组的内容,则它不应与其他组重叠。
这是我到目前为止所做的:
HTML:
<table id="example">
<thead>
<tr>
<th>Name</th>
<th>type</th>
<th>age</th>
</tr>
</thead>
<tbody id="sortable">
<tr id="1">
<td>Name</td>
<td>Type1</td>
<td>Age</td>
</tr>
<tr id="2">
<td>Name</td>
<td>Type1</td>
<td>Age</td>
</tr>
<tr id="3">
<td>Name</td>
<td>Type2</td>
<td>Age</td>
</tr>
<tr id="4">
<td>Name</td>
<td>Type2</td>
<td>Age</td>
</tr>
</tbody>
</table>
jquery:
var table = $('#example').DataTable({
"searching": false,
"paging": false,
"info": false,
"order": [[0, "asc"]],
drawCallback: function (settings) {
var api = this.api();
var rows = api.rows({ page: 'current' }).nodes();
var last = null;
api.column(1, { page: 'current' }).data().each(function (group, i) {
if (last !== group) {
$(rows).eq(i).before(
'<tr class="groups"><td class="tdgroups" colspan="22" style="Cursor:hand !important;BACKGROUND-COLOR:rgb(237, 208, 0);font-weight:700;color:#006232;">' + '- BRAND NAME: ' + group + '</td></tr>'
);
last = group;
}
});
}
});
$("#sortable").sortable();
$("#sortable").disableSelection();
Jsfiddle 链接:DEMO
【问题讨论】:
-
你应该看看 jQuery-sortable 插件的
helper、start、update和stop函数/回调。 (见:jQuery Sortable - drag and drop multiple items -
但我的问题是,我有一个表结构,我认为这是不可能的。
标签: javascript jquery datatables jquery-ui-sortable