jQuery Datatables 动态列+跨列合并实现代码
更新时间:2020年01月30日 16:16:11 作者:卖萌的猴子
这篇文章主要介绍了jQuery Datatables 动态列+跨列合并实现代码,需要的朋友可以参考下
有时候需要用到
html
<input type="hidden" name="thead_key" id="thead_key" value="<?php if(isset($thead_key)):?><?php echo $thead_key;?><?php endif;?>"> <input type="hidden" name="thead_num" id="thead_num" value="<?php if(isset($thead_num)):?><?php echo $thead_num;?><?php endif;?>"> <table class="table text-nowrap table-striped table-bordered table-hover dataTables_list"> <thead> <tr> <th rowspan="2"><div align="center">备注明细</div></th> <?php if(isset($thead_arr)):?> <th colspan="<?php echo count($thead_arr);?>"><div align="center">校区</div></th> <?php endif;?> </tr> <?php if(isset($thead_arr)):?> <?php foreach($thead_arr as $val):?> <th><div align="center"><?php echo $val;?></div></th> <?php endforeach;?> <?php endif;?> </thead> </table>
js代码基于jquery
var oTable = null;
var initTable = function()
{
var thead_key = $("#thead_key").val();
var thead_num = $("#thead_num").val();
thead_key = thead_key.split(',');
var column_names = new Array();
for(var i=0;i<=thead_num;i++)
{
column_names.push({"className":"text-c","sDefaultContent": ''})
}
oTable = $(".dataTables_list").dataTable({
"sPaginationType": "full_numbers",
"bLengthChange":true,
"bFilter": false,//搜索栏
"bProcessing": false,
"bPaginate": true,
"bServerSide": true,
"bSort": false, //排序功能
//"iDisplayLength":parseInt("{:config('admin_page_size')}"),
"bAutoWidth": false,
"sAjaxSource": "{:url('edu_report/ajax_school_group_product_list')}",
"aoColumns": column_names,//封装好的数组
//给行赋值
"fnRowCallback": function(nRow, aData, iDisplayIndex)
{
$('td:eq(0)', nRow).html(aData.memo);
$.each(thead_key, function(i, args)
{
$('td:eq('+(i+1)+')', nRow).html(aData["memo_cnt_"+args]);
})
},
});
}
效果图:

主要是参考思路与想法,具体的就介绍到这了,如果有帮助希望以后多多支持脚本之家。
相关文章
jQuery中$.ajax()和$.getJson()同步处理详解
这篇文章主要介绍了jQuery中$.ajax()和$.getJson()同步处理详解的相关资料,非常的细致全面,有需要的小伙伴可以参考下。2015-08-08
jQuery实现打开网页自动弹出遮罩层或点击弹出遮罩层功能示例
这篇文章主要介绍了jQuery实现打开网页自动弹出遮罩层或点击弹出遮罩层功能,涉及jQuery事件响应及窗口元素属性的相关操作技巧,需要的朋友可以参考下2017-10-10
jquery关于事件冒泡和事件委托的技巧及阻止与允许事件冒泡的三种实现方法
大家都知道,jQuery事件触发时有2种机制,一种是事件委托,另一种是事件冒泡,冒泡或默认的事件发生,在某些时候是不需要的,在此就需要一些可以阻止冒泡和默认的事件的方法,本文介绍三种方法做到不同程度的阻止,感兴趣的朋友可以了解下,或许对你了解冒泡事件有所帮助2015-11-11


最新评论