Is it possible in bootstrap to create a table as:
Fixed headers and scroll-able content like here
The columns need to size proportionaly to the content of the columns (wider/smaller column depanding on content)
scroll-able x-axis if more columns that can be displayed
columns have min and max width
So far I found only a solution that would require to know the number of columns to size correctly with a flex approach like here .
table {
box-sizing: border-box;
-moz-box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: stretch;
height: 500px; /* this can vary */
}
table * {
box-sizing: inherit;
-moz-box-sizing: inherit;
}
thead {
display: flex;
flex-direction: column;
align-items: stretch;
}
tbody {
overflow-y: scroll;
display: inline-block;
}
thead > tr, tbody > tr, tfoot > tr {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}
thead, tfoot {
flex-shrink: 0;
}
th, tbody td {
width: 20%; /* this can vary */
overflow-x: hidden;
text-overflow: ellipsis;
display: inline-block;
}
tfoot {
display: inline-block;
}
tfoot td {
width: 100%;
display: inline-block;
}
Included is an example of what you might be looking for. I've included how to implement filtering and sorting as well. Keep in mind I just scrapped this together so I haven't had time to test anything, but this is roughly the idea of what you might be looking for?
HTML File:
<div class="wrapTable">
<table class="head table-bordered">
<thead>
<tr>
<td ng-click="sortType = 'id'; sortReverse = !sortReverse">
Id
<span ng-show="sortType == 'id' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
<span ng-show="sortType == 'id' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
</td>
<td ng-click="sortType = 'name'; sortReverse = !sortReverse">
Name
<span ng-show="sortType == 'name' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
<span ng-show="sortType == 'name' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
</td>
</tr>
</thead>
<tr>
<td><input ng-model="dataText.id"></td>
<td><input ng-model="dataText.name"></td>
</tr>
</table>
<div class="scrollableBody">
<table class="table table-bordered table-striped">
<tbody>
<tr ng-repeat="data in dataList | orderBy:sortType:sortReverse| filter:dataText">
<td>{{data.id}}</td>
<td>{{data.name}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
$scope.sortReverse = false;
$scope.sortType = 'id'; // set the default sort type
$scope.dataText = '';
$scope.dataList=....some dynamic JSON data request
</script>
CSS File:
.wrapTable {
height: 100%;
overflow-x: auto;
}
.wrapTable table { /*set wrap for table*/
max-width: 10000px;
table-layout: fixed;
width: 100%;
display: inline-table;
}
table tr td {
margin: 0;
padding: 5px;
width: 200px; /*width of each column*/
word-wrap: break-word;
}
table.head tr td {
background: #000000;
color: white;
height: 40px;
}
.scrollableBody {
height: 550px;
min-width: inherit;
overflow-y: scroll !important;
position: absolute; /* <-- here is what is important*/
}
.scrollableBody::-webkit-scrollbar {
width: 0em;
height: 2em;
}
I forgot to mention that inside the wrapTable you can set a fix width and declare scrollable-x if needed.
Related
now I'm making a v-table(vuetify3) using loop of Vue.js. This v-table is pretty much the same as just an html table. However, I couldn't display the content properly.
The problem is if I try to store a long text in one cell, it gets out of the cell. If I use {overflow: hidden}, overflowed text is not shown. But what I want to do is to change the heigh of the row based on the text size.
My code is below. Even if I set {heigh:auto} to td or tr, it didn't work.
<template>
<div>
<v-table hover="true" class="table">
<thead>
<tr>
<th class="text-left">URL</th>
<th class="text-left">タイトル</th>
</tr>
</thead>
<tbody>
<tr v-for="item in items" :key="item.name">
<td class="url">{{ item.url }}</td>
<td class="title">{{ item.title }}</td>
</tr>
</tbody>
</v-table>
</div>
</template>
<script setup>
import { reactive, ref, computed } from "vue";
import { defineProps, handleError } from "vue";
const props = defineProps({
items: [],
kwsMatrixHeaders: [],
});
</script>
<style scoped>
.table {
display: block;
table-layout: fixed;
}
tbody {
width: 100%;
display: block;
}
tbody tr {
height: auto;
}
th {
display: inline-block;
width: 200px;
}
td {
vertical-align: middle;
display: inline-block;
width: 200px;
height: 100px;
}
.url {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.title {
overflow:visible;
/* text-overflow: ellipsis; */
/* white-space: nowrap; */
}
</style>
I have a table css's with this form: column 1, 2 and 3 are inline-block and column 4 and 5 are block. I want a bottom line divider between table rows that occupied 100% of the screen, not of the div.
Now the bottom line divider is width 100% but I want to cover the full screen. The right and left sides don't go all the way, that's what I want, they do go.
I'm using this:
.dataTable tbody tr:after {
content: "";
position: absolute !important;
height: 1px !important;
width: 100% !important;
background-color: #dddddd !important;
}
Thanks.
Example:
.dataTable {
border: none !important;
}
.dataTable td:nth-child(1) {
display: inline-block !important;
}
.dataTable td:nth-child(2) {
display: inline-block !important;
}
.dataTable td:nth-child(3) {
display: inline-block !important;
}
.dataTable td:nth-child(4) {
display: block !important;
}
.dataTable td:nth-child(5) {
display: block !important;
margin-left: -25px !important;
}
.dataTable thead tr {
position: absolute;
left: -9999px;
}
.dataTable th,
.dataTable td {
padding: 10px;
border-bottom: none !important;
}
.dataTable tbody tr:after {
content: "";
position: absolute !important;
height: 1px !important;
width: 100% !important;
background-color: #dddddd !important;
}
<table id="ptp_f8a8c39ec1dfbfd6_1" class="posts-data-table dataTable no-footer dtr-inline" data-config="{"pageLength":-1,"pagingType":"numbers","serverSide":false,"autoWidth":true,"clickFilter":true,"scrollOffset":15,"resetButton":false,"lengthMenu":[[10,25,50,100,-1],[10,25,50,100,"All"]],"columnDefs":[{"className":"col-data_prova","targets":0},{"className":"col-illa_compet","targets":1},{"className":"col-modalitat_compet","targets":2},{"className":"col-title","targets":3},{"className":"col-actaresultats_prova","targets":4}],"dom":"<\"posts-table-wrapper generatepress\"<\"posts-table-above posts-table-controls\">t>"}" data-filters="false" data-order="[]" style="visibility: visible; position: static; width: 100%;" width="100%"><thead><tr><th class="all col-data_prova sorting_disabled" data-name="data_prova" data-orderable="false" data-searchable="true" rowspan="1" colspan="1" style="width: 29px;" aria-label="Data">Data</th><th data-name="illa_compet" data-orderable="false" data-searchable="true" data-click-filter="true" class="col-illa_compet sorting_disabled" rowspan="1" colspan="1" style="width: 20px;" aria-label="Illa">Illa</th><th data-name="modalitat_compet" data-orderable="false" data-searchable="true" data-click-filter="true" class="col-modalitat_compet sorting_disabled" rowspan="1" colspan="1" style="width: 60px;" aria-label="Modalitat">Modalitat</th><th data-name="title" data-orderable="false" data-searchable="true" data-priority="1" class="col-title sorting_disabled" rowspan="1" colspan="1" style="width: 78px;" aria-label="Competició">Competició</th><th data-name="actaresultats_prova" data-orderable="false" data-searchable="true" class="col-actaresultats_prova sorting_disabled" rowspan="1" colspan="1" style="width: 60px;" aria-label="Resultats">Resultats</th></tr></thead><tbody><tr id="post-row-6228" class="post-row post-type-competicions competicions-6228 publish odd"><td data-sort="1616198400" class="col-data_prova dtr-control" tabindex="0">20/03/2021</td><td class=" col-illa_compet">Mallorca</td><td class=" col-modalitat_compet">Trail</td><td class=" col-title">I Trail-Running Son Quint Palma – Night</td><td class=" col-actaresultats_prova"></td></tr><tr id="post-row-6229" class="post-row post-type-competicions competicions-6229 publish even"><td data-sort="1616284800" class="col-data_prova dtr-control" tabindex="0">21/03/2021</td><td class=" col-illa_compet">Mallorca</td><td class=" col-modalitat_compet">Trail</td><td class=" col-title">I Trail-Running Son Quint Palma – Day</td><td class=" col-actaresultats_prova"></td></tr><tr id="post-row-6340" class="post-row post-type-competicions competicions-6340 publish odd"><td data-sort="1616889600" class="col-data_prova dtr-control" tabindex="0">28/03/2021</td><td class=" col-illa_compet">Mallorca</td><td class=" col-modalitat_compet">Ruta</td><td class=" col-title">San Silvestre Palma 2020</td><td class=" col-actaresultats_prova"></td></tr></tbody></table>
Important: the table is automatically generated, I can't edit it to add classes. The CSS must be done with the HTML of the attached table.
first of all, padding is giving that space.
the only thing needed is that set left:0 and right:0 for pseudo-element ::before ::after.
for your .dataTable tbody tr:after set left:0 and right:0.
Or I am unsure but your table has padding of 10px so set width:calc(100% + 20px).
below is just a replication of that.
.main {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background: #f5f5f5;
}
.table {
position: relative;
background: #fff;
padding: 15px;
width: calc(100% - 60px);
}
.table .block {
display: block;
}
/*for thoes border*/
.table::before,
.table::after {
content: "";
display: inline-block;
height: 2px;
width: 100%;
background-color: #c5c5c5;
position: absolute;
top: 10px;
left: 0;
right: 0;
}
.table::after {
top: initial;
bottom: 10px;
}
<div class="main">
<div class="table">
<span>a</span>
<span>b</span>
<span>c</span>
<span class="block">d</span>
<span class="block">e</span>
</div>
</div>
As you can see, in order to make the entire table cell link-clickable, I used td a {display: block}. The problem is td a {vertical-align: middle} no longer works with display: block. Not sure how else to center it vertically. Any help would be greatly appreciated.
P.S. I avoided using line-height because my link needs to be multi-line.
table {
width: 300px;
border-collapse: collapse;
}
td {
border: 1px solid #000000;
height: 100px;
vertical-align: middle;
}
td a {
display: block;
height: 100px;
vertical-align: middle !important;
}
<table>
<tr>
<td>TEXT</td>
<td>LINK</td>
</tr>
</table>
You can use an auxiliar span and center it inside the anchor, so its content is free to move and align.
E.g.:
table {
width: 300px;
border-collapse: collapse;
}
td {
border: 1px solid #000000;
height: 100px;
vertical-align: middle;
}
td a {
display: flex;
height: 100%;
}
td a span {
height: fit-content;
align-self: center;
}
<table>
<tr>
<td>TEXT</td>
<td>
<a href="">
<span>
A VERY LONG LINK MAY BE LIKE THIS ONE, I GUES, RIGHT? HERE WE GO :D
</span>
</a>
</td>
</tr>
</table>
Added span in anchor tag and made a CSS change for the output
table {
width: 300px;
border-collapse: collapse;
}
td {
border: 1px solid #000000;
height: 100px;
vertical-align: middle;
}
td a {
display: table;
position: relative;
height: 100%;
width: 100%;
}
span {
display: table-cell;
text-align:center;
vertical-align: middle;
}
<table>
<tr>
<td>TEXT</td>
<td><span>LINK</span></td>
</tr>
</table>
I set a fixed width in td, but it doesn't work when the table is overflow. What I have tried is the below code.
td {
width: 192px;
}
It can resolve by following 2 steps.
1 - On table set width:100%
2 - On td of table use class like this when your data get overflow.
.dataRow
{
word-wrap: break-word;
word-break: break-all;
}
3 - after above 2, you can also set width as per your requirement, if needed.
You can change in css with td { width:20px} or you can change it inline <td style="width:20px">.
This can be achieve using display property.
Check below Snippet.
.wrapper {
width: 180px;
border: 1px solid #000;
}
.table-scroll {
width: 100%;
table-layout: fixed;
}
.table-scroll tbody {
display: block;
overflow: scroll;
}
.table-data {
border: 1px solid #0F0;
}
.table-detail {
border: 1px solid #F00;
}
td.first {
width: 200px;
display: inline-block;
}
<div class="wrapper">
<table class="table-scroll table-data">
<tbody>
<tr>
<td class="first">HEAD1</td>
<td>HEAD2</td>
<td>HEAD3</td>
<td>HEAD4</td>
</tr>
</tbody>
</table>
</div>
the URL is http://action.news
there are 3 columns in a fixed width table)
(i removed the script that loads on demand) to make things easier.
thank you kindly
what i have done:
added this code below
https://gist.github.com/hkirsman/3002480
added this per google instructions
<meta name=viewport content="width=device-width, initial-scale=1">
i have read HTML table with auto-fit for some columns, fixed width for others
but still cant get the page to be mobile friendly, the top part seems to realign
I've found this example on the Codepen so you can try it and adjust it to your needs:
Here's some code
HTML:
<table class="js-table participants-table">
<caption>
<p>Responsive Table</p>
</caption>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Gender</th>
<th>Picture</th>
</tr>
</thead>
<tbody>
<!--filled from javascript-->
</tbody>
</table>
CSS:
HTML {
font-size: 100%;
line-height: 1.5;
font-family: 'Raleway', sans-serif;
}
BODY {
margin: 0;
}
*, *:before, *:after {
box-sizing: border-box;
}
IMG {
max-width: 100%;
}
/*Style For Table*/
.participants-table {
table-layout: fixed;
border-collapse: collapse;
margin: 0 auto;
width: 90%;
}
.participants-table TD,
.participants-table TH {
border: 1px solid #b4adad;
}
.participants-table IMG {
width: 150px;
}
.participants-table THEAD {
display: none;
}
.participants-table TD {
display: block;
position: relative;
overflow-x: hidden;
text-overflow: ellipsis;
}
#media only screen and (min-width: 450px) {
.participants-table {
width: auto;
}
.participants-table TD,
.participants-table TH {
padding: .2em 1em;
}
.participants-table THEAD {
display: table-header-group;
}
.participants-table TD {
display: table-cell;
position: static;
}
.participants-table TD:before {
display: none;
}
}
link to the example