// api 地址 http://www.datatables.club/reference/api/
var table;
table = SixDataTableNoPaging("tbList", "/Sys_EntryLibraryRecord/GetListForDeliveryDetails?DeliveryOrderId=@Model.Id" + "&DeliveryOrderType=@((int)DevliveryType.PostalCar)" , columns, {}, function (samid) {
});
//获取列表选择集合
function SixGetDataChecked(table) {
var SamNodes = [];
var check = table.rows('.selected').data();
for (var i = 0; i < check.length; i++) {
SamNodes.push(check[i]);
}
return SamNodes;
}
//获取列表所有数据
function SixGetData(table) {
var SamNodes = [];
var check = table.rows().data();
for (var i = 0; i < check.length; i++) {
SamNodes.push(check[i]);
}
return SamNodes;
}
//置顶
function Top() {
//获取选中的行
var node = SixGetDataChecked(table);
if (node.length != 1) {
layer.msg("请选择一行!");
return false;
}
//选中的行对象
var select_row = node[0];
//所有数据对象
var data = SixGetData(table);
var new_data = [];
new_data.push(select_row);
for (var i = 0; i < data.length; i++) {
if (select_row.Id == data[i].Id) {
continue;
}
new_data.push(data[i]);
}
//清空表格
table.clear();
//添加新的 data json 对象数据 到表格对象 并执行 .draw()
table.rows.add(new_data).draw();
}
//上移一行
function Previous(){
var node = SixGetDataChecked(table);
if (node.length != 1) {
layer.msg("请选择一行!");
return false;
}
//选中的行对象
var select_row = node[0];
//所有数据对象
var data = SixGetData(table);
for (var i = 0; i < data.length; i++) {
var item = data[i];
if (select_row.Id == item.Id) {
if (i === 0 || i > data.length - 1) {
break ;
}
var t = data[i - 1];
data[i - 1] = data[i];
data[i] = t;
break;
}
}
table.clear();
table.rows.add(data).draw();
}
//下移一行
function Next(){
var node = SixGetDataChecked(table);
if (node.length != 1) {
layer.msg("请选择一行!");
return false;
}
//选中的行对象
var select_row = node[0];
//所有数据对象
var data = SixGetData(table);
for (var i = 0; i < data.length; i++) {
var item = data[i];
if (select_row.Id == item.Id) {
if (i ==(data.length - 1) || i <0 ) {
break;
}
var t = data[i + 1];
data[i + 1] = data[i];
data[i] = t;
break;
}
}
table.clear();
table.rows.add(data).draw();
}
//置末
function Bottom(){
var node = SixGetDataChecked(table);
if (node.length != 1) {
layer.msg("请选择一行!");
return false;
}
//选中的行对象
var select_row = node[0];
//所有数据对象
var data = SixGetData(table);
var new_data = [];
for (var i = 0; i < data.length; i++) {
if (select_row.Id == data[i].Id) {
continue;
}
new_data.push(data[i]);
}
new_data.push(select_row);
table.clear();
table.rows.add(new_data).draw();
}
jquery 的 $().DataTable() 表格 行数据 上移下移
最新推荐文章于 2021-08-06 07:55:40 发布