jquery dataTable 设置固定列

引入js

<script src="https://cdn.datatables.net/fixedcolumns/4.0.2/js/dataTables.fixedColumns.min.js"></script>
js代码:
 //初始化页面,加载供应商数据
    dataTables = $('#tab_contractList').DataTable({
        paging: true,
        serverSide: true,
        autoWidth: false,
//获取数据 sAjaxSource: $(
"#basePath").val()+"/demo/getList", iDisplayLength: 10, fnServerData: function (sSource, aoData, fnCallback) { }, pagingType: "full_numbers", //pageLength: 20, "language": { "paginate": { "last": "末页", "first": "首页", "previous": "上一页", "next": "下一页" }, "emptyTable": "无数据", "info": "第 _PAGE_ 页 共 _PAGES_ 页 - 共 _MAX_ 条记录", "infoEmpty": "", "search": "筛选:", "infoFiltered": "" }, searching: false, ordering: false, lengthChange: false,

//设置列宽自适应 "fixedHeader": true, "scrollX": "auto", "scrollY": "400px", "scrollCollapse": true, columns: columns, columnDefs: columnDefs, fnRowCallback : function(nRow, aData, iDisplayIndex) {// 相当于对字段格式化 $('td:eq(0)', nRow).attr('style', 'width:10px;'); },
//去掉设置固定列后,出现双层滚动条问题 drawCallback:
function(setting){ $( $('.DTFC_RightBodyLiner')).css('overflow-y','auto'); $( $('.DTFC_RightBodyLiner')).css('overflow-x','hidden'); $( $('.DTFC_LeftBodyLiner')).css('overflow-y','auto'); $( $('.DTFC_LeftBodyLiner')).css('overflow-x','hidden'); } }); new $.fn.dataTable.FixedColumns( dataTables, { rightColumns: 1 } );

 

posted @ 2022-12-28 17:01  凉面好好吃  阅读(1245)  评论(0编辑  收藏  举报