Calculating total from a html table using Angular - ruby-on-rails

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!

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>

Conditionally render tags to different views?

Am using a view with table (simple html tags) one like below to render in to two different views.
This table is inside MVC views>shared folder so does indicating its used by two different views.
View-1 needs all columns to display; But view-2 doesn't need column "Delete". How to conditionally render this shared (table-view) view showing only columns that the asking view needs?
<table id="example" class="display" style="min-width: 100%">
<thead>
<tr>
<th>Item</th>
<th>ItemDesc</th>
<th>UM</th>
<th>Qty</th>
<th>Category</th>
<th>Comment</th>
<th>Delete</th> /*View-2 don't need this*/
</tr>
</thead>
<tbody>
#foreach (var model in Model){
data goes here for respective <th> as <td> by getting from a model
<td>model.Item</td>
<td>model.ItemDesc</td>
<td>model.UM</td>
<td>model.Qty</td>
<td>model.Category</td>
<td>model.Comment</td>
<td>model.Delete</td> /*View-2 don't need this*/
}
</tbody>
How to do this in ASP MVC 5 views?
You can just store a token value inside Viewbag or Tempdata as :
#Viewbag.show="no";
if(#Viewbag.show!="no"){
<td>model.Delete</td>
}
else{
<td></td>
}
One of the solution is pass the additional information in the modal of the view like this
if(modal.EnableDelete)
<td>Delete</td>

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();

Is it possible to modify ASP.NET MVC WebGrid so that it doesn't look like a regular grid table?

I need to render a table that doesn't look like a regular grid table, where for one entry, which would be a row in a typical table, columns 1 and 2 values can be put in row 1, columns 3, 4 and 5 values will be in row 2, and so on like so:
<table id="display_searchresults_student">
<tr>
<th rowspan="4"><img src="../../Images/picture_temp.jpg" id="display_searchresults_studentpicture"/></th>
<td id="display_searchresults_studentname">**Name Column**
<img src="../../Images/picture_temp.jpg" height="25px" width="25px"/>
</td>
<td align="right" width="100px">Rating Column</td>
</tr>
<tr>
<td id="display_searchresults_studentlocation">City Column, State Column | University Column</td>
<td></td>
</tr>
<tr>
<td id="display_searchresults_studentinfo">Department Column | School Standing Column Graduation Date Column | GPA Column</td>
<td></td>
</tr>
<tr>
<td id="display_searchresults_studentdesc" colspan="2">Comments Column...</td>
</tr>
</table>
This table will have multiple entries. The reason why I thought of using a WebGrid is because I need the sorting, filtering and paging capability. I now that Telerik allows constructing tables like that. However, I'm not seeing how to do it through the WebGrid. Is there a way to change the Webgrid's HTML prior to it being rendered without breaking the sorting, filtering and paging capabilities? Does jqGrid or other open-source grids allow to do something like that?
Thanks a lot in advance.
It's hard to tell what you are talking about without an example, but what about Masonry?

Does HTML5 ban th cells from tbody?

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".

Resources