How to display Firebase data with multi-level key on HTML table?
Date : March 29 2020, 07:55 AM
I wish this help you I think part of the problem is that ng-repeat-start and ng-repeat-end are the wrong tools for the situation. Based on my day-to-day work, I've found that if you're operating on an HTML table, a more basic ng-repeat setup is preferable. <table>
<thead>
<tr>
<td>alamat</td>
<td>email</td>
<td>identitas</td>
<td>layanan</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in list">
<td>{{item.alamat}}</td>
<td>{{item.email}}</td>
<td>{{item.identitas}}</td>
<td>{{item.layanan}}</td>
</tr>
</tbody>
</table>
|
Parse complex multi-header html table with pandas and bs4
Date : March 29 2020, 07:55 AM
wish helps you Complex Table linkfrom bs4 import BeautifulSoup
from urllib.request import urlopen
import pandas as pd
page = urlopen('https://transparency.entsoe.eu/generation/r2/actualGenerationPerProductionType/show?name=&defaultValue=true&viewType=TABLE&areaType=BZN&atch=false&datepicker-day-offset-select-dv-date-from_input=D&dateTime.dateTime=09.08.2017%2000:00%7CUTC%7CDAYTIMERANGE&dateTime.endDateTime=09.08.2017%2000:00%7CUTC%7CDAYTIMERANGE&area.values=CTY%7C10YES-REE------0!BZN%7C10YES-REE------0&productionType.values=B01&productionType.values=B02&productionType.values=B03&productionType.values=B04&productionType.values=B05&productionType.values=B06&productionType.values=B07&productionType.values=B08&productionType.values=B09&productionType.values=B10&productionType.values=B11&productionType.values=B12&productionType.values=B13&productionType.values=B14&productionType.values=B20&productionType.values=B15&productionType.values=B16&productionType.values=B17&productionType.values=B18&productionType.values=B19&dateTime.timezone=UTC&dateTime.timezone_input=UTC')
soup = BeautifulSoup(page.read())
table = soup.find('tbody')
res = []
row = []
for tr in table.find_all('tr'):
for td in tr.find_all('td'):
row.append(td.text)
res.append(row)
row = []
df = pd.DataFrame(data=res)
>>> for tr in table.find_all('tr'):
... for td in tr.find_all('td'):
... row.append(td.text.strip())
... res.append(row)
... row = []
|
Turn data into an HTML pivot table with multi-level headings
Date : March 29 2020, 07:55 AM
I wish this help you Here is a function that takes data rows (array of arrays or array of plain objects), and the indexes/keys of the columns/fields by which to group and pivot the data. It produces the innerHTML that can be used for a table element. /*
Create table HTML: only pass data (no labels).
Pass column indexes/keys for:
- the column with the values for the cells,
- the row headers, and
- the column headers
Optionally provide callback for aggregating data that ends up in same cell
*/
function pivotTable(data, valueColumn, groupColumns, pivotColumns, aggregator = x=>x.length ? x[0] : "") {
// Helper function
function span(...args) {
return [" rowspan", " colspan"].map((dim, i) =>
args[i] > 1 ? dim + '="' + args[i] + '"' : ""
).join``;
}
// Structure dimensions:
const [groups, pivots] = [groupColumns, pivotColumns].map(columns => {
const colMap = {};
for (const row of data) {
columns.reduce((acc, colNo) => (acc[row[colNo]] = acc[row[colNo]] || {}), colMap);
}
const headers = columns.map(col => []);
const tree = (function process(colMap, y=0, x=0) {
return Object.entries(colMap).reduce((acc, [title, obj]) => {
const result = process(obj, y+1, x);
const size = result.size || 1;
result.title = title;
acc.children[title] = result;
acc.size += size;
headers[y].push(result);
x += size;
return acc;
}, { title: null, x, size: 0, children: {} });
})(colMap);
tree.headers = headers;
return tree;
});
// Collect data in matrix, per dimensions:
const matrix = Array.from({length:groups.size}, row => Array.from({length:pivots.size}, cell => []));
for (const row of data) {
const y = groupColumns.reduce((acc, colNo) => acc.children[row[colNo]], groups).x;
const x = pivotColumns.reduce((acc, colNo) => acc.children[row[colNo]], pivots).x;
matrix[y][x].push(row[valueColumn]);
}
matrix.forEach(row => row.forEach((values,i) => row[i] = aggregator(values)));
// Produce HTML for column headers:
let html = `<tr><th${span(groupColumns.length, pivotColumns.length)}></th>${
pivots.headers.map(header => header.map(o => `<th${span(1, o.size)}>${o.title}</th>`).join``).join("</tr>\n<tr>")
}</tr>`;
// Produce HTML for the row headers and cells:
let startRow = true;
let y = 0;
(function loop(children, depth=0) {
Object.values(children).map(group => {
if (startRow) html += "<tr>";
startRow = false;
html += `<th${span(group.size, 1)}>${group.title}</th>`;
loop(group.children, depth+1);
});
if (depth >= groupColumns.length) {
html += `${matrix[y].map(value => `<td>${value}</td>`).join``}</tr>\n`;
startRow = true;
y++;
}
})(groups.children);
return html;
}
// Demo where data is structured as array of arrays:
const data = [["lemma","form","tense","mood","voice","person","number"],["πιστεύω","πεπίστευκα","perf","ind","act","1st","sg"],["πιστεύω","πεπιστεύκαμεν","perf","ind","act","1st","pl"],["πιστεύω","πεπίστευκας","perf","ind","act","2nd","sg"],["πιστεύω","πεπιστεύκατε","perf","ind","act","2nd","pl"],["πιστεύω","πεπιστεύκειν","perf","inf","act","",""],["πιστεύω","πεπιστεύκειν","plup","ind","act","1st","sg"],["πιστεύω","πεπιστεύκεισαν","plup","ind","act","3rd","pl"],["πιστεύω","πεπίστευκεν","perf","ind","act","3rd","sg"],["πιστεύω","πεπίστευκεν","perf","inf","act","",""],["πιστεύω","πεπίστευκεν","perf","inf","act","3rd","sg"],["πιστεύω","πεπίστευκεν","plup","ind","act","3rd","pl"],["πιστεύω","πεπιστευκέναι","perf","inf","act","",""],["πιστεύω","πεπίστευμαι","perf","ind","mp","1st","sg"],["πιστεύω","πεπίστευμαι","perf","ind","pass","1st","sg"],["πιστεύω","πεπίστευνται","perf","ind","mid","3rd","pl"],["πιστεύω","πεπίστευνται","perf","ind","mp","3rd","pl"],["πιστεύω","ἐπεπίστευντο","plup","ind","mp","3rd","pl"],["πιστεύω","πεπίστευται","perf","ind","mid","3rd","sg"],["πιστεύω","πεπίστευται","perf","ind","mp","3rd","sg"],["πιστεύω","ἐπεπίστευτο","plup","ind","mp","3rd","sg"],["πιστεύω","πιστεῦσαι","aor","imperat","mid","2nd","sg"],["πιστεύω","πιστεῦσαι","aor","inf","act","",""],["πιστεύω","πιστεῦσαι","aor","inf","act","3rd","sg"],["πιστεύω","πιστεῦσαι","aor","opt","act","3rd","sg"],["πιστεύω","πιστεῦσαν","aor","ind","act","3rd","pl"],["πιστεύω","πιστεύῃ","pres","ind","act","3rd","sg"],["πιστεύω","πιστεύῃ","pres","ind","mp","2nd","sg"],["πιστεύω","πιστεύῃ","pres","subj","act","3rd","sg"],["πιστεύω","πιστεύῃ","pres","subj","mp","2nd","sg"],["πιστεύω","πίστευε","imperf","ind","act","3rd","sg"],["πιστεύω","πίστευε","pres","imperat","act","2nd","sg"],["πιστεύω","πιστεύει","pres","ind","act","3rd","sg"],["πιστεύω","πιστεύει","pres","ind","mp","2nd","sg"],["πιστεύω","πιστεύειν","pres","inf","act","",""],["πιστεύω","πιστεύεις","pres","ind","act","2nd","sg"],["πιστεύω","ἐπίστευεν","imperf","ind","act","3rd","sg"],["πιστεύω","πιστεύεσθαι","pres","inf","mp","",""],["πιστεύω","πιστεύεται","pres","ind","mp","3rd","sg"],["πιστεύω","πιστεύετε","imperf","ind","act","2nd","pl"],["πιστεύω","πιστεύετε","pres","imperat","act","2nd","pl"],["πιστεύω","πιστεύετε","pres","ind","act","2nd","pl"],["πιστεύω","πιστευέτω","pres","imperat","act","3rd","sg"],["πιστεύω","πιστεύητε","pres","subj","act","2nd","pl"],["πιστεύω","πιστευθῇ","aor","subj","pass","3rd","sg"],["πιστεύω","ἐπιστεύθη","aor","ind","pass","3rd","sg"],["πιστεύω","πιστεύσῃ","aor","subj","act","3rd","sg"],["πιστεύω","πιστεύσῃ","aor","subj","mid","2nd","sg"],["πιστεύω","πιστεύσῃ","fut","ind","mid","2nd","sg"],["πιστεύω","πιστεύῃς","pres","subj","act","2nd","sg"],["πιστεύω","ἐπίστευσα","aor","ind","act","1st","sg"],["πιστεύω","πιστεύσαι","aor","imperat","mid","2nd","sg"],["πιστεύω","πιστεύσαι","aor","inf","act","",""],["πιστεύω","πιστεύσαι","aor","inf","act","3rd","sg"],["πιστεύω","πιστεύσαι","aor","opt","act","3rd","sg"],["πιστεύω","ἐπιστεύσαμεν","aor","ind","act","1st","pl"],["πιστεύω","ἐπίστευσαν","aor","ind","act","3rd","pl"],["πιστεύω","πιστευσάντων","aor","imperat","act","3rd","pl"],["πιστεύω","πιστεύσας","aor","ind","act","2nd","sg"],["πιστεύω","ἐπίστευσας","aor","ind","act","2nd","sg"],["πιστεύω","πιστεύσατε","aor","imperat","act","2nd","pl"],["πιστεύω","ἐπιστεύσατε","aor","ind","act","2nd","pl"],["πιστεύω","ἐπίστευσε","aor","ind","act","3rd","sg"],["πιστεύω","πιστεύσει","aor","subj","act","3rd","sg"],["πιστεύω","πιστεύσει","fut","ind","act","3rd","sg"],["πιστεύω","πιστεύσει","fut","ind","mid","2nd","sg"],["πιστεύω","πιστεύσειν","fut","inf","act","",""],["πιστεύω","πιστεύσεις","aor","subj","act","2nd","sg"],["πιστεύω","πιστεύσεις","fut","ind","act","2nd","sg"],["πιστεύω","ἐπίστευσεν","aor","ind","act","3rd","sg"],["πιστεύω","πιστεύσετε","aor","subj","act","2nd","pl"],["πιστεύω","πιστεύσετε","fut","ind","act","2nd","pl"],["πιστεύω","πιστεύσητε","aor","subj","act","2nd","pl"],["πιστεύω","πιστεύσητε","fut","ind","act","2nd","pl"],["πιστεύω","πιστεύσομεν","aor","subj","act","1st","pl"],["πιστεύω","πιστεύσομεν","fut","ind","act","1st","pl"],["πιστεύω","πίστευσον","aor","imperat","act","2nd","sg"],["πιστεύω","πιστεύσουσι","fut","ind","act","3rd","pl"],["πιστεύω","πιστεύσουσιν","aor","subj","act","3rd","pl"],["πιστεύω","πιστεύσουσιν","fut","ind","act","3rd","pl"],["πιστεύω","πιστεύσῃς","aor","subj","act","2nd","sg"],["πιστεύω","πιστεύσω","aor","ind","mid","2nd","sg"],["πιστεύω","πιστεύω","pres","subj","act","1st","sg"],["πιστεύω","πιστεύωμεν","pres","subj","act","1st","pl"]];
const html = pivotTable(data.slice(1), 1, [0, 6, 5], [2, 3, 4]);
document.querySelector("table").innerHTML = html;
table,
tr,
td,
th {
border: 1px solid;
border-collapse: collapse;
}
<table></table>
function fromHtml(table) {
const results = [];
for (const row of table.rows) {
results.push(Array.from(row.cells, cell => cell.textContent.trim()));
}
return results;
}
[
{lemma: "πιστεύω", form: "πεπίστευκα", tense: "perf", mood: "ind", voice: "act", person: "1st", number "sg"},
{lemma: "πιστεύω", form: "πεπιστεύκαμεν", tense: "perf", mood: "ind", voice: "act", person: "1st", number: "pl"},
/* ... */
];
const html = pivotTable(data, "form", ["lemma", "number", "person"], ["tense", "mood", "voice"]);
|
Display data in HTML table with multi level grouping
Tag : html , By : CrookedNumber
Date : March 29 2020, 07:55 AM
wish help you to fix your issue What you want is to flatten all streats into array, so that you cal loop over it. The flat code will be: const concat = (x,y) => x.concat(y)
const flatMap = (f,xs) => xs.map(f).reduce(concat, [])
let states = flatMap(c => c.States.map(s => ({Country:c, State: s})), this.Countries);
let cities = flatMap(c => c.State.Cities.map(s => ({Country:c.Country, State:c.State, City: s})), states);
this.streets = flatMap(c => c.City.Streets.map(str => ({Country:c.Country, State:c.State, City: c.City, Street: str})), cities);
<tbody>
<tr *ngFor="let str in streets">
<td *ngIf="firstCountryInGroup(str)" [rowspan]="numberOfCountry(str)">
{{str.Country.CountryName}}
</td>
<td *ngIf="firstStateInGroup(str)" [rowspan]="numberOfStatse(str)">
{{str.State.CityName}}
</td>
<td *ngIf="firstCityInGroup(str)" [rowspan]="numberOfCities(str)">
{{str.City.CityName}}
</td>
<td>{{str.Street.Name}}<td>
<td>{{str.Street.Male}}<td>
<td>{{str.Street.Female}}<td>
<td>{{str.StreetOthers}}<td>
</tr>
</tbody>
|
HTML page with a standard header footer layout without using table tag
Date : March 29 2020, 07:55 AM
|