Columns won't freeze when individual column filtering applied
Columns won't freeze when individual column filtering applied
I have an html table where I need the header frozen, 2 left columns frozen, and show the option to filter on all other columns (not the 2 left columns). When I did fixed columns by itself it worked great.. but when I added the code to include drop down filtering on columns the fixed column option doesn't work. any idea how I can resolve this?? The header is frozen, the individual column filtering works (yay) but the 2 left columns are not frozen. code below:
<script>
$(document).ready(function () {
$('#primary').DataTable({
initComplete: function () {
this.api().columns([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]).every(function () {
var column = this;
var select = $('<select><option value="">Show All</option></select>')
.appendTo($(column.header()))
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
var val = $('<div/>').html(d).text();
select.append('<option value="' + val + '">' + val + '</option>');
});
});
},
paging: false,
sort: false,
scrollY: 500,
scrollX: true,
select: true,
fixedColumns: {
leftColumns: 2
},
fixedHeader: {
header: true,
},
});
});
</script>
table:
<table id="1" class="table table-striped">
@if (Model.1Function != null)
{
<thead>
<tr>
@foreach (DataColumn column in (Model.1Function as DataTable).Columns)
{
<th>@column.ColumnName.ToUpper()</th>//header row
}
</tr>
</thead>
<tbody>
@if ((Model.1Function as DataTable).Rows.Count > 0)
{
foreach (DataRow dr in (Model.1Function as DataTable).Rows)
{
<tr>
@foreach (DataColumn column in (Model.1Function as DataTable).Columns)
{
<td style="max-width:200px; white-space:normal">
@dr[column].ToString()
</td>//write one row at a time.
}
</tr>
}
}
else
{
var count = (Model.1Function as DataTable).Columns.Count;
<tr>
<td colspan='@count' style="color:red;">
No Data Found.
</td>
</tr>
}
</tbody>
}
else
{
<tr>
<td style="color:red;">
@(Model.1Function .HasErrors != false ? Model.1Function .HasErrors.ToString() : "")
</td>
</tr>
}
</table>
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
According to the compatibility matrix FixedHeader and FixedColumns are not compatible to be used on the same table. For more info please read their docs:
https://datatables.net/extensions/fixedheader/
https://datatables.net/extensions/fixedcolumns/
Kevin
I removed the fixed header parameter but no change.. still the same issue.
@kthorngren idk if you saw my response above.. but removing the fixed header option did not fix the issue. Any help would be great
I built a test case for you using your above code without FixedHeader. It seems to work:
http://live.datatables.net/sezuheka/1/edit
Can you update the test case to show the issue or if the issue exists provide the exact steps needed to recreate the issue.
Kevin
Jeez.. I accidentally added an extra column in the this.api().column array.. that was the reason it was failing
sorry for the inconvenience