I have found something unusual and was wondering if this is intentional behaviour and if there is a fix for this. I would ideally like to stay within bootstrap without having to specify specific widths.
I am using twitter bootstrap to format a table. However when there is a table with no data the column widths are different to a table with data, i.e. a body with rows.
I have created a jsFiddle to demo this. jsFiddle
Here is the html.
<div class="col-md-10 col-md-offset-1">
<div class="col-md-12 category-header"><span class="">Turbo</span></div>
<div class="col-md-12 no-padding">
<div class="table-responsive">
<table class="table no-margin">
<thead>
<tr>
<th class="text-left col-md-1">Part No.</th>
<th class="text-left col-md-3">Description</th>
<th class="text-center col-md-3">Notes</th>
<th class="text-center col-md-2">Dates</th>
<th class="text-center col-md-1">Stock</th>
<th class="text-right col-md-1">RRP</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">ISTB10768R</td>
<td class="col-md-3">REMANUFACTURED TURBO</td>
<td title="" class="col-md-3 text-center"></td>
<td class="col-md-2 text-center"></td>
<td class="col-md-1 text-center">
<i title="" data-placement="top" data-toggle="tooltip" class="fa fa-check amber black-tooltip" data-original-title="Less than three units in stock"></i>
</td>
<td class="col-md-1 text-right">£370.00</td>
<td class="col-md-1 text-right">
<span data-part-number="ISTB10768R" data-part-id="564" href="#" class="glyphicon glyphicon-shopping-cart add-to-cart-btn pink " title="Add To Cart ">Add</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-md-12 category-header"><span class="">Gear Boxes</span></div>
<div class="col-md-12 no-padding">
<div class="table-responsive">
<table class="table no-margin">
<thead>
<tr>
<th class="text-left col-md-1">Part No.</th>
<th class="text-left col-md-3">Description</th>
<th class="text-center col-md-3">Notes</th>
<th class="text-center col-md-2">Dates</th>
<th class="text-center col-md-1">Stock</th>
<th class="text-right col-md-1">RRP</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tbody/>
</table>
<div class="missing-parts">Please call the sales team for price and availability</div>
</div>
</div>
</div>
I am sorry but there is a problem in the code you provided(specifically in the second table), perhaps a typo. Which is causing the overflow.
Second table code you provided
<table class="table no-margin">
<thead>
<tr>
<th class="text-left col-md-1">Part No.</th>
<th class="text-left col-md-3">Description</th>
<th class="text-center col-md-3">Notes</th>
<th class="text-center col-md-2">Dates</th>
<th class="text-center col-md-1">Stock</th>
<th class="text-right col-md-1">RRP</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tbody/>
</table>
<div class="missing-parts">Please call the sales team for price and availability</div>
As you can see the <tbody/> is wrong. There is no starting <tbody> tag & the closing tag should be </tbody>. Also there the missing-parts in nowhere inside the table body. It is outside the table body and that's why the weird behavior.
I have provided the correct code below. Here is the updated Fiddle. Works fine now.
Corrected table code
<table class="table no-margin">
<thead>
<tr>
<th class="text-left col-md-1">Part No.</th>
<th class="text-left col-md-3">Description</th>
<th class="text-center col-md-3">Notes</th>
<th class="text-center col-md-2">Dates</th>
<th class="text-center col-md-1">Stock</th>
<th class="text-right col-md-1">RRP</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="missing-parts">Please call the sales team for price and availability</div>
</td>
</tr>
</tbody>
</table>
Very important thing to note here is that, even though you have not specified any number of data columns under the first <tr>, it automatically assigns the <td> values to its respective <th>s.
In other words. If you mention only one <td>, it will automatically become the data of the first header ie. "Part No.". Which also means the the width of the data takes the width of the header it corresponds to(just like the top table). Try adding another <td> inside the same table row, you will understand.
Related
So my text is "falling" out of my page at certain sizes, how do I stop this?
I have Googled and tried many things to no avail.
If you check out my screenshot u can see what I mean, and the code that is the victim of this is below as well.
Thanks in advance!
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<div class="container">
<div class="shadow p-3 mb-5 bg-white rounded">
<table class="table">
<thead>
<tr>
<th scope="col" >CRN</th>
<th scope="col">Subject</th>
<th scope="col">Course</th>
<th scope="col">Credits</th>
<th scope="col">Title</th>
<th scope="col">Days</th>
<th scope="col">Times</th>
<th scope="col">Instructor</th>
<th scope="col">Attribute</th>
<th scope="col">Professor Difficulty</th>
<th scope="col">Professor Rating</th>
<th scope="col">Would Take Again</th>
</tr>
</thead>
<tbody>
{% for row in all_data %}
<tr>
<th>{{row['crn']}}</th>
<td><strong>{{row['subj']}}</strong></td>
<td >{{row['crse']}}</td>
<td>{{row['cred']}}</td>
<td>{{row['title']}}</td>
<td>{{row['days']}}</td>
<td>{{row['time']}}</td>
<td>{{row['instr']}}</td>
<td>{{row['Attr']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{row['profDiff']}}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">{{row['profDiff']}}%
</div>
</div>
</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profRating']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profWouldTakeAgain']}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</body>
One way is to use overflow: scroll on the problematic div, so that it becomes scrollable:
.container > div {
overflow: scroll;
background-color: #fff;
}
body {
background-color: pink;
}
<div class="container">
<div class="shadow p-3 mb-5 bg-white rounded">
<table class="table">
<thead>
<tr>
<th scope="col" >CRN</th>
<th scope="col">Subject</th>
<th scope="col">Course</th>
<th scope="col">Credits</th>
<th scope="col">Title</th>
<th scope="col">Days</th>
<th scope="col">Times</th>
<th scope="col">Instructor</th>
<th scope="col">Attribute</th>
<th scope="col">Professor Difficulty</th>
<th scope="col">Professor Rating</th>
<th scope="col">Would Take Again</th>
</tr>
</thead>
<tbody>
{% for row in all_data %}
<tr>
<th>{{row['crn']}}</th>
<td><strong>{{row['subj']}}</strong></td>
<td >{{row['crse']}}</td>
<td>{{row['cred']}}</td>
<td>{{row['title']}}</td>
<td>{{row['days']}}</td>
<td>{{row['time']}}</td>
<td>{{row['instr']}}</td>
<td>{{row['Attr']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor"> <div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{row['profDiff']}}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">{{row['profDiff']}}%</div>
</div>
</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profRating']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profWouldTakeAgain']}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</body>
Alternatively, you can use some Javascript to check the current screen width, and then resize content appropriately using CSS's transform: scale(). In the example below I used jQuery for brevity, but this can sure be done using plain JS. Two things to note here:
The content should resize as the browser window is resized;
When using transform: scale, it is best to also set the transform-origin of the div to top-left so that the div does not "move around" as it is scaled.
$(document).ready(function() {
resizeTable();
});
$(window).on("resize", function() {
resizeTable();
});
function resizeTable() {
var width = $(document).width();
// if width / 1500 is greater than 1, set scale to 1
// (i.e. do not zoom in stuff if the screen is very large)
// here 1500 is only an example, you can set the number to whatever you see fit
scale = Math.min(width / 1500, 1);
$(".container table").css("transform", `scale(${scale})`);
}
.container > div {
overflow: scroll;
background-color: #fff;
}
.container table {
transform-origin: left top;
}
body {
background-color: pink;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<div class="shadow p-3 mb-5 bg-white rounded">
<table class="table">
<thead>
<tr>
<th scope="col" >CRN</th>
<th scope="col">Subject</th>
<th scope="col">Course</th>
<th scope="col">Credits</th>
<th scope="col">Title</th>
<th scope="col">Days</th>
<th scope="col">Times</th>
<th scope="col">Instructor</th>
<th scope="col">Attribute</th>
<th scope="col">Professor Difficulty</th>
<th scope="col">Professor Rating</th>
<th scope="col">Would Take Again</th>
</tr>
</thead>
<tbody>
{% for row in all_data %}
<tr>
<th>{{row['crn']}}</th>
<td><strong>{{row['subj']}}</strong></td>
<td >{{row['crse']}}</td>
<td>{{row['cred']}}</td>
<td>{{row['title']}}</td>
<td>{{row['days']}}</td>
<td>{{row['time']}}</td>
<td>{{row['instr']}}</td>
<td>{{row['Attr']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor"> <div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{row['profDiff']}}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">{{row['profDiff']}}%</div>
</div>
</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profRating']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profWouldTakeAgain']}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</body>
However, this second approach is not optimal for very small screens, e.g. mobile phones, as text will become way too small to read. So, such small screens should ideally be handled separately using CSS media queries.
My HTML table is getting more time to load when the row count is large. I have to load almost 50000 row table to the webpage. I just used basic HTML table. ASP.NET C#.
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Available Resistors In Stock</h3>
<!--
<input type="text" class="form-control pull-right" id="task-table-filter" data-action="filter" data-filters="#task-table" placeholder="Filter Resistors" />
-->
</div>
<table class="table table-hover" id="task-table">
<thead>
<tr>
<th class="center">#</th>
<th class="center">Resistor Type</th>
<th class="center">Resistor Value</th>
<th class="center">Ohm</th>
<th class="center">Location</th>
<th class="center">PL</th>
<th class="center">Place</th>
<th class="center">Category</th>
<th class="center">Quantity</th>
<th class="center">Part NO</th>
<th class="center">Description</th>
<th class="center">Active</th>
<th class="center">Edit</th>
</tr>
</thead>
<tbody>
#for (int i = 0; i < Model.Rows.Count; i++)
{
<tr class="center">
<td>#Model.Rows[i][0]</td>
<td>#Model.Rows[i][1]</td>
<td>#Model.Rows[i][2]</td>
<td>#Model.Rows[i][3]</td>
<td>#Model.Rows[i][4]</td>
<td>#Model.Rows[i][5]</td>
<td>#Model.Rows[i][6]</td>
<td>#Model.Rows[i][7]</td>
<td>#Model.Rows[i][8]</td>
<td>#Model.Rows[i][9]</td>
<td>#Model.Rows[i][10]</td>
<td>#Model.Rows[i][11]</td>
<td>
<a href="#Url.Action("StoreAddResistors", "Store",new {#id=#Model.Rows[i][0] } )">
<span class="glyphicon glyphicon-refresh"></span>
</a>
</td>
</tr>
}
</tbody>
</table>
</div>
Is there any way to reduce the loading time of the webpage?
try to split the page into several. Or is it possible to somehow connect several html documents to 1 page? I have no more idea
I am trying to make something like this in Bootstrap 4, setting the columns of table in pixels, with fixed values, forcing the horizontal scroll inside the card, but is not working. The columns don't have the size I want. The columns sizes are going to be same for all devices.
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<table class="table-sm table-hover table-bordered text-center">
<thead>
<tr class="text-uppercase font-size-1">
<th width="500px" class="font-weight-medium"></th>
<th width="500px" class="font-weight-medium">produto</th>
<th width="500px" class="font-weight-medium">status</th>
<th width="500px" class="font-weight-medium">sku</th>
<th width="500px" class="font-weight-medium">preço</th>
<th width="500px" class="font-weight-medium">estoque</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
What am I doing wrong?
It does seem to be working here is the example code
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<table class="table-sm table-hover table-bordered text-center">
<thead>
<tr class="text-uppercase font-size-1">
<th style="width:100px" class="font-weight-medium">first</th>
<th style="width:200px" class="font-weight-medium">produto</th>
<th style="width:300px" class="font-weight-medium">status</th>
<th style="width:400px" class="font-weight-medium">sku</th>
<th style="width:500px" class="font-weight-medium">preço</th>
<th style="width:600px" class="font-weight-medium">estoque</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
you need to put correct inline styles tag
<th style="width:500px;">
Why bootstrap responsive table is not working with dir-paginate.
I have created a responsive grid HTML table by using bootstrap which is working with hard-coded data, but when my angular developer colleague used some 'dir-paginate' for retrieving data from the database then my responsive design code is not working when minimizing the browser shorter.
<div class="portlet-body flip-scroll">
<div style="overflow-x:auto;">
<table id="Tbl_SiteVisitViewAll" class="table table-bordered table-striped table-condensed flip-content">
<thead class="flip-content">
<tr>
<th>S. No.</th>
<th ng-click="Sort('Active')">Attended By</th>
<th>Edit</th>
</tr>
</thead>
<tbody dir-paginate="S in SiteVisits |filter : FollowUp |orderBy:'key':AscOrDesc | itemsPerPage:20">
<tr>
<td>{{S.index}}</td>
<td>{{S.UpdatedBy}}</td>
<td>
<a href="#" ">
Edit
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
I think you are using the directive at the wrong Position. You want to repeat the <tr>-element instead of the <tbody>-element.
For more Information look at this answer: https://stackoverflow.com/a/34392061/7225524
<div class="portlet-body flip-scroll">
<div style="overflow-x:auto;">
<table id="Tbl_SiteVisitViewAll" class="table table-bordered table-striped table-condensed flip-content">
<thead class="flip-content">
<tr>
<th>S. No.</th>
<th ng-click="Sort('Active')">Attended By</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr dir-paginate="S in SiteVisits |filter : FollowUp |orderBy:'key':AscOrDesc | itemsPerPage:20">
<td>{{S.index}}</td>
<td>{{S.UpdatedBy}}</td>
<td>
<a href="#" ">
Edit
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
I cant seem to get this right, i made a divider through css divs and it shows on page but when in print the lines i made doesnt show..what other options should i do? im running out of ideas, what am i doing wrong how can i achieve this
here is what i want ot achieve
heres my css
heres the print preview
page code:
<div id="page-wrapper">
<div class="row">
<div class="col-md-12">
<div class="panel-body">
<p style="text-align:center;"><b>PROPERTY ACKNOWLEDGEMENT RECEIPT</b></p>
<p style="text-align:right;">Control No.</p>
<div class="row">
<div class="col-md-16">
<table class="table table-hover table-striped table-bordered table-condensed" class="">
<thead>
<tr>
<th style="text-align:center;">Quantity</th>
<th style="text-align:center;">Unit</th>
<th style="text-align:center;">Description</th>
<th style="text-align:center;">Unit Value</th>
<th style="text-align:center;">Property No.</th>
</tr>
</thead>
<tbody>
<tr>
<td>12</td>
<td>bucket</td>
<td style="font-size:12px;">oremloremloremloremloremloremloremloremloremlorem</td>
<td>2</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr style="background-color:black;"> NOTE:
<div style="height:2px;width:100%;background-color:black;"></div>
<div style="width:2px;height:100px;background-color:black;margin:0px auto;"></div>
</div>
</div>
</div>
$(document).ready(function() {
$('#dataTables-example').DataTable({
responsive: true
});
});