Fixed columns and headers isn't quite working for us
Fixed columns and headers isn't quite working for us
Link to test case:
Table options used:
$('.DT_table').DataTable({
dom: 'Bfr',
paging: false,
scrollX: true,
fixedHeader: true,
fixedColumns: {left: 2},
columnDefs: [{
type: 'natural', targets: 1,
}],
buttons: [
{
extend: 'excel',
text: '<i class="dt-btn-icon fa fa-2x fa-file-excel-o"></i>',
className: 'btn btnExport',
},
{
extend: 'print',
text: '<i class="fa fa-2x fa-print">',
className: 'btn btnPrint',
messageTop: $(document).find('h4').html(),
customize: function (win) {
$(win.document.body).find('h1').css('text-align','center');
$(win.messageTop).find('h4').css('text-align','center');
console.log(win.document)
},
}],
})
Debugger code (debug.datatables.net):
N/A
Error messages shown:
None
Description of problem:
We have an RTL table and wanted to have the first 2 columns fixed for easier readability on mobile devices (turning responsive has resulted in hiding columns, which wasn't desirable) We noticed a few issues in our case:
1. The first column was squeezed almost completely ignoring its content
2. The Datatable top buttons and search field are scrolled off the screen along while scrolling the table
3. Static header isn't working when scrolling vertically
4. The fixed columns classes & styling are gone
See here
Answers
Many times this is the result of not using the correct style integration files for the style framework you are using. Use the Download Builder to get the correct files. If you are still having issues then we will need to see the problem to help debug. Please post a link to your page or a test case replicating the issues.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Hi! Thank you for the quick response, I used the download builder a while ago when starting this. I have tried to mimic a close example here http://live.datatables.net/cetofixe/3/
I don't have the test case completely right as the search input seems to be placed incorrectly. But there are some problems I found which may help:
Move jquery.js above bootstrap.js.
You have duplicated and conflicting CSS and JS include statements. I commented them out. The CDN bundle contains these includes.
You have
dom: 'Bfr'
. You are missingt
for the table. This can cause strange issues. Also you should use the Bootstrap styled string for thedom
option.Here is the updated test case:
http://live.datatables.net/felaluxi/1/edit
I added some rows to show fixedHeader works.
Let us know if these changes helps.
Kevin
I posted a reply earlier not sure if is went through but I don't see it in the thread!
I've added your comment above as a quote. It was caught in the spam queue - sorry. It looks like one of the emoji characters was giving it some problems.
Are you able to share a link to a page showing the header being duplicated? It sounds like it might be cloning for some reason before it needs to - possibly due to being initialised hidden?
There isn't an option in DataTables for that I'm afraid. I was wondering if
position: sticky
would do it, but I can't seem to get that to work as expected. I'm sure there is an answer there, but I'm missing it...Allan
Thank you Alan for adding my previous comment. I think you are right about the position sticky, I added the below CSS classes which seems to have helped position them. I believe the trick was to make the content of the row for the search and buttons to "fit-content" rather than 100%
Here is an updated fiddle
http://live.datatables.net/felaluxi/2/
Would that be easily integratabtle into DataTables allowing for different buttons setup and support for RTL?
I will try to see what is causing this duplicate header and replicate it for review..
A quick follow up, the CSS code above did not work for me on my page unfortunately. The buttons and search input still moves with the rest of the non-fixed columns part of the table to the far right, well beyond the user's screen view when scrolled horizontally.
@allan @kthorngren is there a way for us to create HTML buttons away from DataTable buttons, then hide all DataTable buttons, however be able to trigger DT buttons using the created HTML buttons? This way we can place the HTML buttons in any place, with whatever CSS style, yet be able to trigger DT buttons when clicked?
Sorry I don't know why the styling is a problem. However you have a couple options:
B
from thedom
config.button().trigger()
to trigger the Datatable button.Kevin
Thank you, I will give that a try now. Would you be so kind to let me know how I can do the same for the columns visibility button?
I tried adding it as one of the DT buttons, but the selection pop up shows beyond the table, see here http://live.datatables.net/felaluxi/3/edit
In the example for button().trigger() it shows
table.button( '2-1' ).trigger()
can you explain what does'2-1'
mean?Option 1 Direct insertion method worked perfectly, thank you
Is there a way to do the same as below but for the search input?
table.buttons().container().appendTo( $('.#customDiv', table.table().container() ) );
You can use jQuery to move the search element. Do this in `-option initComplete.
Kevin
That's awesome, I think we are conversing to a complete solution here...
Quick note, removing the DOM option from the configuration introduced another issue: right below the table now shows the page number (page 1 of X), and we are not interested in showing pagination at all. Is there another way other than enforcing
display: none
in the CSS of thedataTables_info
element?Set the
info
to false.Kevin