jQuery Easyui Datagrid实现单行的上移下移及保存移动的结果


Posted in Javascript onAugust 15, 2016

1、实现行的上移、下移、

说明:

1.1 通过datagrid生成的表格有固定的格式,比如,表格div的class名是datagrid-view。比如每一行tr都有id和datagrid-row-index属性等。

1.2 在上移和下移以后,我们将移动以后的两行的id和datagrid-row-index属性也必须互换,这样能保证datagrid-row-index=0的行肯定是页面显示的表格的第一行,=1的是第二行等等。将来保存的时候,就是通过取这个属性值找某一行的数据的。

function move(isUp) {
var selections = $dg.datagrid('getSelections');
if(selections.length == 0){
return;
}
var $view = $('div.datagrid-view');
var index = $dg.datagrid('getRowIndex',selections[0]);
var $row = $view.find('tr[datagrid-row-index=' + index + ']');
if (isUp) {
$row.each(function(){
var prev = $(this).prev();
var prevId = prev.attr('id');
var prevDatagridRowIndex = prev.attr('datagrid-row-index');
var thisId = $(this).attr('id');
var thisDatagridRowIndex = $(this).attr('datagrid-row-index');
prev.length && $(this).insertBefore(prev);
$(this).attr('id',prevId);
$(this).attr('datagrid-row-index',prevDatagridRowIndex);
prev.attr('id',thisId);
prev.attr('datagrid-row-index',thisDatagridRowIndex);
});
} else {
$row.each(function(){
var next = $(this).next();
var nextId = next.attr('id');
var nextDatagridRowIndex = next.attr('datagrid-row-index');
var thisId = $(this).attr('id');
var thisDatagridRowIndex = $(this).attr('datagrid-row-index');
next.length && $(this).insertAfter(next);
$(this).attr('id',nextId);
$(this).attr('datagrid-row-index',nextDatagridRowIndex);
next.attr('id',thisId);
next.attr('datagrid-row-index',thisDatagridRowIndex);
});
}
}

2、保存移动的结果

说明:每一个tr包含若干个td,每个td都有field属性,即表格展示对象的相应属性名,例子中goodsId是我要展示的商品的主键。每个td下都包含一个div,通过层层

find找到这个div以后,值就得到了。

function nextStep() {
var arrayData = $dg.datagrid('getData').rows;
var $view = $('div.datagrid-view');
if(arrayData.length!=0){
saveIds = '';
for(var index=0;index<arrayData.length;index++){
var goodsId = $view.find('tr[datagrid-row-index=' + index + ']').find("td[field='goodsId']").find('div').html();
saveIds += goodsId;
if(index != arrayData.length-1){
saveIds += ',';
}
}
$.ajax({
url:'${pageContext.request.contextPath}/coupons/getTemplateId',
type:'post',
dataType:'json',
success:function(result){
window.location.href="${pageContext.request.contextPath}/coupons/tpl"+result+"?goodsId="+saveIds;
}
});
}
}

以上所述是小编给大家介绍的jQuery Easyui Datagrid实现单行的上移下移及保存移动的结果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Javascript 相关文章推荐
javascript分页代码实例分享(js分页)
Dec 13 Javascript
javascript框架设计之种子模块
Jun 23 Javascript
深入探究AngularJS框架中Scope对象的超级教程
Jan 04 Javascript
Angular的Bootstrap(引导)和Compiler(编译)机制
Jun 20 Javascript
picLazyLoad 实现图片延时加载(包含背景图片)
Jul 21 Javascript
原生javascript实现读写CSS样式的方法详解
Feb 20 Javascript
js仿微博动态栏功能
Feb 22 Javascript
移动端效果之Swiper详解
Oct 09 Javascript
JS中promise化微信小程序api
Apr 12 Javascript
webpack+vue+express(hot)热启动调试简单配置方法
Sep 19 Javascript
微信小程序云开发之云函数详解
May 16 Javascript
vue - vue.config.js中devServer配置方式
Oct 30 Javascript
关于动态执行代码(js的Eval)实例详解
Aug 15 #Javascript
jQuery Ajax Post 回调函数不执行问题的解决方法
Aug 15 #Javascript
对js eval()函数的一些见解
Aug 15 #Javascript
详细解读Jquery各Ajax函数($.get(),$.post(),$.ajax(),$.getJSON())
Aug 15 #Javascript
js HTML5 Canvas绘制转盘抽奖
Sep 13 #Javascript
jQuery学习笔记之回调函数
Aug 15 #Javascript
纯css下拉菜单 无需js
Aug 15 #Javascript
You might like
php下一个阿拉伯数字转中文数字的函数
2007/07/16 PHP
php常用ODBC函数集(详细)
2013/06/24 PHP
php中用memcached实现页面防刷新功能
2014/08/19 PHP
Laravel中使用Queue的最基本操作教程
2017/12/27 PHP
Laravel解决nesting level错误和隐藏index.php的问题
2019/10/12 PHP
javascript数组组合成字符串的脚本
2021/01/06 Javascript
jquery 学习笔记 传智博客佟老师附详细注释
2020/09/12 Javascript
JavaScript 三种创建对象的方法
2009/10/16 Javascript
js判断变量是否未定义的代码
2020/03/28 Javascript
jquery选择器之属性过滤选择器详解
2014/01/27 Javascript
七个很有意思的PHP函数
2014/05/12 Javascript
JavaScript检测浏览器cookie是否已经启动的方法
2015/02/27 Javascript
详解Vue+Element的动态表单,动态表格(后端发送配置,前端动态生成)
2019/04/20 Javascript
Nodejs + Websocket 指定发送及群聊的实现
2020/01/09 NodeJs
微信小程序新闻网站详情页实例代码
2020/01/10 Javascript
Vue scoped及deep使用方法解析
2020/08/01 Javascript
如何利用JS将手机号中间四位变成*号
2020/09/29 Javascript
[15:35]教你分分钟做大人:天怒法师
2014/10/30 DOTA
[56:14]Fnatic vs OG 2018国际邀请赛小组赛BO2 第二场 8.18
2018/08/19 DOTA
Python中__init__和__new__的区别详解
2014/07/09 Python
Python正则抓取网易新闻的方法示例
2017/04/21 Python
Python获取二维矩阵每列最大值的方法
2018/04/03 Python
Python3安装pip工具的详细步骤
2019/10/14 Python
Python Sqlalchemy如何实现select for update
2020/10/12 Python
奥地利网上书店:Weltbild
2017/07/14 全球购物
印尼披萨外送专家:Domino’s Pizza印尼
2017/12/28 全球购物
西安当代医院管理研究院笔试题
2015/12/11 面试题
老师推荐信
2013/10/28 职场文书
员工培训邀请函
2014/02/02 职场文书
高中英语演讲稿范文
2014/04/24 职场文书
奉献家乡演讲稿
2014/09/16 职场文书
人身意外保险授权委托书
2014/10/01 职场文书
呼啸山庄读书笔记
2015/06/29 职场文书
高中开学感言
2015/08/01 职场文书
教你用eclipse连接mysql数据库
2021/04/22 MySQL
MySQL日期时间函数知识汇总
2022/03/17 MySQL