How can i format my data like this in table - html

I have a dynamic data where they have the same floornumber, so i wanna do is every data have a same number will be under a row on their floor. I want to make every row theirs a row, and then under all of that is their units. Is their any library for that? Thanks
const data = [
{floornumber: 1, unitname: '101', unitype: 'basic'},
{floornumber: 1, unitname: '102', unitype: 'basic'},
{floornumber: 1, unitname: '103', unitype: 'basic'},
{floornumber: 2, unitname: '203', unitype: 'basic'},
{floornumber: 2, unitname: '203', unitype: 'basic'}
]
<table>
<thead>
<th>
Floor
</th>
<th>
Unit Name
</th>
<th>
Unit Type
</th>
</thead>
<tbody>
<tr>
<td>1</td>
</tr>
<tr>
<td>blank</td>
<td>101</td>
<td>Basic</td>
</tr>
<tr>
<td>blank</td>
<td>102</td>
<td>Basic</td>
</tr>
<tr>
<td>blank</td>
<td>103</td>
<td>Basic</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>blank</td>
<td>203</td>
<td>Basic</td>
</tr>
<tr>
<td>blank</td>
<td>203</td>
<td>Basic</td>
</tr>
</tbody>
</table>

I don't think there is a library for this because it is a very unique way to present the data.
You must make sure, your data is sorted by floor number. Then I would read the first line and create row set a:
<tr>
<td>1</td>
</tr>
<tr>
<td>blank</td>
<td>101</td>
<td>Basic</td>
</tr>
loop through your data and create row set b:
<tr>
<td>blank</td>
<td>102</td>
<td>Basic</td>
</tr>
until the floor number changes. In this case create row set a again and so on until you are at the end of the data.

Related

table with one header and data from Array inside a Map with thymeleaf

I want to create a table that its data is a Map< String, List < Object> >.
So the table has one header that and the rows should have the exact data.
Map.key
Object.item1
Object.item2
Object.item3
So since it is a List of Object i want one row for every Object of the List and the Map.key to be repeated.
So i need to iterate through keys like
<table>
<thead>
<tr>
<th>Code</th>
<th>Status</th>
<th>Flag</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<tr th:each= "result : ${myMap}">
<td th:text="${result.key}"></td>
<td><table>
<tr th:each="obj: ${result.value}">
<td th:text="${not #lists.isEmpty(obj.errorList)}?'Error':'Warning'"></td>
<td th:text="${obj.flag}==true?'YES':'NO'"></td>
<td th:text="${not #lists.isEmpty(obj.errorList)}?${obj.warningList}:${obj.errorList}"></td>
</tr>
</table></td>
</tr>
</tbody>
</table>
but this solution places a table in a table. I want to use one header and iterate the lists and place the variables in the main table .
I think you're looking for a structure like this:
<table>
<thead>
<tr>
<th>Code</th>
<th>Status</th>
<th>Flag</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<th:block th:each= "result : ${myMap}">
<tr th:each="obj: ${result.value}">
<td th:text="${result.key}" />
<td th:text="${not #lists.isEmpty(obj.errorList)}?'Error':'Warning'" />
<td th:text="${obj.flag}==true?'YES':'NO'" />
<td th:text="${not #lists.isEmpty(obj.errorList)}?${obj.warningList}:${obj.errorList}" />
</tr>
</th:block>
</tbody>
</table>

How to xpath values in a dynamic table?

Could please someone help me to xpath values in a dynamic table.
I have the following HTML code and I need to select the values of the cells, as for example:
if a tr-cell contains the text "Values1" then select the first value (0) in td / third value (1) in td of this cell
I would be very thankful.
<table class="DynamicTable">
<tbody>
<tr>
<th>Details</th>
</tr>
<tr>
<td>0</td>
<td>Values1</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>Values2</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>Values6</td>
<td>0</td>
</tr>
</tbody>
</table>

Get Elements from IE Table via VBScript

I'm having some problems getting the elements I need from a web page table. The example code from the table is:
<tr>
<td colspan="11" class="anscalls">Answered Calls</td>
</tr>
<tr class="daterow">
<td>01/01/2001</td>
<td colspan="10"> </td>
</tr>
<tr class="item">
<td>User 1</td>
<td>#</td>
</tr>
<tr class="daterow">
<td>02/01/2001</td>
<td colspan="10"> </td>
</tr>
<tr class="changeditem">
<td>User 1</td>
<td>#</td>
</tr>
<tr class="changeditem">
<td>User 2</td>
<td>#</td>
</tr>
<tr class="daterow">
<td>03/01/2001</td>
<td colspan="10"> </td>
</tr>
<tr class="item">
<td>User 1</td>
<td>#</td>
</tr>
<tr class="daterow">
<td>04/01/2001</td>
<td colspan="10"> </td>
</tr>
<tr class="changeditem">
<td>User 1</td>
<td>#</td>
</tr>
<tr class="changeditem">
<td>User 2</td>
<td>#</td>
</tr>
<tr class="changeditem">
<td>User 3</td>
<td>#</td>
</tr>
<tr class="daterow">
<td>05/01/2001</td>
<td colspan="10"> </td>
</tr>
<tr class="item">
<td>User 1</td>
<td>#</td>
</tr>
I'm able to get the information between the "changeditem" class, which is what I need, but I also need the information from the "daterow" class to go along with the "changeditem" information. I'm currently using the following code:
For j = 0 To (.Document.getElementsByClassName("changeditem").Length - 1)
MsgBox .Document.getElementsByClassName("changeditem").Item((j + 0)).InnerText & Chr(44) & _
.Document.getElementsByClassName("changeditem").Item((j + 1)).InnerText
j = j + 1
Next
Which Outputs:
User1,#
User2,#
User1,#
User2,#
User3,#
I would need to loop through the entire table, which is much bigger than shown, and get the "daterow" class relevant to the "changeditem" classes, which I cannot figure out how to do.
What I'm aiming to get is:
02/01/2001,User 1,#
02/01/2001,User 2,#
04/01/2001,User 1,#
04/01/2001,User 2,#
04/01/2001,User 3,#
Thanks in advance.
Not a VBScript answer, but jQuery exists specifically for this kind of DOM manipulation and is very widely used, so I'll suggest it anyway. Using jQuery you could do something like the following. I am by no means fluent in jQuery and this will not output the exact desired output, but it illustrates the idea. You could
do all of this with standard DOM methods, jQuery just makes it much easier.
<script>
$(function() {
// get a reference to all changeditem rows
var $changedItem = $('tr.changeditem');
// loop the results
$changedItem.each(function() {
// contents of first td in tr
console.log( $(this).children('td').first().text());
// if there is a sibling tr daterow, get a reference
var $dateRow = $(this).next('tr.daterow');
// contents of first td in tr
console.log( $dateRow.children('td').first().text());
});
});
</script>

Parsing htmlagilitypack (table without id's) vb.net

Hope to get some answers from you.
I use vb.net and htmlagilitypack to fetch data and it works, but not the way I want it to =)
I have this html page (part of):
<TABLE WITH=100% BORDER=4>
<TR>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=Lok" >Lok</A></TH>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=Avg" >Avgår</A></TH>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=AvgS" >Station</A></TH>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=Ank" >Ankommer</A></TH>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=AnkS" >Station</A></TH>
<TH>Tjänstetyp</TH>
</TR>
<TR>
<TD>R1176</TD>
<TD>Mar-20-2013 13:04:00</TD>
<TD>HBGB</TD>
<TD>Mar-20-2013 21:21:00</TD>
<TD>ET3</TD>
<TD>B1</TD>
</TR>
<TR>
<TD>R1267</TD>
<TD>Mar-20-2013 13:04:00</TD>
<TD>HBGB</TD>
<TD>Mar-20-2013 21:21:00</TD>
<TD>ET3</TD>
<TD>B2</TD>
</TR>
<TR>
<TD>R1267</TD>
<TD>Mar-20-2013 22:05:00</TD>
<TD>ET3</TD>
<TD>Mar-20-2013 22:28:00</TD>
<TD>KBÄ</TD>
<TD>D1</TD>
</TR>
<TR>
<TD>R1281</TD>
<TD>Mar-21-2013 13:04:00</TD>
<TD>HBGB</TD>
<TD>Mar-21-2013 21:21:00</TD>
<TD>ET3</TD>
<TD>D1</TD>
</TR>
<TR>
<TD>R1281</TD>
<TD>Mar-21-2013 22:05:00</TD>
<TD>ET3</TD>
<TD>Mar-21-2013 22:28:00</TD>
<TD>KBÄ</TD>
<TD>B2</TD>
</TR>
<TR>
<TD>RXXXXX</TD>
<TD>Mar-21-2013 22:05:00</TD>
<TD>ET3</TD>
<TD>Mar-21-2013 22:28:00</TD>
<TD>KBÄ</TD>
<TD>B1\B2</TD>
</TR>
<TR>
<TD>R1281</TD>
<TD>Mar-25-2013 13:04:00</TD>
<TD>HBGB</TD>
<TD>Mar-25-2013 21:21:00</TD>
<TD>ET3</TD>
<TD>D1</TD>
</TR>
<TR>
<TD>R1281</TD>
<TD>Mar-25-2013 22:05:00</TD>
<TD>ET3</TD>
<TD>Mar-25-2013 22:28:00</TD>
<TD>KBÄ</TD>
<TD>D1</TD>
</TR>
<TR>
<TD>R1254</TD>
<TD>Mar-27-2013 13:04:00</TD>
<TD>HBGB</TD>
<TD>Mar-27-2013 21:21:00</TD>
<TD>ET3</TD>
<TD>B2</TD>
</TR>
<TR>
<TD>RXXXXX</TD>
<TD>Mar-27-2013 13:04:00</TD>
<TD>HBGB</TD>
<TD>Mar-27-2013 21:21:00</TD>
<TD>ET3</TD>
<TD>B1\B2</TD>
</TR>
</TABLE>
<A><A>Senast uppdaterad: Mar-20-2013 18:16:00</A><BR>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<TR>
<TD width="20%" bgcolor="#009900" align="left">
<IMG src="http://litmgc101.greencargo.com/bottenbild.jpg" alt="Green Cargo" width=800 height=25 border=0>
</TD>
</TR>
<TR>
</table>
What I want to do is to fetch the parts with (for example) "R1176" and the date "Mar-20-2013 13:04:00". (Would prefer to NOT have the time "13:04:00"), but I can delete that in VB.net later if I can't skip it in the parsing phase.
So to simply explain what I want to do is following:
Get all the "R1234" and the date that comes with it then put it in let's say a textbox for the "R4321" and another textbox for the date or something.
In C# I'd do something like this:
var result =
doc.DocumentNode.SelectNodes("//td/a[contains(#href,'Lokindivid')]")
.Select(node => new KeyValuePair<string, DateTime>(node.InnerText, DateTime.Parse(node.SelectSingleNode("./ancestor::tr[1]/td[2]").InnerText).Date));
My VB.NET foo resulted in the following code (which is a literal translation) which works with the sample html you provided:
Dim doc As New HtmlDocument
doc.LoadHtml(Content.Html)
Dim items = doc.DocumentNode.SelectNodes("//td/a[contains(#href,'Lokindivid')]").Select(Function(node) New KeyValuePair(Of String, DateTime)(node.InnerText, DateTime.Parse(node.SelectSingleNode("./ancestor::tr[1]/td[2]").InnerText).Date))
For Each item As KeyValuePair(Of String, Date) In items
Console.WriteLine(item.Key)
Console.WriteLine(item.Value)
Next

Table cell too wide

Please, either look at http://jsfiddle.net/mawg/pL9kd/ or stick the code below into your favourite HTML editor ...
Look to the right of OMG! Item 4 contains a *nested* array. (How) can I get that nested array (xyz) to be 2 columns wide, even if its content doesn't need so much space?
<table border="1" cellpsacing="0" cellpadding="0" style="">
<tr><th style="border-width:1" colspan="3">This is an array</th></tr>
<td colspan="2">
<table border="1">
<tr><td colspan="3">Array</td></tr>
<tr>
<td>item 1</td>
<td>string ( 3 chars)</td>
<td>abc</td>
</tr>
<tr>
<td>0</td>
<td>string ( 25 chars)</td>
<td>item 2 is indexed by zer0</td>
</tr>
<tr>
<td>this equals seven</td>
<td>integer</td>
<td>7</td>
</tr>
<tr>
<td>item 4 is a nested array</td>
<td colspan="2">
<table border="1">
<tr><td colspan="3">Array</td></tr>
<tr>
<td>0</td>
<td>string ( 24 chars)</td>
<td>item 4, offest 0's value</td>
</tr>
<tr>
<td>OMG! Item 4 contains a *nested* array F5</td>
<td colspan="2">
<table border="1">
<tr><td colspan="3">Array</td></tr>
<tr>
<td>xyz</td>
<td>string ( 7 chars)</td>
<td>xyz val</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>item 4, offest 2 is True</td>
<td>boolean</td>
<td>True</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>final item</td>
<td colspan="2">NULL</td>
</tr>
</table>
</td>
</table>
Do you mean like this? http://jsfiddle.net/pL9kd/8/
(Width = 100%)
Check this you can use the width, to set to width='66%' which works since you know there are 3 columns and 2/3 is 66%. Also set the containing table to width='100%' since you are going to need all of the possible space.
From what I could find there is nothing like what your asking (or at least my interpretation of it). Could you not simply create a column width equaling two total columns?
So something like
<td width="40">xyz</td>
I could be way off but that's just my guess. Just curious, what is the implementation for this? I am sure you know css lists and other css elements are much more efficient at styling, correct?