Nested Rows in Html Custom Tables - html

As per my client requirement we are working on some custom table and I got stuck at nested rows.
when I click that plus symbol the rows of that particular row should be binded to the next row...
My data is in this format:
tabledata = [
{
reference: "191782-01", name: "American Electric LLC", assigned: "Rusty", Ship: "PKUP", Open: "15", total: "30", percentage: "50", staged: "1/4", datetime: "07/25/18 7:51 AM",
child: [{
reference: "191782-01", name: "American Electric LLC", assigned: "Rusty", Ship: "PKUP", Open: "15", total: "30", percentage: "50", staged: "1/4", datetime: "07/25/18 7:51 AM"
},
{
reference: "191782-01", name: "American Electric LLC", assigned: "Rusty", Ship: "PKUP", Open: "15", total: "30", percentage: "50", staged: "1/4", datetime: "07/25/18 7:51 AM"
}]
},
{ reference: "191780-02", name: "Good Business Company", assigned: "", Ship: "WISE", Open: "8", total: "8", percentage: "0", staged: "1/2", datetime: "07/25/18 8:12 AM", child: [] },
{ reference: "191782-02", name: "Cecchin Plumbing", assigned: "", Ship: "PKUP", Open: "23", total: "36", percentage: "36", staged: "1/3", datetime: "07/25/18 8:01 AM", child: [] },
{ reference: "191780-01", name: "Company Name 1", assigned: "MULTI", Ship: "PKUP", Open: "1", total: "1", percentage: "0", staged: "2/4", datetime: "07/25/18 8:05 AM", child: [] },
{ reference: "191702-02", name: "Leep's Supply", assigned: "MULTI", Ship: "WISE", Open: "3", total: "6", percentage: "50", staged: "2/4", datetime: "07/25/18 8:46 AM", child: [] }
]
I need child object to be visible when I click plus icon
My Angular Code:
<tbody>
<tr *ngFor="let data of tabledata">
<td class="text-left">{{data.reference}}<span *ngIf="data.reference.includes('191782')"
class="badge badge-warning win-badge win-badge-warning win-badge-large ml-3"
style="border-radius: 1.4rem">Urgent</span></td>
<td>{{data.name}}</td>
<td><span [ngClass]="{'badge badge-secondary win-badge win-badge-secondary': data.assigned=='MULTI', 'bgtrans': data.assigned!='MULTI'}">{{data.assigned}}</span></td>
<td>{{data.Ship}}</td>
<td><span [ngClass]="{'alert alert-error mobile-error alert-dismissible': data.Open>10, 'bgtrans': data.Open<10}">{{data.Open}}</span></td>
<td>{{data.total}}</td>
<td>{{data.percentage}}</td>
<td>{{data.staged}}</td>
<td>{{data.datetime}}</td>
<td><a href="javascript:void(0)"
*ngIf="data.child.length>0"><i class="fa fa-plus-square-o"></i></a> </td>
</tr>
</tbody>

You can map the array first, in order to transform it into a flat array, and then bind to the resulting array:
// pass a function to map
let arrays = tabledata.map(x => new Array(x).concat(x.child));
let flatTableData = [].concat.apply([], arrays);
To identify the child rows, just look for the ones that haven't the child property

Related

Vega lite Top 10 order host descending based on the sum of field score

I have this example data
"values": [
{"host": "host-one", "score": 70, date: 1593674604},
{"host": "host-two", "score": 30, date: 1593674608},
{"host": "host-three", "score": 12, date: 1593674615},
{"host": "host-two", "score": 95, date: 1593674624},
{"host": "host-three", "score": 1, date: 1593674633}
]
In a heatmap I have to show top 10 host, based on the sum of the score per host, in the y axis, I have tried in many ways without success, this is what I have tried the last time:
}
transform: [
{calculate: "datum.key.date", as: "date"}
{calculate: "datum.key.host", as: "host"}
{calculate: "datum.key.score", as: "score"}
{
window: [
{op: "sum", field: "score", as: "score_order"}
]
}
groupby: ["host"]
]
mark: {type: "rect", cornerRadius: 3}
encoding: {
x: {
bin: {maxbins: 80}
field: date
type: temporal
}
y: {
field: host
type: ordinal
sort: {field: "score_order", order: "descending"}
}
Any clues on what Im doing wrong?

How to Translate data in array of objects with .map() using react-i18next

Just started using i18next and having a bit of issues translating the following data.
export const educationData = [
{ education: "Some education 1", timeframe: "2017 - 2018", id: 1 },
{ education: "Some education 2", timeframe: "2016 - 2017", id: 2 },
{ education: "Some education 3", timeframe: "2015 - 2016", id: 3 },
{ education: "Some education 4", timeframe: "2014 - 2015", id: 4 }
];
JSON in locales for different languages looks like:
"education": {
"heading": "Education",
"educationData": [
{
"id": 1,
"education": "Some education 1",
"timeframe": "2017 - 2018"
},
{
"id": 2,
"education": "Some education 2",
"timeframe": "2016 - 2017"
},
{
"id": 3,
"education": "Some education 3",
"timeframe": "2015 - 2016"
},
{
"id": 4,
"education": "Some education 4",
"timeframe": "2014 - 2015"
}
]
}
Component looks like:
import React from "react";
import { useTranslation } from "react-i18next";
import { educationData } from "../data/educationData";
import Education from "./Education.js";
function ListEducation() {
const { t } = useTranslation();
return (
<div className="education py-1">
<h2>{t("education.heading")}</h2>
<hr />
{educationData.map((edu) => (
<Education
key={edu.id}
education={edu.education}
timeframe={edu.timeframe}
/>
))}
</div>
);
}
export default ListEducation;
How do i get the translations to work in the .map() function? Outside of .map() something like t("education.educationData.0.education") works fine.
Inside .map function it just outputs "education.educationData.0.education" as a string.
You can get access to an array from file with translations using:
t('education.educationData', { returnObjects: true })
and then easily map through this array.
Source: i18next documentation: Arrays
You can try this
{t(`education.educationData.${id}.${education}`)}
You're basically concatenating the string.

How to insert dropdown into dynamic table in angular7

Tried to insert dropdown inside dynamic table but i do not know how to do it.I want to insert dropdown with some values on last column.Please help anyone to find the solution.
head = [ "Name", "Age", "Gender","Action"];
details = [
{ "name": "star1", "age": "25", "gender": "male","action": "" },
{ "name": "star2", "age": "22", "gender": "female","action": "" },
{ "name": "star3", "age": "21", "gender": "male","action": "" },
{ "name": "star4", "age": "35", "gender": "female","action": "" },
];
constructor(){
this.tableHead = this.head;
this.userDetails = this.details;
}
Demo:https://stackblitz.com/edit/angular-bfs3gp?file=src/app/app.component.ts
I have made a solution for you. Can you please replace your details array to
details = [
{ name: "star1", age: "25", gender: "male", action: ["Edit", "Delete"] },
{ name: "star2", age: "22", gender: "female", action: ["Edit", "Delete"] },
{ name: "star3", age: "21", gender: "male", action: ["Edit", "Delete"] },
{ name: "star4", age: "35", gender: "female", action: ["Edit", "Delete"] }
];
Then Replace the dynamic-table.component.html to below code
<table>
<thead>
<tr class="table-head">
<th *ngFor="let tableHead of tableHeads">{{tableHead}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let tableData of tableDatas">
<td *ngFor="let colName of tableColNameGenerated"> {{colName != 'action' ? tableData[colName] : ''}}
<span *ngIf="colName == 'action'">
<select>
<option *ngFor="let opt of tableData.action">{{opt}}</option>
</select>
</span>
</td>
</tr>
</tbody>
</table>
Now I hope your concern is resolved.
Hope this helps!
Thank you.

(kendo)How to specify data-columns field type in declarative grid definition

I have a grid which I define declaratively. It works well except that the column sorting interprets the columns as strings, whereas I wish for some columns to be sorting as numerical values.
Below is my grid definition.
The column I am interested in sorting in numerical order is "incident_count". I have tried specifying a type: "number" attribute to the column but it did not work.
<div id="PatrolRecords">
<div data-filterable='{ "mode": "row" }'
data-role='grid'
data-sortable='true'
data-detail-template='patrolDetailTemplate'
data-detail-init='detailInit'
data-bind='source: reportData.Patrols, events: {excelExport: excelExportHandler}'
data-pageable='{ "pageSize": 10 }'
data-toolbar='["excel"]'
data-excel='{ "fileName": "Patrols.xlsx", "allPages": "true" }'
data-columns='[
{
field: "patrol_id_plain",
title: "Patrol ID",
filterable: false,
width: 70
},
{
field: "incident_count",
title: "Incidents",
filterable: false,
type: "number",
width: 70
},
{
title: "GPS",
template: kendo.template($("#gpsTemplate").html()),
filterable: false,
width: 50
},
{
title: "",
template: kendo.template($("#viewLinkTemplate").html()),
filterable: false,
width: 60
},
]'>
</div>
</div>
Here is my viewmodel /datasource:
viewModel = kendo.observable({
reportData:
"Patrols":
[{
"patrol_id": "yO0crrEjeNvlrkc3H8otng%3d%3d",
"patrol_id_plain": "7383748",
"tour_name": "Airport Towers",
"location_name": "Airport Towers",
"client_company": "Scottsdale Auto Center",
"address": "18881 Von Karman",
"city": "Irvine",
"abbreviation": "CA",
"end_date": "10/31/2016 11:56:47 AM",
"end_date_seconds": "531237407",
"first_name": "James",
"last_name": "Wierzba",
"patrolled_by": "James Wierzba",
"incident_only": "0"
},
"patrol_id": "KhZmgPq2fbSP3Zly%2bw2I5Q%3d%3d",
"patrol_id_plain": "7383747",
"tour_name": "Airport Towers",
"location_name": "Airport Towers",
"client_company": "Scottsdale Auto Center",
"address": "18881 Von Karman",
"city": "Irvine",
"abbreviation": "CA",
"end_date": "10/10/2016 6:24:01 AM",
"end_date_seconds": "529403041",
"first_name": "James",
"last_name": "Wierzba",
"patrolled_by": "James Wierzba",
"incident_only": "0"
],
excelExportHandler: function (e) {
var sheet = e.workbook.sheets[0];
for (var i = 1; i < sheet.rows.length; i++) {
var row = sheet.rows[i];
var data = e.data.reportData.Patrols[i - 1];
if (data.incident_only == "1") row.cells[6].value = '-';
else row.cells[6].value = data.completed_checkpoint_count + ' of ' + data.total_checkpoint_count;
}
}
});
Try to specify the datatype in the DataSource, specifically in the model statement.

hourly_forecast from Wunderground API

I'm trying to get the hourly forecast temperature for a specific hour of the day from the Wunderground API for a research project:
This is an example of the JSON:
http://api.wunderground.com/api/[key]/geolookup/astronomy/forecast/history_/hourly/conditions/q/mo/columbia.json
The specific section looks like this:
"hourly_forecast": [
{
"FCTTIME": {
"hour": "17","hour_padded": "17","min": "00","sec": "0","year": "2013","mon": "7","mon_padded": "07","mon_abbrev": "Jul","mday": "15","mday_padded": "15","yday": "195","isdst": "1","epoch": "1373925600","pretty": "5:00 PM CDT on July 15, 2013","civil": "5:00 PM","month_name": "July","month_name_abbrev": "Jul","weekday_name": "Monday","weekday_name_night": "Monday Night","weekday_name_abbrev": "Mon","weekday_name_unlang": "Monday","weekday_name_night_unlang": "Monday Night","ampm": "PM","tz": "","age": ""
},
"temp": {"english": "86", "metric": "30"},
"dewpoint": {"english": "71", "metric": "22"},
"condition": "Thunderstorm",
"icon": "tstorms",
"icon_url":"http://icons-ak.wxug.com/i/c/k/tstorms.gif",
"fctcode": "15",
"sky": "66",
"wspd": {"english": "10", "metric": "16"},
"wdir": {"dir": "ESE", "degrees": "119"},
"wx": "Scattered Thunderstorms , Scattered Light Rain Showers",
"uvi": "3",
"humidity": "60",
"windchill": {"english": "-9998", "metric": "-9998"},
"heatindex": {"english": "91", "metric": "33"},
"feelslike": {"english": "91", "metric": "33"},
"qpf": {"english": "", "metric": ""},
"snow": {"english": "", "metric": ""},
"pop": "30",
"mslp": {"english": "30.14", "metric": "1020"}
}
,
I get the JSON like so:
$.ajax({
url : "http://api.wunderground.com/api/[key]/geolookup/forecast/hourly/history_/astronomy/conditions/q/"+lat+","+lon+".json",
dataType : "jsonp",
success : function(parsed_json) {
Then I try to run through the hourly forecasts like so (normally mday and hour are replaced with a variable containing today's date and a specific hour, but for troubleshooting, I put these numbers in).
// get the forecast
$.each( parsed_json['hourly_forecast'], function( i, value ) {
if( value.FCTTIME.mday == 15 && value.FCTTIME.hour == 19) {
six_hour_forecast = value.temp.english;
}
However, I consistently get the wrong temp.english for six_hour_forecast.
So close — what am I missing?
This did it:
// Get the forecast 6 hour temp
$.each( parsed_json['hourly_forecast'], function( index, value ) {
if( value['FCTTIME']['hour']==sunrise_hour*1 + 6 && value['FCTTIME']['mday']==window.current_day ) {
window.six_hour_forecast = value.temp.english;
}
}); // end each