How do I let datatable headers adjust with the column width?
up vote
1
down vote
favorite
I am using jQuery datatables for a project and I have the following issue:
On first load, the columns of the header and data rows are nicely aligned. However, when the window is resized, the body cells shrink or grow, whereas the header cells remain a constant width. The result is a mis-alignment of the header and body rows.
The following code is used to initialize the datatable:
$el.DataTable(
paging: true,
lengthChange: true,
searching: true,
ordering: true,
info: true,
autoWidth: false,
pageLength: 25,
columns: getColumns(configurationObject),
scrollX: true,
language: localizationObject,
data: getDataset(configurationObject),
dom: 'lrtip',
lengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, localizationObject['allRows']]
]
);
And the html is as follows:
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Code</th>
<th>Description</th>
</tr>
</thead>
</table>
In my quest to solve this issue, I have tried the following:
- Set
autoWidthto true/false - Enable/Disable the responsive plugin
Many answers revolve around the table being constructed before the dom is finished loading, or inside a hidden div preventing widths to be calculated. Neither of those are true for me. The code above gets called in a $(document).ready(function () } and is not hidden when called (as I said, initial load works fine, but I thought it is worth mentioning).
In my investigation, I noticed that, for the header row, an entirely new html table is created. The cells of that row are also given a fixed width. That does explain the misalignment to me, but, I am no closer to actually resolving the issue at hand.
I am trying to achieve either of two scenarios:
- The columns of the body are of fixed width, and horizontal scroll will take over if the table overflows. I have set
scrollXto true, and on small screens this works very well. - The columns of the header row are not of fixed width, but rather the width of the body columns.
Hopefully I have provided enough information for someone to find an answer, because I have googled and looked and I can't find it. If more information is needed, then please let me know.
Thank you in advance.
javascript jquery datatables
add a comment |
up vote
1
down vote
favorite
I am using jQuery datatables for a project and I have the following issue:
On first load, the columns of the header and data rows are nicely aligned. However, when the window is resized, the body cells shrink or grow, whereas the header cells remain a constant width. The result is a mis-alignment of the header and body rows.
The following code is used to initialize the datatable:
$el.DataTable(
paging: true,
lengthChange: true,
searching: true,
ordering: true,
info: true,
autoWidth: false,
pageLength: 25,
columns: getColumns(configurationObject),
scrollX: true,
language: localizationObject,
data: getDataset(configurationObject),
dom: 'lrtip',
lengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, localizationObject['allRows']]
]
);
And the html is as follows:
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Code</th>
<th>Description</th>
</tr>
</thead>
</table>
In my quest to solve this issue, I have tried the following:
- Set
autoWidthto true/false - Enable/Disable the responsive plugin
Many answers revolve around the table being constructed before the dom is finished loading, or inside a hidden div preventing widths to be calculated. Neither of those are true for me. The code above gets called in a $(document).ready(function () } and is not hidden when called (as I said, initial load works fine, but I thought it is worth mentioning).
In my investigation, I noticed that, for the header row, an entirely new html table is created. The cells of that row are also given a fixed width. That does explain the misalignment to me, but, I am no closer to actually resolving the issue at hand.
I am trying to achieve either of two scenarios:
- The columns of the body are of fixed width, and horizontal scroll will take over if the table overflows. I have set
scrollXto true, and on small screens this works very well. - The columns of the header row are not of fixed width, but rather the width of the body columns.
Hopefully I have provided enough information for someone to find an answer, because I have googled and looked and I can't find it. If more information is needed, then please let me know.
Thank you in advance.
javascript jquery datatables
I ran into something similar and I have to call the DataTable.adjust() every time. May be you can try it
– Loredra L
Nov 9 at 16:51
Are you able to made a snippet example with the basic code that generate the issue?
– D. Smania
Nov 9 at 22:00
try<table class="table table-bordered table-striped" style="width: 100%;">
– zerosand1s
Nov 10 at 3:02
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using jQuery datatables for a project and I have the following issue:
On first load, the columns of the header and data rows are nicely aligned. However, when the window is resized, the body cells shrink or grow, whereas the header cells remain a constant width. The result is a mis-alignment of the header and body rows.
The following code is used to initialize the datatable:
$el.DataTable(
paging: true,
lengthChange: true,
searching: true,
ordering: true,
info: true,
autoWidth: false,
pageLength: 25,
columns: getColumns(configurationObject),
scrollX: true,
language: localizationObject,
data: getDataset(configurationObject),
dom: 'lrtip',
lengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, localizationObject['allRows']]
]
);
And the html is as follows:
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Code</th>
<th>Description</th>
</tr>
</thead>
</table>
In my quest to solve this issue, I have tried the following:
- Set
autoWidthto true/false - Enable/Disable the responsive plugin
Many answers revolve around the table being constructed before the dom is finished loading, or inside a hidden div preventing widths to be calculated. Neither of those are true for me. The code above gets called in a $(document).ready(function () } and is not hidden when called (as I said, initial load works fine, but I thought it is worth mentioning).
In my investigation, I noticed that, for the header row, an entirely new html table is created. The cells of that row are also given a fixed width. That does explain the misalignment to me, but, I am no closer to actually resolving the issue at hand.
I am trying to achieve either of two scenarios:
- The columns of the body are of fixed width, and horizontal scroll will take over if the table overflows. I have set
scrollXto true, and on small screens this works very well. - The columns of the header row are not of fixed width, but rather the width of the body columns.
Hopefully I have provided enough information for someone to find an answer, because I have googled and looked and I can't find it. If more information is needed, then please let me know.
Thank you in advance.
javascript jquery datatables
I am using jQuery datatables for a project and I have the following issue:
On first load, the columns of the header and data rows are nicely aligned. However, when the window is resized, the body cells shrink or grow, whereas the header cells remain a constant width. The result is a mis-alignment of the header and body rows.
The following code is used to initialize the datatable:
$el.DataTable(
paging: true,
lengthChange: true,
searching: true,
ordering: true,
info: true,
autoWidth: false,
pageLength: 25,
columns: getColumns(configurationObject),
scrollX: true,
language: localizationObject,
data: getDataset(configurationObject),
dom: 'lrtip',
lengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, localizationObject['allRows']]
]
);
And the html is as follows:
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Code</th>
<th>Description</th>
</tr>
</thead>
</table>
In my quest to solve this issue, I have tried the following:
- Set
autoWidthto true/false - Enable/Disable the responsive plugin
Many answers revolve around the table being constructed before the dom is finished loading, or inside a hidden div preventing widths to be calculated. Neither of those are true for me. The code above gets called in a $(document).ready(function () } and is not hidden when called (as I said, initial load works fine, but I thought it is worth mentioning).
In my investigation, I noticed that, for the header row, an entirely new html table is created. The cells of that row are also given a fixed width. That does explain the misalignment to me, but, I am no closer to actually resolving the issue at hand.
I am trying to achieve either of two scenarios:
- The columns of the body are of fixed width, and horizontal scroll will take over if the table overflows. I have set
scrollXto true, and on small screens this works very well. - The columns of the header row are not of fixed width, but rather the width of the body columns.
Hopefully I have provided enough information for someone to find an answer, because I have googled and looked and I can't find it. If more information is needed, then please let me know.
Thank you in advance.
javascript jquery datatables
javascript jquery datatables
asked Nov 9 at 15:06
Maarten
415
415
I ran into something similar and I have to call the DataTable.adjust() every time. May be you can try it
– Loredra L
Nov 9 at 16:51
Are you able to made a snippet example with the basic code that generate the issue?
– D. Smania
Nov 9 at 22:00
try<table class="table table-bordered table-striped" style="width: 100%;">
– zerosand1s
Nov 10 at 3:02
add a comment |
I ran into something similar and I have to call the DataTable.adjust() every time. May be you can try it
– Loredra L
Nov 9 at 16:51
Are you able to made a snippet example with the basic code that generate the issue?
– D. Smania
Nov 9 at 22:00
try<table class="table table-bordered table-striped" style="width: 100%;">
– zerosand1s
Nov 10 at 3:02
I ran into something similar and I have to call the DataTable.adjust() every time. May be you can try it
– Loredra L
Nov 9 at 16:51
I ran into something similar and I have to call the DataTable.adjust() every time. May be you can try it
– Loredra L
Nov 9 at 16:51
Are you able to made a snippet example with the basic code that generate the issue?
– D. Smania
Nov 9 at 22:00
Are you able to made a snippet example with the basic code that generate the issue?
– D. Smania
Nov 9 at 22:00
try
<table class="table table-bordered table-striped" style="width: 100%;">– zerosand1s
Nov 10 at 3:02
try
<table class="table table-bordered table-striped" style="width: 100%;">– zerosand1s
Nov 10 at 3:02
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228272%2fhow-do-i-let-datatable-headers-adjust-with-the-column-width%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I ran into something similar and I have to call the DataTable.adjust() every time. May be you can try it
– Loredra L
Nov 9 at 16:51
Are you able to made a snippet example with the basic code that generate the issue?
– D. Smania
Nov 9 at 22:00
try
<table class="table table-bordered table-striped" style="width: 100%;">– zerosand1s
Nov 10 at 3:02