Here is some CSS code that will help align buttons, search, and page length:
Before:
https://i.sstatic.net/sQt2m.png
After:
https://i.sstatic.net/uRRqi.png
The CSS code is as follows:
<style>
.dataTables_length label {
margin-top: 15px;
display: inline-flex;
}
.dataTables_length label select {
margin-left: 20px;
margin-right: 20px;
}
.dataTables_length {
margin-left: 20px;
margin-right: 20px;
}
.dataTables_wrapper {
display: flex;
flex-wrap: wrap;
}
.dt-buttons {
padding-top: 10px;
padding-bottom: 10px;
flex-wrap: wrap;
}
.dataTables_filter {
margin-top: 12px;
}
</style>
The Datatables initialization configurations should include the following:
dom: 'Blfrtip'
To initialize Datatables with buttons for copy, excel, pdf, and print, you need to import the following scripts:
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>
<script src="https://cdn.datatables.net/select/1.2.5/js/dataTables.select.min.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.bootstrap4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.colVis.min.js"></script>
Here is a full example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
...
...
...
</body>
</html>