I am building an UI in angular application and need to do colspan for column called Subscriptions highlighted in the screenshot below. I tried applying colspan but doest seem to take effect.
What I need is something like this
Html
<tr>
<th class="tableItem bold">Legal Class Name</th>
<th class="tableItem bold">Last Edited</th>
<th class="tableItem bold">Legal Class ID</th>
<th class="tableItem bold"></th>
<th class="tableItem bold">TERMS</th>
<th class="tableItem bold">SUBSCRIPTIONS</th>
<th class="tableItem bold">Primary Currency</th>
</tr>
<ng-container>
<!-- <tr *ngFor="let f of fundClass['LegalFundClassDetailsViewModel'] | keyvalue"> -->
<tr *ngFor="let f of LegalFundClasses.LegalFundClassDetailsViewModel">
<td class="tableItem">{{f.Description}}</td>
<td class="tableItem"></td>
<td class="tableItem">{{f.Id}}</td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td colspan="5" class="tableItem"></td>
<td class="tableItem">
<kendo-dropdownlist style="width:100%" [(ngModel)]="f.CurrencyId"
class="form-control form-control-sm" [data]="Currencies"
[filterable]="false" textField="CURRENCY_NAME" [valuePrimitive]="true" valueField="CURRENCY_ID">
</kendo-dropdownlist>
</td>
</tr>
</ng-container>
</table>
What gets generated on on inspect of the element . I have shared it across three screenshots as it was difficult to capture in one
Screenshot 1 - The header section
Screenshot 2 - The row section - Expanded
Screenshot 3 - The row section - Collapsed
Screenshot 4 of the entire table in collapsed view
Edit
I have tried the pseudo code suggested by #cpcolella in angular but need to display as seen in the screenshot above in the post
So It should display
Legal Class Name Class A Class B Class C in one row
<div *ngIf="LegalFundClasses && LegalFundClasses.LegalFundClassDetailsViewModel && ColumnNames">
<table class="fundClassesTable table-striped">
<tr *ngFor="let c of ColumnNames">
<th class="tableItem bold">{{ c }}</th>
<ng-container *ngFor="let f of LegalFundClasses.LegalFundClassDetailsViewModel">
<td class="tableItem" *ngIf="c == ColumnNames[0]">{{f.Description}}</td>
<td class="tableItem" *ngIf="c == ColumnNames[1]">{{f.AuditSummary}}</td>
<td class="tableItem" *ngIf="c == ColumnNames[2]">{{f.Id}}</td>
</ng-container>
</tr>
</table>
</div>
</div>
Output of the logic above
You are generating the code wrong. I don't use angular, but the final table structure should look like this:
<table>
<tr>
<th class="tableItem bold">Legal Class Name</th>
<th class="tableItem">Class B</th>
<th class="tableItem">Class A</th>
<th class="tableItem">Class D</th>
<th class="tableItem">Class B</th>
<th class="tableItem">Class A</th>
<th class="tableItem">Class B1</th>
<th class="tableItem">Class C</th>
</tr>
<tr>
<td class="tableItem bold">Last edited</td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
</tr>
<tr>
<td class="tableItem bold">Legal class ID</td>
<td class="tableItem">123</td>
<td class="tableItem">123</td>
<td class="tableItem">123</td>
<td class="tableItem">123</td>
<td class="tableItem">123</td>
<td class="tableItem">123</td>
<td class="tableItem">123</td>
</tr>
<tr>
<td class="tableItem bold">Subscription</td>
<td colspan = "7"> </td>
</tr>
</table>
I've only generated 3 rows. As you can see, each row has 8 column (like yours), except the last one, that has only 2, with one of them spanning 7 columns.
You should not use a for cycle for generating all rows, as the subscription row is different.
You don't get to choose which direction tr and td go. tr is alwys a row. td and th are always cells that make a new column in that row. colspan lets one td or th take up multiple columns. Your table should prbasbly look something like this (though I am also not familiar with angular).
table {
border-collapse: collapse;
width: 100%;
}
table, td {
border: 1px solid black;
text-align: center;
padding: 5px;
}
th {
border: 1px solid black;
text-align: left;
padding: 5px;
}
tr:hover {background-color: #EFF3FB;}
td:nth-child(odd) {background-color: #E7EFFE;}
<table style="border-style: solid; border-width: 1px; padding: 25px;">
<tr>
<th class="tableItem bold">Legal Class Name</th>
<td class="tableItem">Class B</td>
<td class="tableItem">Class A</td>
<td class="tableItem">Class D</td>
<td class="tableItem">Class B</td>
<td class="tableItem">Class A</td>
<td class="tableItem">Class B1</td>
<td class="tableItem">Class C</td>
</tr>
<tr>
<th class="tableItem bold">Last edited</th>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
<td class="tableItem"></td>
</tr>
<tr>
<th class="tableItem bold">Legal class ID</th>
<td class="tableItem">11166</td>
<td class="tableItem">11167</td>
<td class="tableItem">13714</td>
<td class="tableItem">13717</td>
<td class="tableItem">13713</td>
<td class="tableItem">13716</td>
<td class="tableItem">13715</td>
</tr>
<tr>
<th class="tableItem bold">Subscription</th>
<td colspan = "7"> </td>
</tr>
</table>
https://stackoverflow.com/a/31408141/7724517
EDIT:
You'll need to have two loops. One through all of the horizontal headings and their associated field in the LegalClass object (outer) and one through all of the legal class objects (inner). The outer one will put the header item in first (for example: Legal Class Name) and the inner one will put the values for each legal class (in this example, the description). I hope this makes sense. This pseudo code is sort of like python.
FieldNames = {'Legal Class Name':'Description', 'Last Edited':'', 'Legal Class ID':'Id', 'TERMS':'', 'SUBSCRIPTIONS':'', 'Primary Currency':'CurrencyId'}
html = ""
foreach Field in FieldNames:
html += "<tr> <th class="tableItem bold">Field.Key</th>"
foreach LegalClass in LegalClassList:
html += "<td class="tableItem">LegalClass.Field.Value</td>""
html += "</tr>"
EDIT 2:
Something like this maybe. Again, I'm not proficient with angualar.
<table>
<ng-container>
<tr *ngFor="let Row of Rows">
<th class="tableItem bold">{{ Row.Header }}</th>
<td *ngFor="let LFC of LegalFinancialClass" class="tableItem"> {{ LFC.Row.Value }} </td>
</tr>
</ng-container>
</table>
Related
Hello i have a table and i want to center a th between two other th.
I want to change the position of th Vieillesse de base to be displayed in the center of Provisionnel and Régularisation.
Here my HTML :
<div class="row mt-1">
<div class="col-12">
<table class="table table-striped table-adjust ">
<thead class="cordonnes-cabinet">
<tr>
<th scope="col">Date</th>
<th scope="col" style="text-align:center" colspan="2">Vieillesse de base</th>
<th scope="col" style="text-align:right">Complémentaire</th>
<th scope="col" style="text-align:right">Total</th>
</tr>
<tr>
<th scope="col">...</th>
<th scope="col" style="text-align:right">Provisionnel</th>
<th scope="col" style="text-align:right">Régularisation</th>
<th scope="col" style="text-align:right">...</th>
<th scope="col" style="text-align:right">...</th>
</tr>
</thead>
<tbody class="cordonnes-cabinet">
#for (int i = 0; i < echeancierGeneriqueAjustee.Count; i++)
{
<tr>
<th style="font-weight:100">#(echeancierGeneriqueAjustee[i]["Date"])</th>
<td style="text-align:right">#(echeancierGeneriqueAjustee[i]["MontantProv"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[i]["MontantRegul"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[i]["MontantComplement"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[i]["TotalEcheance"])</td>
</tr>
}
<tr>
<th style="font-size:14px">Total</th>
<td style="text-align:right">#(echeancierGeneriqueAjustee[0]["TotalProv"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[0]["TotalRegul"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[0]["TotalComplement"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[0]["Total"])</td>
</tr>
</tbody>
</table>
</div>
</div>
The key to do this is use html colspan in the th, to simulate equality of width with the second row. Then you only need to use .text-center.
In you particular case, use colspan="2" in the second th
JS FIDDLE DEMO
<table class="table">
<thead class="cordonnes-cabinet">
<tr>
<th>Date</th>
<th colspan="2" class="text-center">Vieillesse de base</th>
<th>Complémentaire</th>
<th>Total</th>
</tr>
<tr>
<th style="width:10%">...</th>
<th class="text-center">Provisionnel</th>
<th class="text-center">Régularisation</th>
<th>...</th>
<th>...</th>
</tr>
</thead>
<tbbody>
<tr>
<th>col1</th>
<td class="text-center">col2</td>
<td class="text-center">col3</td>
<td>col4</td>
<td>col5</td>
</tr>
</tbbody>
</table>
So the issue here is that your text is centered but the Column to the right is X wide and creates a optical illusion that your column is a lot wider.
I would set the column saying "Complémentaire" to text-align: left with class text-left then it will create the illuion you want.
Ive attached a picture where you can see that your code actually centers the text its just an optical illuion
This is how it would look with left aligned in the blue column:
And now its just a question on how to make it pretier with paddings on the td's and th's
I have a table where I want to sort a column "BugId".
The inbuilt bootstrap sorting sorts in a particular fashion where ID-1 is followed by ID-11,then ID-12 and so on,(in an alphabetic fashion) whereas I want ID-1 to be followed by ID-2, then ID-3 ....ID-11 and so on.(in a numerical fashion)
This is how my table looks:
<table id="myTable" class="footable table table-striped toggle-arrow-tiny m-xxs" data-page-size="1000">
<thead>
<tr>
<th >Bug ID</th>
<th>Component</th>
<th data-sort-ignore="true">Report Date</th>
</tr>
</thead>
<tbody></tbody>
</table>
Can I change the sorting for only one column in this fashion?
<table data-toggle="table" id="myTable" class="footable table table-striped toggle-arrow-tiny m-xxs" data-page-size="1000">
<thead>
<tr>
<th data-field="bugid" data-sortable="true" data-sort-name="_bugid_data" data-sorter="bugidsorter" >Bug ID</th>
<th data-field="component" data-sortable="true" >Component</th>
<th data-sort-ignore="true">Report Date</th>
</tr>
</thead>
<tbody><tr>
<td data-bugid="1">id-1</td>
<td >x</td>
<td>11/12/2015</td>
</tr>
<tr>
<td data-bugid="2" >id-2</td>
<td >a</td>
<td>11/12/2015</td>
</tr>
<tr>
<td data-bugid="3">id-3</td>
<td >b</td>
<td>11/12/2015</td>
</tr>
<tr>
<td data-bugid="4">id-4</td>
<td >c</td>
<td>11/12/2015</td>
</tr>
<tr>
<td data-bugid="5">id-5</td>
<td >d</td>
<td>11/12/2015</td>
</tr>
<tr>
<td data-bugid="6">id-6</td>
<td >e</td>
<td>11/12/2015</td>
</tr>
<tr>
<td data-bugid="10">id-10</td>
<td >e</td>
<td>11/12/2015</td>
</tr>
</tbody>
</table>
sorting function
function bugidsorter(a, b) {
console.log(a);
if (a.bugid < b.bugid) return -1;
if (a.bugid > b.bugid) return 1;
return 0;
}
fiddle
I have this huge list of sport players (833) in a CSV file, with their name, team name, and stats.
I created a table that is responsive like this:
<table class="responsive-table" id="my-table">
<caption>AUDL Historical Stats</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Team</th>
<th scope="col">Plus/ Minus</th>
<th scope="col">Completions</th>
<th scope="col">Attempts</th>
<th scope="col">Comp %</th>
<th scope="col">Assists</th>
<th scope="col">Goals</th>
<th scope="col">Scores (G+A)</th>
<th scope="col">Drops</th>
<th scope="col">Blocks</th>
<th scope="col">Hockey Assists</th>
<th scope="col">Points Played</th>
<th scope="col">Games Played</th>
</tr>
</thead>
<tbody>
/* PLAYER ONE */
<tr>
<th scope="row"></th>
<td data-title="Team"></td>
<td data-title="Plus/ Minus" data-type="double"></td>
<td data-title="Completions" data-type="double"></td>
<td data-title="Attempts" data-type="double"></td>
<td data-title="Comp %" data-type="double"></td>
<td data-title="Assists" data-type="double"></td>
<td data-title="Goals" data-type="double"></td>
<td data-title="Scores (G+A)" data-type="double"></td>
<td data-title="Drops" data-type="double"></td>
<td data-title="Blocks" data-type="double"></td>
<td data-title="Hockey Assists" data-type="double"></td>
<td data-title="Points Played" data-type="double"></td>
<td data-title="Games Played" data-type="double"></td>
</tr>
/* PLAYER TWO */
...
</tbody>
</table>
Instead of Copy and pasting the data one at a time. Is there a way to export with adding the "data-title" and "data-type" to the td tags, and scope="row" to the th tag for each player?
Any help is appreciated!
A table on my site has been flagged by an accessibility plugin (aXe). After some tinkering, it ended up saying that I had to fix the following two things:
<th> elements should only be used when there is a single row and
single column of headers
Table has cells whose rowspan attribute is not equal to 1
How can I reasonably build a table with nested levels of information without violating at least one of those?
My table code is:
<table>
<tbody>
<tr>
<th scope="col" rowspan="2">Type Of</th>
<th scope="col" colspan="2">Blue</th>
<th scope="col" colspan="2">Green</th>
</tr>
<tr>
<td scope="col" class="centered">Light Blue</td>
<td scope="col" class="centered">Dark Blue</td>
<td scope="col" class="centered">Light Green</td>
<td scope="col" class="centered">Dark Green</td>
</tr>
<tr>
<th scope="row">Type 1</th>
<td class="centered">Y</td>
<td class="centered">Y</td>
<td class="centered">Y</td>
<td class="centered">N</td>
</tr>
<tr>
<th scope="row">Type 2</th>
<td class="centered">Y</td>
<td class="centered">Y</td>
<td class="centered">Y</td>
<td class="centered">N</td>
</tr>
<tr>
<th scope="row">Type 3</th>
<td class="centered">Y</td>
<td class="centered">Y</td>
<td class="centered">Y</td>
<td class="centered">N</td>
</tr>
</tbody>
</table>
Accessibility tools are free to invent their own rules, but this tool is wrong saying you should remove table headers th when you use rowspan or colspan. It's totally wrong. Check that you have the last version of this tool : this is an awful advice.
In your case, you can use the following technique to mark column headers:
H43: Using id and headers attributes to associate data cells with header cells in data tables
Your have one problem in your example:
Your headers in your second line are not marked as column headers (th) (and headers attribute should only reference th with id).
You markup should be something like:
<table>
<thead>
<tr>
<th rowspan="2" id="typeof">Type Of</th>
<th colspan="2" id="blue">Blue</th>
<th colspan="2" id="green">Green</th>
</tr>
<tr>
<th id="lightblue">Light</th>
<th id="darkblue">Dark</th>
<th id="lightgreen">Light</th>
<th id="darkgreen">Dark</th>
</tr>
</thead>
<tbody>
<tr>
<th id="type1" headers="typeof">Type 1</th>
<td headers="type1 lightblue" title="Yes">Y</td>
<td headers="type1 darkblue" title="Yes">Y</td>
<td headers="type1 lightgreen" title="Yes">Y</td>
<td headers="type1 darkgreen" title="No">N</td>
</tr>
<tr>
<th id="type2" headers="typeof">Type 2</th>
<td headers="type2 lightblue" title="Yes">Y</td>
<td headers="type2 darkblue" title="Yes">Y</td>
<td headers="type2 lightgreen" title="Yes">Y</td>
<td headers="type2 darkgreen" title="No">N</td>
</tr>
<tr>
<th id="type3" headers="typeof">Type 3</th>
<td headers="type3 lightblue" title="Yes">Y</td>
<td headers="type3 darkblue" title="Yes">Y</td>
<td headers="type3 lightgreen" title="Yes">Y</td>
<td headers="type3 darkgreen" title="No">N</td>
</tr>
</tbody>
</table>
Also, I added a title attribute in order to add a speakable alternative for screen readers (you could have used aria-label but title adds a tooltip for other people, except it is not keyboard friendly). Better choice would be to have here a full word.
I'm not sure what tool you are using, but have you tried using col and colgroup elements? There is some basic information here from W3C about irregular headers in data tables.
Also, I put together a quick JSFiddle based on your table if you want to look at that: https://jsfiddle.net/dngvc84o/
I am trying to shrink one cell in the table, but it refuses to shring..here is my table.
<table cellspacing="0" style="position: absolute;width: 990px;margin-left: 8px;" align="center">
<thead>
<tr class='no-wrap'>
<th width="20%"></th>
<th width="10%">Our Rating</th>
<th width="10%">Users' Rating</th>
<th width="30%">Review</th>
<th width="30%">Price</th>
</tr>
</thead>
<tbody>
<tr>
<td width="20%"></td>
<td width="10%">Our Rating</td>
<td width="10%">Users' Rating</td>
<td width="30%">Review</th>
<td width="30%">Price</td>
</tr>
</tbody>
</table>
The problem is that the review part doesnt shrink..even when I give it a lower percentage..why is that?
You have incorrect HTML syntax.
You need to wrap your table row elements in tr:
<tbody>
<tr>
<td></td>...
</tr>
</tbody>
Also you have a </th> where you should have a <td> on your 2nd row, 4th cell (Review):
<td width="30%">Review</th>