Reputation: 331
I would like to set fixed columns on scroll with data tables, say I have a column at index 1,10,15. On horizontal scroll, I need to be able to set those as fixed. At the moment I am only able to set only the first column to be fixed.
Work for the first column
$('#example').DataTable( {
fixedColumns: true
} );
Works for the first two columns
$('#example').DataTable( { fixedColumns: { leftColumns: 2 } } );
How do I fix the 1,10,15
I tried
$('#example').DataTable( {
fixedColumns: {
leftColumns: [1,10,15]
}
} );
Example
table columns = > |1(freeze) | 2 |... |10(freeze)|....|15(freeze)|
Any suggestions
Upvotes: 0
Views: 2934
Reputation: 7624
As per Datatable's Doc
You can add Fixed Columns in both Left and Right and it even allows multiple Columns.
Catch is all columns have to be continous.
Unfortunately fixing column in middle is not allowed. Due to its complexity. Read Doc above
Sample Code
$(document).ready(function() {
var table = $('#datatbleId').DataTable( {
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false,
fixedColumns: {
leftColumns: 2,
rightColumns: 3
}
} );
} );
More detail here
Upvotes: 3
Reputation: 408
You might try this to fix the column in your js .
$(document).ready(function() {
var table = $('#example').DataTable( {
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false,
fixedColumns: {
leftColumns: 1,
rightColumns: 1
}
} );
} );
Upvotes: 1