jQuery Datatables 动态列+跨列合并实现代码
时间:2021-03-22 09:10:08|栏目:jquery|点击: 次
有时候需要用到
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
下一篇:如何使用jQUery获取选中radio对应的值(一句代码)
本文标题:jQuery Datatables 动态列+跨列合并实现代码
本文地址:http://www.codeinn.net/misctech/85844.html






