Does HTML5 ban th cells from tbody? - asp.net-mvc

I have the following markup as a part of a Razor view:
<table>
<caption>Presidents</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Born</th>
<th scope="col">Died</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Washington</th>
<td>1732</td>
<td>1799</td>
</tr>
<!-- etc -->
</tbody>
</table>
With the "target schema for validation" set to HTML5, Visual Studio complains thusly:
Warning 1 Validation (HTML5): Element 'th' must not be nested within element 'tbody tfoot'.
Is this really true? If so, could someone link to the spec?
My understanding was that using <th> for row headers was not just legal but encouraged. It certainly seems fairly common, I could link dozens of tutorials explaining (seemingly sensibly) that it helps with accessibility.
Is this a VS bug? A real change coming with HTML5 (a good one? a bad one?)? What's the story?

My understanding was that using <th> for row headers was not just legal but encouraged
As far as I know, this was always legal in HTML 4 (and possibly its predecessors), and hasn't changed in HTML5.
W3C's HTML5 validator, while still experimental, reports no warnings or errors. Then again, I'm sure the HTML5 validation Visual Studio is using is experimental as well since HTML5 itself hasn't yet been finalized.
The HTML5 spec on marking up tabular data, specifically section 4.9.13, shows the use of <th> within <tbody> and <tfoot> to scope row data:
<table>
<thead>
<tr>
<th>
<th>2008
<th>2007
<th>2006
<tbody>
<tr>
<th>Net sales
<td>$ 32,479
<td>$ 24,006
<td>$ 19,315
<tr>
<th>Cost of sales
<td> 21,334
<td> 15,852
<td> 13,717
<tbody>
<tr>
<th>Gross margin
<td>$ 11,145
<td>$ 8,154
<td>$ 5,598
<tfoot>
<tr>
<th>Gross margin percentage
<td>34.3%
<td>34.0%
<td>29.0%
</table>
So it's perfectly legitimate to have <th> elements inside <tr> elements inside either a <tbody> or <tfoot>. As it should be anyway, since table headings aren't just found on table headers.

The HTML5 spec only requires that it be inside a tr, and the spec actually includes an example with a th nested inside a tbody.

Generally a TH in a THEAD will have a scope value of "col" while a TH in a TBODY will have a scope value of "row".

Related

Puppeteere/Chromium pdf printing ignores css page-breaks in tables

I was browsing the last hours to find a solution for my problem with latest puppeteer (2.0.0) / chromium 78.0.x to get our printing system working. We allow to setup page breaks in tables, which worked find in PhantomJS renderer, but not in the puppeteer/chromium solution.
Beside many little difference in global css and printing PDF header/footer the printing of tables was the last problem (hopefully).
It turns out that the "page-break-before: always" is simply ignored.
Example:
<table>
<thead> ... </thead>
<tbody> ...
<tr style="page-break-before: always;"> ...should be on next page ... </tr>
</tbody>
</table>
Some of the Chrome forum articles point out, this has been solved.
So the question is what is causing the problem.
Regards,
Andre
PS) Later we found now: put a "display: block" on all tags of the table solves the problem. Maybe that helps someone. Any comments on that?
<table style="display: block;">
<thead style="display: block;"> ... </thead>
<tbody style="display: block;"> ...
<tr style="display: block; page-break-before: always;"> ...is now on the next page ... </tr>
</tbody>
</table>
Bad news for the solution we provided above. This destroys the feature of having table headers on each page.
setup 1)
Setting "display: block;" for the thead will disable the feature of having the table header on each page.
==> no page break
setup 2)
Set the thead to "display: table-header-group;" and tbody to "table-row-group" then the chrome will ignore the page-breaks.
==> no table headers on each page
setup 3) Having the thead: "display: table-header-group;" and the tbody: "display: block" is destroying the column structure. The body will be rendered only on the first column.
==> Destroys the table. the body is just in the first column
Here comes our hack to solve the problem. we use setup 3, with this:
- we build a table with just one column
- the column contains a table with all columns we really want to render
- the column widths are set to fix values (that was anyway the case in our rendering system)
<table>
<thead>
<tr>
<td> <table> .... the header of the real table </table> </td>
</tr>
</thead>
<tbody style="display:block;">
<tr>
<td>
<table> .... one row of the real table </table>
<td>
</tr>
<tr>
<td>
<table> .... another row of the real table </table>
<td>
</tr>
</tbody>
</table>

Jquery DataTable not working properly

I'm using datatable plugin but having an issue with the sorting. default sorting order is asc and i want data in descending order when the page is loaded.
following is the script i'm using for initialization:
jQuery(document).ready(function(){
App.init();
});
also tried to use this
$('#sample_1').dataTable();
but it effects the menus. Menu sliders stops working and datatable also not working properly with this.
and there is no error in console.
Thanks
Without seeing your init code and HTML, we can't really point out what is going wrong.
If your table is visible before the DataTable is initialized, then you'll need to make sure it is sorted correctly in the original HTML.
When initializing the DataTable you'll want to set up the initial sorting - e.g. for descending sort on the first column:
$table = $("#sample_1").dataTable({
"aaSorting": [[0, 'desc']]
});
Here is the HTML:
<table class="table table-striped table-bordered adjust_table" style="table-layout:fixed;" id="sample_1"><thead>
<tr>
<th class="">Order ID</th>
<th class="">Name</th>
</tr>
</thead>
<tbody>
<tr>
<th class="">2001</th>
<th class="">John</th>
</tr>
<tr>
<th class="">2002</th>
<th class="">Marry</th>
</tr>
</tbody>
</table>
And following is the init code:
App.init();

Calculating total from a html table using Angular

I am really new with Angular and just finished the tutorial and my contact-list app. I would like to perform some simple calculations with rails generated html table using AngularJS on the client-side.
My table looks like this
<table>
<thead>
<tr>
<th>Group</th>
<th>Current</th>
<th>Previous</th>
<th>Difference %</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name</td>
<td>10</td>
<td>20</td>
<td>100%</td> //Want to use Angular
</tr>
</tbody>
<tr>
<td>Total:</td>
<td>10</td> //Want to use Angular
<td>20</td> //Want to use Angular
</tr>
</table>
I could write it with simple Javascript, however with time I would like these numbers to change styles, depending on the result, draw graphs, etc.
Please point me into the right direction! Thank you!

How to resize a long table attribute for a column

I have a long column attribute in my table, it is a token, and I want it to be displayed in two rows instead of one since the token is taking a lot of table space.
For example: "44b4bf4c01261542c9e34701fe435e55"
Code snippet:
<table class="table table-striped table-hover" id="admin_data_table">
<thead>
<tr>
<th>request</th>
</tr>
</thead>
<tbody>
<tr>
<td><%= #request.token %></td>
</tr>
<tbody>
</table>
How can I make this long value 44b4bf4c01261542c9e34701fe435e55 shorter for example to be like:
44b4bf4c012615
42c9e34701fe
435e55
You could use String's scan method to break it up into bits and then join it back together. Here's an example breaking it up into a maximum of 15 characters per line.
> str = "44b4bf4c01261542c9e34701fe435e55"
=> "44b4bf4c01261542c9e34701fe435e55"
> puts str.scan(/.{0,15}/).join("\n")
44b4bf4c0126154
2c9e34701fe435e
55
This is a frontend view concern. You should use HTML or CSS to deal with the width of the column instead of transforming the data itself.
You can do so by setting the HTML width, for example:
<table class="table table-striped table-hover" id="admin_data_table">
<thead>
<tr>
<th width='10%'>request</th>
</tr>
</thead>
<tbody>
<tr>
<td width='10%'><%= #request.token %></td>
</tr>
<tbody>
</table>
You could use css by:
admin_data_table .token-column { width: 10% }
Or if you still feel like transforming the data generated in the backend, you can split the token string with ruby like this:
<%= #token.each_slice(10) # will produce an array of chunks of 10 characters %>
I agree this is a front-end concern. You could try this in your css
table td
{
table-layout:fixed;
width:20%;
overflow:hidden;
word-wrap:break-word;
}
Hope that helps

How do I write VB Inline html templates in Razor?

I am struggling with writing in-line templates in razor vb.
Here is a sample forms c# version. Can someone translate to RAZOR vb?
<%Html.GridView<Employee>(
this.ViewData.Model,
data => { %>
<table class="grid" cellpadding="0" cellspacing="0">
<tr>
<th> </th>
<th> </td>
<th> </td>
<th>Name</th>
<th>E-mail</th>
</tr>
<% },
It does not appear, even in the latest Visual Studio, that this was supported, which is very unfortunate. It does seem templates are supported to some degree (as taken from this), but not for complex control setups like you have above. Bummer.

Resources