I have a is-fullwidth Bulma table in my angular7 app which works fine. But now I need to add a angular component inside each row, and td tags lies inside that component. But when I do that, table rows not spans to its full width.
<table class="table is-fullwidth">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of rows">
<app-table-row [details]="row">
</app-table-row>
</tr>
</tbody>
</table>
table-row.component.html
<td>
<div *ngIf="!showField"> {{ details.name }} </div>
<div *ngIf="showField" class="field">
<div class="control">
<input [value]="details.name" class="input" type="text">
</div>
</div>
</td>
<td>{{ details.address }}</td>
This outputs the following
if I remove the angular component and add tds normally, it spans correctly. Like this.
Why is it not work when angular component added? And how should I fix it?
The reason this is happening is probably because the td elements are not direct children of the tr, but children of the app-table-row component.
Not sure that it would make sense in your case, but you can change the selector property in the app-table-row component to select the tr itself, like so:
#Component({
selector: 'tr[app-table-row]',
...
})
export class AppTableRowComponent {}
And use it like this:
<table class="table is-fullwidth">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of rows" app-table-row [details]="row">
</tr>
</tbody>
</table>
This way the app-table-row is not a separate node in the DOM.
Related
I'm trying to create (using Semantic-UI and knockoutjs) a data table where each row has an expandable item (accordion) to show a sub-table of data related to the expanded row.
I have tried to use colspan="4" on my sub-table's <td> element, to no avail. No matter what I try, the sub-table seems to only exist within the first column of the parent table. The jsfiddle below demonstrates the issue better than my description, I'm sure.
https://jsfiddle.net/xpvt214o/908333/
This may be a simple CSS issue -- I'm no expert -- but nothing I've tried works for me. I also tried wrapping the sub-table as a <div>, but that seemed to break the accordion from collapsing.
<table class="ui celled table accordion">
<thead><tr>
<th ></th>
<th >ID</th>
<th>Name</th>
<th >FK1 ID</th>
<th >FK2 ID</th>
</tr></thead>
<tbody data-bind="foreach: arrayVM">
<tr class="ui title">
<td><i class="dropdown icon"></i></td>
<td data-bind="text: id"></td>
<td data-bind="text: name"></td>
<td data-bind="text: fk1id"></td>
<td data-bind="text: fk2id"></td>
</tr>
<tr style="display:none">
<td colspan="5" class="ui content">
<table class="ui inverted celled table" style="width:700px">
<tbody>
<tr>
<td><i class="ui logo add icon"></i></td>
<td data-bind="text: id"></td>
<td>column2</td>
<td>column3</td>
<td>column4</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
I have a responsive table where the end column shows money figures. Currently it looks like this:
But I want it to do this:
There may not be any data so the £ sign will be replace with N/A which should also be pulled to the right of the column.
The data is fetched from MySQL but here is a simplified snippet of my code:
<table id="mytable" class="table table-bordred table-striped">
<thead>
<th>Reference</th>
<th>Client</th>
<th>Description</th>
<th>Money</th>
</thead>
<tbody>
<tr>
<td>#1234</td>
<td>Josh Blease</td>
<td>Needs a new filter fixing</td>
<td class='money'>
<div class='text-right'>Budget: £123,456</div>
<div class='text-right'>Value: £200,000</div>
<div class='text-right'>Spent: N/A</div>
</td>
</tr>
</tbody>
Divs are useful but Ii don't think that be the best solution for this case maybe you need to use better the table properties
http://www.usabilidad.tv/tutoriales_html/colspan_y_rowspan.asp
<table id="mytable" class="table table-bordred table-striped">
<thead>
<th>Reference</th>
<th>Client</th>
<th>Description</th>
<th colspan="2">Money</th>
</thead>
<tbody>
<tr>
<td rowspan="4">#1234</td>
<td rowspan="4">Josh Blease</td>
<td rowspan="4">Needs a new filter fixing</td>
</tr>
<tr>
<td>Budget</td>
<td>£123,456</td>
</tr>
<tr>
<td>Value</td>
<td>£200,000</td>
</tr>
<tr>
<td>Spent</td>
<td>N/A</td>
</tr>
</tbody>
</table>
<table id="mytable" class="table table-bordred table-striped">
<thead>
<th>Reference</th>
<th>Client</th>
<th>Description</th>
<th>Money</th>
</thead>
<tbody>
<tr>
<td>#1234</td>
<td>Josh Blease</td>
<td>Needs a new filter fixing</td>
<td class='money'>
<div class='text-right'><span>Budget:</span> £123,456</div>
<div class='text-right'><span>Value:</span> £200,000</div>
<div class='text-right'><span>Spent:</span> N/A</div>
</td>
</tr>
</tbody>
and
#mytable tbody tr td .text-right span{
min-width:200px;
max-width:300px;
display: inline-block;
}
Spans need to be set as inline-block otherwise the width properties won't take hold as they are by default inline only elements.
Setting the min and max width will force the span container to not go below or above a certain point, meaning that your other text will be forced to stay to the left of the (example) 200px mark even if your initial text (as in spent) only ends up being (again, example) 80px
How do you set the size of a column in a Bootstrap responsive table? I don't want the table to loose its reponsive features. I need it to work in IE8 as well. I have included HTML5SHIV and Respond.
I'm using Bootstrap 3 (3.2.0)
<div class="table-responsive">
<table id="productSizes" class="table">
<thead>
<tr>
<th>Size</th>
<th>Bust</th>
<th>Waist</th>
<th>Hips</th>
</tr>
</thead>
<tbody>
<tr>
<td>6</td>
<td>79 - 81</td>
<td>61 - 63</td>
<td>89 - 91</td>
</tr>
<tr>
<td>8</td>
<td>84 - 86</td>
<td>66 - 68</td>
<td>94 - 96</td>
</tr>
</tbody>
</table>
</div>
Bootstrap 4.0
Be aware of all migration changes from Bootstrap 3 to 4. On the table you now need to enable flex box by adding the class d-flex, and drop the xs to allow bootstrap to automatically detect the viewport.
<div class="container-fluid">
<table id="productSizes" class="table">
<thead>
<tr class="d-flex">
<th class="col-1">Size</th>
<th class="col-3">Bust</th>
<th class="col-3">Waist</th>
<th class="col-5">Hips</th>
</tr>
</thead>
<tbody>
<tr class="d-flex">
<td class="col-1">6</td>
<td class="col-3">79 - 81</td>
<td class="col-3">61 - 63</td>
<td class="col-5">89 - 91</td>
</tr>
<tr class="d-flex">
<td class="col-1">8</td>
<td class="col-3">84 - 86</td>
<td class="col-3">66 - 68</td>
<td class="col-5">94 - 96</td>
</tr>
</tbody>
</table>
bootply
Bootstrap 3.2
Table column width use the same layout as grids do; using col-[viewport]-[size]. Remember the column sizes should total 12; 1 + 3 + 3 + 5 = 12 in this example.
<thead>
<tr>
<th class="col-xs-1">Size</th>
<th class="col-xs-3">Bust</th>
<th class="col-xs-3">Waist</th>
<th class="col-xs-5">Hips</th>
</tr>
</thead>
Remember to set the <th> elements rather than the <td> elements so it sets the whole column. Here is a working BOOTPLY.
Thanks to #Dan for reminding me to always work mobile view (col-xs-*) first.
You could use inline styles and define the width in the <th> tag. Make it so that the sum of the widths = 100%.
<tr>
<th style="width:10%">Size</th>
<th style="width:30%">Bust</th>
<th style="width:50%">Waist</th>
<th style="width:10%">Hips</th>
</tr>
Bootply demo
Typically using inline styles is not ideal, however this does provide flexibility because you can get very specific and granular with exact widths.
you can use the following Bootstrap class with
<tr class="w-25">
</tr>
for more details check the following page
https://getbootstrap.com/docs/4.1/utilities/sizing/
I have a table that has a radio button in on td element, however i am unable to set the width (my page is in HTML5 so using the style css attribute to set the width).
My row is as follows:
<h3><span data-bind="text: description"></span></h3>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th colspan="2">Description</th>
<th>Setup</th>
<th>Monthly</th>
</tr>
</thead>
<tbody>
<!-- ko foreach: options -->
<tr>
<td style="width:16px"><input type="radio" data-bind=" attr: { name: $parent.name }, checkedValue: $data, checked: $parent.selection" /></td>
<td><span data-bind="text: description"></span></td>
<td><span data-bind="text: setup == 0 ? '-' : setup"></span></td>
<td><span data-bind="text: price == 0 ? '-' : price"></span></td>
</tr>
<!-- /ko -->
</tbody>
</table>
In fact all of the rows are 154px wide, each row is equal.
Don't worry about the data-bind attributes, i am using knockoutjs. I am using bootstrap for the stlying, but cant see any column widths applied fron the bootstrap CSS.
I have take a screenshot of chrome below:
Edit and further info
After looking at the fiddle from #daker's comment here http://jsfiddle.net/g18c/Lnvny/, i could see the width was applied OK.
When going over my code, i have a thead section which is causing the issue, this is not present in the above fiddle.
Adding the below thead section to the fiddle stops the widths from applying on the td element, updated here http://jsfiddle.net/g18c/Lnvny/2/
<thead>
<tr>
<th colspan="2">Description</th>
<th>Setup</th>
<th>Monthly</th>
</tr>
</thead>
If i set the width in the th element with <th colspan="2" style="width:20px">Description</th> it sizes, so the td elements are following the width of the td, which makes sense.
However the description spans across 2 columns with colspan="2" which consists of both the first td with radio, and second td with the text description data-bind in the tbody.
Is there any way to keep the th colspan=2 in the thead, yet set the width of the radio button td=16px in tbody?
set width for second column as auto:
http://jsfiddle.net/Lnvny/46/
<h3><span data-bind="text: description"></span></h3>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th colspan="2">Description</th>
<th>Setup</th>
<th>Monthly</th>
</tr>
</thead>
<tbody>
<!-- ko foreach: options -->
<tr>
<td style="width: 15px;"><input type="radio" data-bind=" attr: { name: $parent.name }, checkedValue: $data, checked: $parent.selection" /></td>
<td style="width: auto;">text<span data-bind="text: description"></span></td>
<td style="width: 25%;"><span data-bind="text: setup == 0 ? '-' : setup"></span></td>
<td style="width: 25%;"><span data-bind="text: price == 0 ? '-' : price"></span></td>
</tr>
<!-- /ko -->
</tbody>
</table>
16px+40%+25%+25% is not 100%.
You can't mix px and % this way, the table rendering algorithm can't satisfy such conditions...
As mali303 said, you could set the second td to auto, or even simpler: Don't set its width. The last two colums will be 25% width, the first 16px width and all the remaining space will go for the second column (and 1st td + 2nd td will be 50%)
You could also go the simpler way:
Use 3 columns (50%,25%,25%), remove th colspan, and join the content of your 2 first columns
(both are inline elements):
<td style="width: 50%;">
<input type="radio" data-bind="..." />
<span data-bind="text: description"></span>
</td>
<td style="width:1px"><div style="width:16px"><input type="radio" data-bind=" attr: { name: $parent.name }, checkedValue: $data, checked: $parent.selection" /></div></td>
Add an empty <th></th> in your <thead> section:
http://jsfiddle.net/Lnvny/48/
<table>
<thead>
<tr>
<th colspan="2">Description</th>
<th>Setup</th>
<th>Monthly</th>
<th></th>
</tr>
</thead>
I have a three column layout, in which I have two tables connected back to back in the third column:
<div class="span2">
..
</div>
<div class="span7">
..
</div>
<div class="span3">
<h4>Betslips: </h4>
<table class="table table-stripped table-hover table-condensed" id="RecentContests">
<caption class="text-left">My Backs</caption>
<thead>
<tr></tr>
</thead>
<tbody>
<tr class ="success">
<td>King Rama</td>
<td>4.5</td>
<td>1000$</td>
<td>3500$</td>
<td>Matched</td>
<td>X</td>
</tr>
<tr class ="success">
<td>The Favorite</td>
<td>1.5</td>
<td>550$</td>
<td>750$</td>
<td>Matched</td>
<td>X</td>
</tr>
</tbody>
</table>
<table class="table table-stripped table-hover table-condensed">
<caption class="text-left">My Lays</caption>
<tbody>
<tr class ="error">
<td>Dare Devil</td>
<td>4.5</td>
<td>1000$</td>
<td>3500$</td>
<td>Pending</td>
<td>X</td>
</tr>
<tr class ="error">
<td>Irish Win</td>
<td>5.5</td>
<td>150$</td>
<td>2500$</td>
<td>Pending</td>
<td>X</td>
</tr>
</tbody>
</table>
When opened in browser it computes different widths for the tables, according to me it should be the same, any idea why is it happening and how to prevent it? I would like the second table to be the same width as of the first one.
By default, the tables will only be wide enough to accommodate their content, so there's little chance of them being the same width. To make them display the same width, consider setting a width via CSS. E.g.
table {width: 600px;}
or
table {width: 100%;}
You can also make the tables look more even and alike by adding
table {table-layout: fixed;}
It could be the span3 class in on the div, I've seen bootstrap, you might want to just size the table yourself.