i need add fixed headers to the table create with yajra datatables in laravel 9.28
I have other tables with parameter: ->fixedHeader(true)
and when i´m scrolling down, my headers stay in top.
In my new table, i´m setting this parameter:
return $this->builder()
->setTableId('web-newspaper-table')
->columns($this->getColumns())
->minifiedAjax()
->orderBy(2, 'DESC')
->destroy(true)
->fixedHeader(true)
->responsive(true)
->serverSide(true)
->stateSave(true)
->processing(true)
->pageLength(100)
->dom($this->domHtml)
->language(__('app.datatable'))
->parameters([
'fixedHeader' => true,
'initComplete' => 'function () {
window.LaravelDataTables["web-newspaper-table"].buttons().container()
.appendTo( "#table-actions")
}',
'fnDrawCallback' => 'function( oSettings ) {
$("body").tooltip({
selector: '[data-toggle="tooltip"]'
})
}',
])
->buttons(Button::make(['extend' => 'excel', 'text' => '<i class="fa fa-file-export"></i> ' . trans('app.exportExcel')]));
}
When i´m doing scrolling down, my headers not set in top.
i trayed to add styles:
#web-newspaper-table thead th {
position: sticky !important;
z-index: 12;
top: 0px;
background: white;
}
i trayed to add javascript:
<script>
$(document).ready(function() {
$('#web-newspaper-table').DataTable({
fixedHeader: {
header: true,
footer: true
}
});
});
</script>
But always i have same problem. Not keep headers in top
.
I read in other forum, that <link rel="stylesheet" href="{{ asset('vendor/datatables/dataTables.bootstrap4.min.css') }}">
this style create conflicts with <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/fixedheader/3.1.2/css/fixedHeader.dataTables.min.css">
that, also, i add this style or plugin, and althought not set my headers in top…
What i´m doing bad?
Thanks for readme, and sorry for my bad english
2
Answers
To set fixed header in Yajra Datatable, check official docs. They show how:
These will help you set fixed header in Yajra Datatable.
Sorry for problem. Fix header in Yajra Datatables, make sure to include the right CSS and JS files for FixedHeader. Add these in your Blade template:
Then initialize with:
Yajra Datatables Package Documentation
Maybe this helps?