datatables 带参数查询与完成后的回调处理

datatables 带参数查询

var table = $('#datatables');//表格对象
 //datatables
table.dataTable( {
  "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
  "sPaginationType": "bootstrap",
  "oLanguage": {
		  "sLengthMenu": "每页显示  _MENU_ 条记录",  
		  "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
		  "oPaginate": {
			  "sFirst": "首页",
			  "sPrevious": "前一页",
			  "sNext": "后一页",
			  "sLast": "尾页"
			  },
		  "sZeroRecords": "抱歉, 没有找到",
		  "sInfoEmpty": "没有数据"
		},
 "bProcessing": true,
 "bServerSide": true,
 "sAjaxSource": "/user/list",
 "bFilter": true, 
								 
  "aoColumnDefs": [{
				  "aTargets": [3],
				  "mData": null,
				  "bSortable": false,
				  "bSearchable": false,
				  "mRender": function (data, type, full) {
					  if(full[3] == 1){
						 return "使用中"  
					  }else if(full[3] == 0){
						 return "禁用" 
					  }
				  }
			  },{
				  "aTargets": [4],
				  "mData": null,
				  "bSortable": false,
				  "bSearchable": false,
				  "mRender": function (data, type, full) {
					  if(full[4] == 2){
						 return "管理员"  
					  }else if(full[4] == 1){
						 return "用户" 
					  }
				  }
			  },{
				  "aTargets": [5],
				  "mData": null,
				  "bSortable": false,
				  "bSearchable": false,
				  "mRender": function (data, type, full) {
					  return '<a data-toggle="modal" data-target="#myModal"  data-title="' + full[0] + '"  class="btn btn-info" href="#"><i class="icon-edit icon-white"></i>修改</a>' +'&nbsp;&nbsp;';
				  }
			  }]

});

//动态的点击事件来查询
//带参数查询
$('.icon-external-link').click(function () {
	//以下为查询时候动态添加查询参数方法
	var oSettings = table.fnSettings();
	oSettings.aoServerParams.push({
		"fn": function (aoData) {
			aoData.push({
			"name": "thisisok",
			"value": "这是我传递的参数的内容说"
			});
		}
	});
	table.fnDraw();
});

第二种

$('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "scripts/server_processing.php",
    "fnServerParams": function ( aoData ) {
      aoData.push( { "name": "more_data", "value": "my_value" } );
    }
});


完成操作后的回调(发现很适合搞一些总计之类的处理)


"fnDrawCallback":function(obj){
     console.log(obj.aoData[0]._aData);
}

完成渲染后给每行最后一个td加个caozuo的class,以后事件中使用

"fnDrawCallback":function(obj){
    $.each(obj.aoData,function(k,v){
       $(v.nTr).find('td:last').addClass('caozuo');
    });
}






转载于:https://my.oschina.net/tongjh/blog/215081

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值