2016-03-12 36 views
0

之间<head>标签:数据表fixedColumns不工作

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css"/> 
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/fixedcolumns/3.2.1/css/fixedColumns.dataTables.min.css"/> 
<script type="text/javascript" src="https://cdn.datatables.net/fixedcolumns/3.2.1/js/dataTables.fixedColumns.min.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script> 

脚本:

<script> 
$(document).ready(function() { 
    var table = $('#example').DataTable({ 
     scrollY:  "300px", 
     scrollX:  true, 
     scrollCollapse: true, 
     paging:   true, 
     fixedColumns: { 
      leftColumns: 2 
     } 
    }); 
}); 
</script> 

表(它有超过2行):

<table id="example" class="stripe row-border order-column" cellspacing="0" width="100%"> 
<thead> 
<tr> 
<th>..</th> 
<th>..</th> 
<th>..</th> 
<th>..</th> 
<th>..</th> 
<th>..</th> 
</tr> 
</thead> 
<tbody> 
<tr> 
<td>...</td> 
<td>...</td> 
<td>...</td> 
<td>...</td> 
<td>...</td> 
<td>...</td> 
</tr> 
</tbody> 
</table> 

CSS:

/* Ensure that the demo table scrolls */ 
th, td { white-space: nowrap; } 
div.dataTables_wrapper { 
    width: 100%; 
    margin: 0 auto; 
} 

表正在工作,但表没有固定列。 FixedColumns部分不起作用。我的代码有什么问题?我该如何解决它?

它说它看起来像你的文章主要是代码;请添加一些更多的细节,所以我打字这发送这个问题 -

回答

4

问题是图书馆没有正确的顺序。你的脚本等应该是这样的:

<script type="text/javascript" src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/fixedcolumns/3.2.1/js/dataTables.fixedColumns.min.js"></script> 

所以基本上你只需要确保fixedcolumns之前加载主数据表js文件:)