1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| $(function () { var table;
function getParams() { return { 'q': $('#q').val(), }; }
function loadTable() {
if (table) { table.ajax.reload(null, true); return; } table = $('#my-table').DataTable({ 'serverSide': true, 'paging': true, 'rowReorder': { 'selector': 'tr', 'dataSrc': 'seq', }, 'columnDefs': [ { 'orderable': true, 'targets': 0, 'className': 'reorder' }, { 'orderable': false, 'targets': '_all' } ], 'columns': [ { 'data': 'seq' }, { 'data': 'col_1' }, { 'data': 'col_2' }, { 'data': 'col_3' }, ], 'ajax': { 'url': '/get-menu-data', 'type': 'GET', 'data': function (d) { Object.assign(d, getParams()); return d; }, }, });
table.on( 'row-reorder', function ( e, diff, edit ) { var postData = []; for ( var i = 0, ien = diff.length ; i < ien ; i++ ) { var rowData = table.row(diff[i].node).data(); postData.push({ 'id': rowData.id, 'new_seq': diff[i].newData, }); }
$.ajax({ url: '/update-menu-seq', dataType: 'json', type: 'post', async: false, data: { seqs: postData, }, success: function (data, textStatus, jqXHR) { }, error: function (jqXHR, textStatus, errorThrown) { alert(errorThrown); }, complete: function (jqXHR, textStatus) { } }); }); } loadTable(); });
|