jQuery Datatables 動態(tài)列+跨列合并實現(xiàn)代碼
更新時間:2020年01月30日 16:16:11 作者:賣萌的猴子
這篇文章主要介紹了jQuery Datatables 動態(tài)列+跨列合并實現(xiàn)代碼,需要的朋友可以參考下
有時候需要用到
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值的方法
最近著手一個項目用到了服務(wù)器空間checkboxlist ,使用起來是方便,可以想要從js獲取值就稍微麻煩點了,google后找到了如下方法,感興趣的小伙伴們可以參考一下2015-09-09jQuery.event兼容各瀏覽器的event詳細(xì)解析
jQuery在遵循W3C規(guī)范的情況下,對事件的常用屬性進(jìn)行了封裝,使得事件處理在各大瀏覽器下都可以正常的運行而不需要進(jìn)行瀏覽器類型判斷2013-12-12jquery select多選框的左右移動 具體實現(xiàn)代碼
這篇文章介紹了jquery實現(xiàn)select多選框的左右移動的方法,有需要的朋友可以參考一下2013-07-07jQuery實現(xiàn)驗證表單密碼一致性及正則表達(dá)式驗證郵箱、手機(jī)號的方法
這篇文章主要介紹了jQuery實現(xiàn)驗證表單密碼一致性及正則表達(dá)式驗證郵箱、手機(jī)號的方法,涉及jQuery表單元素獲取及正則驗證相關(guān)操作技巧,需要的朋友可以參考下2017-12-12