jQuery Datatables 動(dòng)態(tài)列+跨列合并實(shí)現(xiàn)代碼
更新時(shí)間:2020年01月30日 16:16:11 作者:賣萌的猴子
這篇文章主要介紹了jQuery Datatables 動(dòng)態(tài)列+跨列合并實(shí)現(xiàn)代碼,需要的朋友可以參考下
有時(shí)候需要用到
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">備注明細(xì)</div></th> <?php if(isset($thead_arr)):?> <th colspan="<?php echo count($thead_arr);?>"><div align="center">校區(qū)</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,//封裝好的數(shù)組 //給行賦值 "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]); }) }, }); }
效果圖:
主要是參考思路與想法,具體的就介紹到這了,如果有幫助希望以后多多支持腳本之家。
相關(guān)文章
jQuery獲取checkboxlist的value值的方法
最近著手一個(gè)項(xiàng)目用到了服務(wù)器空間checkboxlist ,使用起來是方便,可以想要從js獲取值就稍微麻煩點(diǎn)了,google后找到了如下方法,感興趣的小伙伴們可以參考一下2015-09-09jQuery.event兼容各瀏覽器的event詳細(xì)解析
jQuery在遵循W3C規(guī)范的情況下,對(duì)事件的常用屬性進(jìn)行了封裝,使得事件處理在各大瀏覽器下都可以正常的運(yùn)行而不需要進(jìn)行瀏覽器類型判斷2013-12-12NiftyCube——輕松實(shí)現(xiàn)圓角邊框
這篇文章主要介紹了NiftyCube——輕松實(shí)現(xiàn)圓角邊框2007-02-02使用jQuery操作HTML的table表格的實(shí)例解析
這篇文章主要介紹了使用jQuery操作HTML的table表格的實(shí)例解析,包括用jQuery獲取表格總行數(shù)的小技巧,需要的朋友可以參考下2016-03-03jquery select多選框的左右移動(dòng) 具體實(shí)現(xiàn)代碼
這篇文章介紹了jquery實(shí)現(xiàn)select多選框的左右移動(dòng)的方法,有需要的朋友可以參考一下2013-07-07jQuery實(shí)現(xiàn)驗(yàn)證表單密碼一致性及正則表達(dá)式驗(yàn)證郵箱、手機(jī)號(hào)的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)驗(yàn)證表單密碼一致性及正則表達(dá)式驗(yàn)證郵箱、手機(jī)號(hào)的方法,涉及jQuery表單元素獲取及正則驗(yàn)證相關(guān)操作技巧,需要的朋友可以參考下2017-12-12