jquery-datatables icon indicating copy to clipboard operation
jquery-datatables copied to clipboard

table-sm Bootstrap class breaks fixedColumns

Open Ana06 opened this issue 5 years ago • 11 comments

Using table-sm Boostrap class with fixedColumns option breaks the table and render an extra arrow.

With table-sm:

image

Without table-sm:

HTML code (it is long :see_no_evil:):

<table class="table table-sm" id="project-monitor-table">
<thead class="header">
<tr>
<th></th>
<th class="text-center" colspan="2">
Debian_7.0
</th>
<th class="text-center" colspan="2">
Debian_8.0
</th>
<th class="text-center" colspan="2">
Debian_9.0
</th>
<th class="text-center" colspan="1">
SLE_12_SP4
</th>
<th class="text-center" colspan="1">
SLE_15
</th>
<th class="text-center" colspan="1">
openSUSE_Leap_15.0
</th>
<th class="text-center" colspan="1">
openSUSE_Leap_15.1
</th>
<th class="text-center" colspan="1">
openSUSE_Leap_42.3
</th>
<th class="text-center" colspan="2">
openSUSE_Tumbleweed
</th>
<th class="text-center" colspan="2">
xUbuntu_12.04
</th>
<th class="text-center" colspan="2">
xUbuntu_14.04
</th>
<th class="text-center" colspan="2">
xUbuntu_16.04
</th>
<th class="text-center" colspan="1">
xUbuntu_17.10
</th>
<th class="text-center" colspan="1">
xUbuntu_18.04
</th>
<th class="text-center" colspan="1">
xUbuntu_18.10
</th>
</tr>
<tr>
<th></th>
<th class="text-center">
i586
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
i586
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
i586
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
i586
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
i586
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
i586
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
i586
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
x86_64
</th>
<th class="text-center">
x86_64
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
packname
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
</tr>
<tr>
<td>
packname
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
</tr>
<tr>
<td>
packname
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
<td class="text-center">
status
</td>
</tr>
</tbody>
</table>

Javascript code:

 $('#project-monitor-table').DataTable({scrollX: true, fixedColumns: true, pageLength: 50, lengthMenu: [[10, 25, 50, 100, -1], [10,25, 50, 100, "All"]], search: { regex: true, smart: false } });

Real/original code can be found here: https://github.com/openSUSE/open-build-service/blob/master/src/api/app/views/webui2/webui/project/monitor.html.haml

Ana06 avatar Feb 07 '19 16:02 Ana06

this is probably a bug, but you may override current css with this:

table.dataTable.table-sm .sorting:before,
table.dataTable.table-sm .sorting_asc:before,
table.dataTable.table-sm .sorting_desc:before {
  top: initial;
  right: 1em;
  bottom: 0.3em;
}

http://live.datatables.net/taxawetu/3

mkhairi avatar Feb 08 '19 00:02 mkhairi

table.dataTable.table-sm .sorting:before,
table.dataTable.table-sm .sorting_asc:before,
table.dataTable.table-sm .sorting_desc:before {
  top: initial;
  right: 1em;
  bottom: 0.3em;
}

thanks @mkhairi! :wink: This removes the extra arrow, but not the fact that the first column has its own scroll and that it can be independently moved. You can see it by making one of the packnames longer in your code:

image

Ana06 avatar Feb 08 '19 09:02 Ana06

@Ana06, try to set column width on the first column

     <tr>
          <th width="200px"></th>
          <th class="text-center"> i586 </th>
          <th class="text-center"> x86_64 </th>
          <th class="text-center">i586</th>
          <th class="text-center"> x86_64 </th>
 ....

or pass datatables option

columnDefs: [
     { width: 200, targets: 0 }
],

or use css ellipsis

mkhairi avatar Feb 08 '19 10:02 mkhairi

@mkhairi

try to set column width on the first column

This doesn't seem to work: http://live.datatables.net/liduciti/1/edit I have tried to remove the scroll (probably there is a better way to do this):

.DTFC_LeftBodyLiner{
  overflow-y: hidden !important;
}

http://live.datatables.net/puraqodo/1/edit

But there the border between the first and the second column is gone... it seems that the first column is wither than the cell where it is contained:

image

Ana06 avatar Feb 08 '19 12:02 Ana06

@Ana06, 😉 here alternative example using ellipsis and word-wrap http://live.datatables.net/sanabewe/5/

mkhairi avatar Feb 08 '19 13:02 mkhairi

@mkhairi

@Ana06, here alternative example using ellipsis and word-wrap http://live.datatables.net/sanabewe/5/

That works perfectly... until you add a w-100 to the table (which I didn't add originally to simplify as it didn't seem to be related): http://live.datatables.net/sanabewe/7/edit :sob:

Ana06 avatar Feb 08 '19 13:02 Ana06

@Ana06 why did you add class w-100? is that necessary?

mkhairi avatar Feb 08 '19 14:02 mkhairi

@mkhairi

@Ana06 why did you add class w-100? is that necessary?

To ensure that the table takes all the space.

If the table is big enough, it looks fine without it:

image

But if it is smaller

with w-100

image

without:

image

it looks weird... :disappointed:

Ana06 avatar Feb 08 '19 14:02 Ana06

@Ana06 owh, i see... try use style="min-width: 100%" instead of .w-100

mkhairi avatar Feb 08 '19 14:02 mkhairi

@mkhairi that works! :tada: I am still not completely convinced with having to set the column width, but it is good enough :wink: The bug should still be fix in DataTables though :smile:

Thanks for the help! :cupid: I have added you as co-author as it is more your code than mine (hope that it is fine): https://github.com/openSUSE/open-build-service/pull/6948/commits/15415b1c9b7a7ee373d39793b538f4868475b200

Ana06 avatar Feb 08 '19 16:02 Ana06

@mkhairi, just in case it is useful to fix the bug, we needed to add word-break: break-all; as well: https://github.com/openSUSE/open-build-service/pull/6985/commits/383e65c5688f9ba9eb2988fda0822832458da5ef :wink:

Ana06 avatar Feb 15 '19 08:02 Ana06