table列表展示中拖动排序

it2024-04-23  155

前端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,103asbegin 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 endend

 

转载于:https://www.cnblogs.com/yjm8023/p/9645190.html

相关资源:表格拖动排序
最新回复(0)