最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

BootStrap table实现表格行拖拽效果

来源:动视网 责编:小OO 时间:2020-11-27 22:03:19
文档

BootStrap table实现表格行拖拽效果

本文实例为大家分享了BootStrap table实现表格行拖拽的具体代码,供大家参考,具体内容如下:不上图了;首先还是得添加三个文件,自己上网搜搜就行。<;script src="~/Content/bootstrap-table/jquery.tablednd.js">;<;/script>;<;script src="~/Content/bootstrap-table/bootstrap-table-reorder-rows.js">;<;/script>;<;link href="~/Content/bootstrap-table/bootstrap-table-reorder-rows.css" rel="stylesheet"/>。
推荐度:
导读本文实例为大家分享了BootStrap table实现表格行拖拽的具体代码,供大家参考,具体内容如下:不上图了;首先还是得添加三个文件,自己上网搜搜就行。<;script src="~/Content/bootstrap-table/jquery.tablednd.js">;<;/script>;<;script src="~/Content/bootstrap-table/bootstrap-table-reorder-rows.js">;<;/script>;<;link href="~/Content/bootstrap-table/bootstrap-table-reorder-rows.css" rel="stylesheet"/>。


本文实例为大家分享了BootStrap table实现表格行拖拽的具体代码,供大家参考,具体内容如下

不上图了

首先还是得添加三个文件,自己上网搜搜就行

<script src="~/Content/bootstrap-table/jquery.tablednd.js"></script>
<script src="~/Content/bootstrap-table/bootstrap-table-reorder-rows.js"></script>
<link href="~/Content/bootstrap-table/bootstrap-table-reorder-rows.css" rel="stylesheet"/>

前台,加在Bootstrap Table 属性里面  

//当选中行,拖拽时的哪行数据,并且可以获取这行数据的上一行数据和下一行数据
 onReorderRowsDrag: function(table, row) {
 //取索引号
 dragbeforeidx = $(row).attr("data-index");
 },
 //拖拽完成后的这条数据,并且可以获取这行数据的上一行数据和下一行数据
 onReorderRowsDrop: function (table, row) {
 //取索引号
 draglateridx = $(row).attr("data-index");
 },
 //当拖拽结束后,整个表格的数据
 onReorderRow: function (newData) {
 //这里的newData是整个表格数据,数组形式
 if (dragbeforeidx != draglateridx) {//这是我其他地方需要的,你们可不必要这个
 //console.log(newData); 调试用代码
 $.post("Sort",
 { jsondata: JSON.stringify(newData) },//将整张表数据Post,当然,先序列化成Json
 function(data) {
 if (data == "success") {
 $table.bootstrapTable('refresh');
 }
 });
 }
 }

后台代码Controller

public string Sort(string jsondata)
 {
 //将json序列化为List<T>
 JavaScriptSerializer serializer = new JavaScriptSerializer();
 List<WorkFlow> list = serializer.Deserialize<List<WorkFlow>>(jsondata);
 BLL.Base.WorkFlow bllworkflow = new BLL.Base.WorkFlow();
 var result = bllworkflow.Sort(list);
 return result;
 }

排序的思路:当前台拖动完成后,将整个表格数据传入后台,先删除之前数据库中的数据,重新保存当前数据实现排序。

缺点:  如果你有分页显示,返回的Table数据只为第一页的。第二页就会出现排序问题。

文档

BootStrap table实现表格行拖拽效果

本文实例为大家分享了BootStrap table实现表格行拖拽的具体代码,供大家参考,具体内容如下:不上图了;首先还是得添加三个文件,自己上网搜搜就行。<;script src="~/Content/bootstrap-table/jquery.tablednd.js">;<;/script>;<;script src="~/Content/bootstrap-table/bootstrap-table-reorder-rows.js">;<;/script>;<;link href="~/Content/bootstrap-table/bootstrap-table-reorder-rows.css" rel="stylesheet"/>。
推荐度:
标签: 表格 table 拖拽
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top