My tables display fine on desktop, but once I try to view the mobile version my table ends up being too wide for the mobile device screen. I am using a responsive layout.
How can I set this table to be displayed fine in the mobile
This is my code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="row clearfix">
<div class="col-xs-12">
<div class="card">
<div class="body">
<div class="table-responsive">
<table id="myTable" class="table table-bordered table-striped table-hover js-basic-example dataTable">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
Another option might be to enable horizontal scrolling for the table by adding overflow-x:auto; to the stylesheet for the parent div.
div.table-responsive {
overflow-x:auto;
}
Don't try to fight fisics, my friends. Maybe you can hide the less important columns using media queries, show 3 instead of 6
Related
I'm using bootstrap 5 to create responsive tables which works fine but when one column has a lot of text all other columns get squished making it look weird. I would like to set it so that the columns with smaller amounts of texts and the table headers to not get cut off. I also have the table set to responsive which in bootstrap's css sets overflow-x: auto.
Picture of what the table looks like on mobile
Second Picture of mobile
Picture of what it looks like on pc
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
</head>
<div class="container">
<div class="table-responsive">
<table class="table table-sm table-bordered table-hover">
<thead class="table-warning">
<tr>
<th scope="col">Ticket ID</th>
<th scope="col">Asset Type Or User</th>
<th scope="col">Asset Tag</th>
<th scope="col">User ID</th>
<th scope="col">Name</th>
<th scope="col">Location</th>
<th scope="col">Description</th>
<th scope="col">Date Added</th>
<th scope="col">Priority</th>
<th scope="col">Mark As Done</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4</th>
<td>computer</td>
<td>C-Place-Holder</td>
<td>NA</td>
<td>Tom Blow</td>
<td>In Health Building, Bottom Floor</td>
<td>User would like to print color, has missing files, and monitor is flickering.</td>
<td>2021-02-24</td>
<td>3</td>
<td>
<button class="btn btn-primary" id="4" onclick="markDone(4)">Done</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
To make it 100% you have to add this command to your CSS
.table-responsive { display: table; } but this won't work for smaller screens. You have to use media queries for that.
Hope my answer helps you.
I‘ve created a page with a data table with Bootstrap 4. In some cases the table is very large and the data retrieval takes a few seconds. Therefore I‘ve added a spinner / loader which shows that the page is still loading. However, the spinner does not stop as expected when the page is completely loaded and I can't find a note in the documentation how to implement this. Am I using the "div" element incorrectly or do I need JavaScript? - Unfortunately I have 0% knowledge of JavaScript. Or is this a browser/OS specific issue? (I'm using Firefox / Linux).
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Hello, Table!</title>
</head>
<body>
<div class="container">
<div class="pt-3">
<span class="h1 mr-3">Large Table</span>
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="table-responsive pt-3">
<table class="table table-hover">
<thead class="thead-dark">
<tr>
<th scope="col">Column 1</th>
<th scope="col">Column 2</th>
<th scope="col">Column 3</th>
<th scope="col">Column 4</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Name 1</th>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<th scope="row">Name 2</th>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<th scope="row">Name 3</th>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
You can use
$(document).ready(function() {
// executes when HTML-Document is loaded and DOM is ready
});
OR
$(window).load(function() {
// executes when complete page is fully loaded, including all frames, objects and images
});
or if you want to hide loader after checking the table is present in DOM or not, then you can check if the table is presnt or not by its tag or selctor length.
Something like this.
var yourElement= document.getElementById("yourElement");
if(yourElement){
// Element exists
}
By jQuery
if ($( "#yourElement").length) {
// element exists
}
$(document).ready(function() {
$('.spinner-border').hide();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Hello, Table!</title>
</head>
<body>
<div class="container">
<div class="pt-3">
<span class="h1 mr-3">Large Table</span>
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="table-responsive pt-3">
<table class="table table-hover">
<thead class="thead-dark">
<tr>
<th scope="col">Column 1</th>
<th scope="col">Column 2</th>
<th scope="col">Column 3</th>
<th scope="col">Column 4</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Name 1</th>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<th scope="row">Name 2</th>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<th scope="row">Name 3</th>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
Why there is an extra column in the table?
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container-fluid">
<center>
<a href="./" class="btn btn-primary">
<i class="far fa-hand-point-left"></i> Back
</a>
<br /><br />
<table class="table table-striped table-hover table-bordered table-responsive">
<thead>
<tr>
<th>Sr.</th>
<th>Name</th>
<th>Contact</th>
<th>City</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>
Name</td>
<td>Email Id (Mobile Number)</td>
<td>City</td>
<td><button class="btn btn-large btn-primary" disabled>Waiting for Directory</button></td>
</tr>
<tr>
<td>2</td>
<td>
Name</td>
<td>Email Id (Mobile Number)</td>
<td>City</td>
<td>Block</td>
</tr>
</tbody>
</table>
</center>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
Why there is an extra column in the table? see image
Also, why there is scrollbar when screen is small? (It should adjust itself with the screen as I am using table-responsive.)
add .table-responsive class to the parent. not on table
<div class="table-responsive">
<table class="table">
...
</table>
</div>
Remove .table-responsive or add style attribute on table tag display : table
I have bootstrap table that looks like this:
As you can see the first column's text doesn't fit. How can I make first column text fit the column ?
Here's the code:
<div class="row">
<div class="col-md-12">
<div class="portlet light ">
<div class="portlet-body">
<table class="table table-striped table-bordered table-hover table-checkable order-column" id="matches_table">
<tbody>
{% for field, value in object.items %}
<tr class="odd gradeX">
<td width=""><b>{{ field|field_name_split|title }}</b></td>
<td width="">{{ value }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
Your code, don't have the . Below I have added a sample table bootstrap code.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Hover Rows</h2>
<p>The .table-hover class enables a hover state (grey background on mouse over) on table rows:</p>
<table class="table table-striped table-bordered table-hover table-checkable order-column">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Thanks,
I want to put two bootstrap tables side by side like it is answered in this question:
Two side by side tables in bootstrap
Unfortunately I don't get the result mentioned there.
My Code looks like this:
<html>
<style>
body {background-color: black;}
</style>
<link rel="stylesheet" type="text/css" href="css/ffw-spring-bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="webjars/datatables-bootstrap/2-20120201/DT_bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="webjars/bootstrap/3.3.5/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="webjars/datatables-bootstrap/2-20120201/DT_bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="css/ffw-spring.css"/>
<link rel="stylesheet" type="text/css" href="css/ffw-spring-jqueryui.css"/>
<link rel="stylesheet" type="text/css" href="css/ffw-spring-bootstrap.css"/>
<script type="text/javascript" src="webjars/datatables/1.10.5/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="js/dataTables.bootstrap.js"></script>
<script type="text/javascript" src="webjars/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-xs-6">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
<div class="col-xs-6">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
</div>
And what I get looks like this:
Thanks in advance
Try Its :
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
</div>
</body>
</html>
You have typo in your code. you need to replace
<div class="col-sx-6">
with
<div class="col-xs-6">
You've made a typo on both the columns.
You wrote col-sx-6 instead of col-xs-6. (column, show it like this on extra small screens and bigger, width of 6)
When using col-sx-6, it is just a div, which will be 100% wide.
Changing it to col-xs-6 will fix your problem.
Also, in bootstrap it is common to place your <div class="row"> inside a <div class="container">.
See: https://getbootstrap.com/docs/3.3/css/#overview-container
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<h1>Your code, using col-xs-6</h1>
<div class="row">
<div class="col-sx-6">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
<div class="col-sx-6">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
</div>
<h1>Corrected code using col-xs-6</h1>
<div class="row">
<div class="col-xs-6">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
<div class="col-xs-6">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
You should do something like below, for all resolutions:
col-lg-6 col-md-6 col-sm-6 col-xs-6
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Location</th>
<th>Message</th>
</tr>
</thead>
</table>
</div>
</div>
If you want two tables(side by side) in mobiles screen and desktop screen, then - change this <div class="col-sx-6"> to <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
And if you want two tables in desktop screen and not in mobile screen.
Change this <div class="col-sx-6"> to <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">