Bootstrap Table Row Going outside - html

I have a simple table in my Codeigniter site like below
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Image</th>
<th>Username</th>
<th>Comment</th>
<th>Action</th>
</tr>
</thead>
<tbody id="ajax_table">
</tbody>
</table>
and I am displaying row like below
public function getComment(){
$page = $_GET['page'];
$user_id =$_GET['user_id'];
// $data['comments'] = $this->member->get_all_comment($user_id);
$comments = $this->member->get_all_comment($page,$user_id);
$html='';
if(isset($comments) && count($comments)>0){
foreach($comments as $comment){
if($comment->image ==""){
$image = "https://granboardonline.com/uploads/empty.jpg";
}
else {
$image = "https://granboardonline.com/uploads/".$comment->image;
}
$html.= "<tr><td>".$comment->date_created."</td><td> <img src= $image style='width:50px;height:50px;'> </td><td>".$comment->fname."</td><td>".$comment->comment."</td>";
if($this->session->userdata('user_id')==$comment->reciver_id || $this->session->userdata('user_id')==$comment->sender_id){
$html.="<td><button class='btn btn-light btn-sm deletecomment' comment_id='".$comment->comment_id."'>Delete</button></td></tr>";
}
}
}
echo $html;
exit;
}
But my comment column's row going outside and looking very bad, How I can show it fit the column?
Thanks!

You can refer https://www.w3schools.com/bootstrap4/bootstrap_tables.asp and
https://getbootstrap.com/docs/4.0/content/tables/ for more information.
<div class="table-responsive">
<table class="table">
...
</table>
</div>
It's always a good practice to set the width of the columns to give more look and feel to the design and avoid taking auto width as per the content.
If you are not using bootstrap table utility classes then remember that your table should have the width 100% and there should be an overflow if the page is opened in the smaller devices to avoid inconsistency in the width of the page.
You can do that by enclosing it inside a div
<div style="overflow:auto">
<table class="table" style="width:100%;">
...
</table>
</div>
I hope that helps you.

use word-break style for td tag
e.g
<td style="word-break: break-word;">aaaaaaaaaaaaaaaaaaaaaaaa</td>

Related

Non Repeating Table Footer That Avoids Breaking Over Printed Pages CSS

So I have a weird situation were I have a table footer that I only need to repeat once so I decided to just add the "footer" trs to the end of the tbody so it would only appear once at the end of the table and look like a footer without the repeating on each printed page.
<table>
<tbody>
#foreach(var item in Model.Items)
{
<tr><td>#item.Name</td></tr>
<tr><td>#item.Total</td></tr>
}
<tr>
<td>Total</td>
<td>#Model.Items.Sum(x => x.Total)</td>
</tr>
<tr>
<td>Discount</td>
<td>#(Model.Items.Sum(x => x.Total) / 50)</td>
</tr>
</tbody>
</table>
This was fine until Model.Items had enough rows that it pushed the second row of the footer onto the next page when I need to keep the two footer rows together.
I've also tried using the actual tfoot tag like so with a page-break-inside:avoid style.
<table>
<tbody>
#foreach (var item in Model.Items)
{
<tr><td>#item.Name</td></tr>
<tr><td>#item.Total</td></tr>
}
</tbody>
<tfoot style="page-break-inside:avoid;">
<tr>
<td>Total</td>
<td>#Model.Items.Sum(x => x.Total)</td>
</tr>
<tr>
<td>Discount</td>
<td>#(Model.Items.Sum(x => x.Total) / 50)</td>
</tr>
</tfoot>
</table>
This kept the footer together but its now repeating on each page instead of once. Someone on another Stack Overflow question suggested using the following style on the tfoot to stop it repeating which worked, but now it ignores the page-break-inside:avoid style.
<tfoot style="display: table-row-group"></tfoot>
Does anyone know how to get a footer to appear once and avoid breaking over multiple printed pages?
I got it working but I had to apply a few styles to make it looks like one table. I put the original footer HTML into a tr > td > table like so:
<table>
<tbody>
#foreach (var item in Model.Items)
{
<tr><td>#item.Name</td></tr>
<tr><td>#item.Total</td></tr>
}
<tr style="page-break-inside:avoid;">
<td colspan="2">
<table>
<tr>
<td>Total</td>
<td>#Model.Items.Sum(x => x.Total)</td>
</tr>
<tr>
<td>Discount</td>
<td>#(Model.Items.Sum(x => x.Total) / 50)</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
This allowed the footer to stay together while only appearing once at the end of the page.

HTML Table automatically starts splitting rows into new columns

My problem is that HTML table instead of displaying Rows vertically, after some rows it starts to put them into a new column automatically, in this order:
|Row1 | Row3 | Row4 |
|Row2 |
But I only need it to go vertically just in one column:
|Row1|
|Row2|
|Row3|...
Below my table's HTML code and how I am loading in data:
<table id="coinflip-table">
<tbody id="coinflip-list">
<tr>
#if (ViewBag.CoinflipAll != null)
{
foreach (CoinFlip.Main.Models.CoinflipViewModel cfGames in Model.Coinflips)
{
<td>
<img class="coinflip-list-avatar" src="#cfGames.User1_IconUrl" />
#if (cfGames.Status != 0)
{
<span class="coinflip-vs-player">VS</span>
<img class="coinflip-list-avatar" src="#cfGames.User2_IconUrl" />
}
</td>
<td class="coinflip-list-skins">
#if (ViewBag.WeaponBet != null)
{
foreach (CoinFlip.Main.Models.WeaponWebViewModel wep in ViewBag.WeaponBet)
{
<img class="coinflip-list-skins-small" title="#wep.Name" src="#wep.ImageUrl">
}
}
</td>
<td>
<span class="coinflip-value">$#cfGames.TotalValue</span>
</td>
<td></td>
<td>
<button class="coinflip-list-action" type="button" data-toggle="modal">WATCH</button>
</td>
}
}
</tr>
</tbody>
</table>
And I cannot seem to understand the cause of it. Is there a solution to this, just to go vertically? In JS, CSS or HTML? Or the issue can be related somewhere else?
Any help is appreciated,
Cheers
you need to include <tr> tag in loop to get row foreach list
or
if you need vertical row within a column try this!
<!-- Row -->
<tr>
<!-- Column -->
<td>
<!-- Row Within Column -->
<tr>
<td></td>
</tr>
</td>
</tr>
comment below if you have any questions?
If you need your table to be built vertically you have to put your foreach loop around < tr > < /tr > elements

Bootstrap datetimepicker issue instide a table-responsive class

I am using this (https://github.com/Eonasdan/bootstrap-datetimepicker) Date and time picker for my website, and when you open the datetime picker in a table-responsive class it does not show the date picker on top the table unless in the css you add .table-responsive { overflow:visible !important } in the css. Its all well and good doing this, but then when you shrink the screen or use it on a mobile / tablet, the table is no longer responsive and hangs off the side of the screen.
Please see this (https://jsfiddle.net/daza110/6abxn644/3/) fiddle which shows it opening correctly until you shrink the screen.
And please see this (https://jsfiddle.net/daza110/6abxn644/4/) fiddle which shrinks the table correctly, but does not show the calendar properly.
<div class="panel-body">
<div class="table-responsive">
<table class="table table-condensed table-hover table-striped text-center bgwhite" id="accountTable">
<thead>
<tr>
<th class="col-sm-2">Debt Ref</th>
<th class="col-sm-2">Due Date</th>
<th class="col-sm-2">Amount Paid</th>
<th class="col-sm-2">Account</th>
<th class="col-sm-2">Reconcile Date</th>
</tr>
</thead>
<tbody>
<tr class="armitage">
<td>
<div>NOR087-DAN052</div>
</td>
<td>
<div>05/01/2016</div>
</td>
<td>
<div>180.00</div>
</td>
<td>
<div class="col-sm-12">Paralegal (951)</div>
</td>
<td>
<div class="col-sm-12">
<input type="text" placeholder="Reconcile Date" name="dates[ifbZ6A4b6r568bad40cd473]" id="dates-ifbZ6A4b6r568bad40cd473" class="form-control ">
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
Jquery
jQuery('#dates-ifbZ6A4b6r568bad40cd473').datetimepicker({
format: "DD/MM/YYYY"
});
UPDATE
I hacked this but it isnt nice, I added a PHP function that attaches a DatePicker and then did the following jquery code, this removes the table-responsive and adds a temp class on show then on hide removes temp class and adds the table-responsive again:
function attachDatePick($fieldId)
{
?>
<script type="text/javascript">
jQuery(function()
{
jQuery('#<?echo $fieldId;?>').datetimepicker().on('dp.show',function()
{
jQuery(this).closest('.table-responsive').removeClass('table-responsive').addClass('temp');
}).on('dp.hide',function()
{
jQuery(this).closest('.temp').addClass('table-responsive').removeClass('temp')
});
});
</script>
<?
}
I don't understand too much what you need but is maybe this?
.table-responsive {
overflow-x: inherit;
}
See in this fiddle
easy way is setting position: static for datepicker wrapper. For instance
<td>
<div class="col-sm-12">
<input type="text" placeholder="Reconcile Date" name="dates[ifbZ6A4b6r568bad40cd473]" id="dates-ifbZ6A4b6r568bad40cd473" class="form-control ">
</div>
</td>
you can set .col-sm-12 {position: static}
I haven't found any answer about this question that really pleases.
So I adapted a another code for bootstrap dropdown with same problem inside .table-responsive
below is the main code, that I put on window:
window.setDatapickerEvents = ($parentElement) => {
$($parentElement).on('dp.show', function (e) {
const $e = $(e.target);
const $input = $e.find('input').first();
const $btn = $e.find('span.input-group-addon').first();
const $dropdownMenu = $e.find('.dropdown-menu');
const eOffset = $e.offset();
const btnWidth = $btn.outerWidth();
const inputWidth = $input.outerWidth();
const dropdownWidth = $dropdownMenu.outerWidth();
const dropdownHeight = $dropdownMenu.outerHeight();
$('body').append($dropdownMenu.detach());
$dropdownMenu.css({
'top': eOffset.top - dropdownHeight,
'left': eOffset.left + inputWidth + (btnWidth / 2) - dropdownWidth + 20,
'width': dropdownWidth,
'height': dropdownHeight,
});
});
$($parentElement).on('dp.hide', function (e) {
const $e = $(e.target);
const $dropdownMenu = $e.find('.dropdown-menu');
$e.append($dropdownMenu.detach());
$dropdownMenu.hide();
});
}
And to enable it inside scripts tag in your page
setDatapickerEvents('.table-responsive');
Before - Problem
After - Resolved
I hope it helps anyone

Table is getting too big

<table border="1" style="width:200px;">
<tr>
<td style="width:50px;overflow:hidden;">Who</td>
<td style="width:50px;overflow:hidden;">Time</td>
<td style="width:100px;overflow:hidden;">What</td>
</tr>
<?php
while($wr = mysqli_fetch_array($read)) {
echo' <tr>
<td>'.$wr['Who'].'</td>
<td>'.$wr['Time'].'</td>
<td>'.$wr['What'].'</td></tr>';
}
?>
$wr['What'] is pulling big data from database and my table is going over 200px. How can I fix it ?
You can use table-layout:fixed and it should force it...
style="width:200px;table-layout:fixed"
Here's a fiddle with appropriate css.
Use the max-width property in CSS on your td to set the maximum width of whatever you want
style='max-width:100px'

IE7 with rowspan when dynamically collapsing multiple rows (extra space at bottom)

I'm trying to dynamically hide/unhide multiple table rows using Javascript to mimic collapse/expand. here are relevant code snippets:
function selectionFilter(check, filter){
var elem = document.getElementById('myScrollTable').rows;
for(i = 0; i < elem.length; i++){
var type = elem[i].getAttribute('type');
if(type== filter){
if(check == true){
elem[i].style.display='';
}else{
elem[i].style.display='none';
}
}
}
}
and here is the sample HTML:
<input type="checkbox" checked="true" value="t1" onclick="selectionFilter(this.checked, this.value);">some type 1</input >
<input type="checkbox" value="t2" onclick="selectionFilter(this.checked, this.value);">some type 2</input ><br><br>
<table cellspacing="1" cellpadding="2" class="" id="myScrollTable">
<thead>
<tr>
<th>Data1</th>
<th>Data2</th>
</tr>
</thead>
<tbody>
<tr type="t1">
<td rowspan="50">something1</td><td>something2</td>
</tr>
<tr type="t1">
<td>something2</td>
</tr>
.
.
<tr type="t2" style="display:none;">
<td rowspan="50">something1</td><td>something2</td>
</tr>
<tr type="t2" style="display:none;">
<td>something2</td>
</tr>
.
.
</tbody>
</table>
In Firefox everything is fine. However in IE, after the first time any row is hidden, when it is unhidden it has some extra space appending at the bottom. This does not happen when rowspan is not used. I tried many things but couldn't get rid of the extra space.
I would truly appreciate if anyone could give me some hint.
Did you try using block instead of an empty string?
you should try using
elem[i].style.display = 'block';
and if this fails you should try
elem[i].style.display = 'table-row';
and allways you should check the w3schools documentation, its really usefull
http://www.w3schools.com/css/pr_class_display.asp
tellme if this works for you