小编给大家分享一下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 Datatables 动态列+跨列合并的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。