JQuery datatables 将符合条件的单元格设置特殊背景,添加点击事件
来源:互联网 发布:台湾化妆品 知乎 编辑:程序博客网 时间:2024/05/24 04:39
项目中使用到了插件datatables,实在太强大了,有了这样的需求,需要根据数据来显示是否要更换背景,以便区别对待,datatables里面有一个属性是: aocolumndefs,里面可以获取到每行的一行json数据,然后设置背景,返回即可.如下:
//设置某些列为特定样式"aoColumnDefs" : [{"aTargets": [0], mRender: function (data, type, c, d) {alert("类型为:"+type);alert("渲染类型:"+d);// alert(c.lastPersonWage.wage.positionRankWage);// alert(c.currentPersonWage.wage.positionRankWage); var lastM =c.lastPersonWage.wage.positionRankWage; var currentM = c.currentPersonWage.wage.positionRankWage; if(lastM != currentM){ alert("两者不相等"); return data ="<span class='cos_class'>测试更改某个单元格</span>"; //return c.lastPersonWage.wage.positionRankWage; } return c.currentPersonWage.retirementCardNo;}},//{//"sClass" : "cos_class",//"aTargets" : [ 3 ]//} ],参考博客:http://blog.csdn.net/qq_30259339/article/details/51151552,解释一下 render:function(a, b, c, d) {}:
ajax表示请求的地址,columns要和返回的json数据中的字段对应,并和table中的th对应"serverSide": true, //启用服务模式这个表示后台分页aoColumns[]数组中表示后端返回的json数据(也和table中的th的数量一致,所以这块容易出错),mData表示json对象的属性名,orderable是否启动排序,sDefaultContent没有这个属性的情况下的默认值,sWidth表示th的宽度,render方法表示对接收到的json数据进行处理判断后显示,` "render" : function(data, type, full, meta) { //return data == 1 ? '有效' : '<font color="red">无效</font>'; if(data==1){ data ="<a href='#' class='upOrderStatus' data-id="+full.id+">有效</a>"; }else{ data ="<a href='#' class='upOrderStatus' data-id="+full.id+"><font color='red'>无效</font></a>"; } return data; }`data表示该json属性的值,type不清楚,full表示整个json对象,就是一整行的值,d不清楚,对data进行处理,再渲染
注:设置背景的class样式为:
.cos_class {
color: #FFA500;
}
最终效果如图:
2.给datatables的某行某列添加点击事件:
$('#sample_1 tbody').on('click','tr:nth-child(2) td:nth-child(2)', function (e) { var name = $(this).text(); alert("给第2行第2列的JQuery datatables添加点击事件"+name); } );
0 0
- JQuery datatables 将符合条件的单元格设置特殊背景,添加点击事件
- datatables 根据某个条件,给符合条件的行加背景
- JQuery datatables插件 使用ajax将struts2的action对象传递给datatables设置数据源方式
- 自定义TextView设置边框与背景颜色添加点击事件,点击更改随机数与背景
- jquery.dataTables 按条件查询后重新生成表格 点击排序还是原来的数据问题
- JQuery bootstrap datepicker 单独设置某些日期的特殊背景颜色和某些月份特殊背景
- datatables 行点击事件
- 将datatable里符合条件的记录取出添加到另一个datatable进行数据绑定!
- jquery中的替换符合条件的字符串
- 将jquery的datatables插件转为中文
- jquery.datatables添加页面跳转的功能
- jQuery DataTables添加可复用的页面跳转
- jQuery实现用户添加删除,符合条件追加到表格
- JQuery点击事件添加间隔
- UIView添加手势 然后UITableView 添加进这个View 导致UITableView 的单元格点击事件无效
- UIView添加手势 然后UITableView 添加进这个View 导致UITableView 的单元格点击事件无效
- UIView添加手势 然后UITableView 添加进这个View 导致UITableView 的单元格点击事件无效
- iOS给背景添加点击事件
- W3C标准 文档 中文翻译
- Linux-C进程管理之信号、共享内存
- C程序中如何获取shell命令执行结果和返回值
- 修改SQL server外键
- 第八周项目2-建立链串算法库
- JQuery datatables 将符合条件的单元格设置特殊背景,添加点击事件
- Android HAL层分析
- Material Design 中最重要的 CoordinatorLayout 布局 (1)
- 无法中止进程无法访问操作拒绝访问
- Read-only file system
- Tessellation(曲面细分技术)
- 安卓ios_注册码系统-MySQL版代理功能接入教程
- 洛谷 1052
- Learning Webpack