table列表展示中拖动排序

前端JS

 

// //保存排序
// if (window.location.href.indexOf("showStatus=0") == -1) {
// $('#saveSort').click(function () {
// var Ids = '';
// $('#tab-sort tbody tr').each(function () {
// var id = $(this).attr('data-id');
// Ids += id + ',';
// });

////Ids是得到拖动后的顺序

// if (Ids.length > 0) {
// Ids = Ids.substring(0, Ids.length - 1);
// }

// $.ajax({
// url: '',
// type: 'POST',
// data: { ids: Ids },
// dataType: 'text',
// success: function (ret) {
// alert(ret == '1' ? '保存成功' : '保存失败');
// window.location.reload();
// },
// error: function (xhr, t) {
// console.log(xhr, t);
// alert('保存失败');
// }
// });
// });
// }

 

MVC后台处理

// 任务管理保存排序
// POST: /Gift/SaveSort
[HttpPost]
public string SaveSort(string ids)
{
PayServices PayServices = new PayServices();
int ret = PayServices.SaveSort(ids) ? 1 : 0;
return ret.ToString();
}

 

 

/// <summary>
/// 保存排序
/// </summary>
/// <param name="giftIds"></param>
/// <returns></returns>
public bool SaveSort(string ids)
{
if (string.IsNullOrWhiteSpace(ids) || ids.IndexOf(',') < 0)
{
return false;
}

using (GiftInfrastructure g = new GiftInfrastructure())
{
return g.GiftSaveSort(ids);
}
}

 

/// <summary>
/// 保存任务管理序
/// </summary>
/// <param name="giftIds">eg: 101,102,103</param>
/// <returns></returns>
public bool GiftSaveSort(string ids)
{
DynamicParameters param = new DynamicParameters();
param.AddDynamicParams(new { giftIds= ids });
try
{
return conn.Execute("AS_SortUserTaskInfo", param, commandType: CommandType.StoredProcedure) > 0;
}
catch (Exception ex)
{
return false;
}
}

 

SQL数据库存储过程

ALTER proc [dbo].[SP_Mliao_SaveSort]
@giftIds varchar(2000) -- eg: 101,102,103
as
begin
if @giftIds is not null and CHARINDEX(',',@giftIds)>0
begin
select ROW_NUMBER()over(order by (select 0))sortid,a as id into #tab_sortid
from [tableListSplit] (@giftIds,',')

update a set a.sortId=b.sortid
from Mliao_Gift a,#tab_sortid b
where a.giftId=b.id

drop table #tab_sortid
end
end

 

posted @ 2018-09-14 10:51  ITMrRight  阅读(1474)  评论(0编辑  收藏  举报