How to render clickable urls using react-json-to-table? - html

i'm new to coding and i'm building a web app using reactjs. i need to render a widget that contains a table to display data that comes from the back-end in json format. The table will change dynamically over time and will always be different.
I found a library that could work for me :
https://github.com/thehyve/react-json-to-table
It works like wonders, but i can't render clickable urls in the tables.
Someone can help me archieve this?
i have some data like this:
{
"Loaded by": "Jills",
"Load id": 34,
"git id": "xxqaygqertqsg98qhpughqer",
"Analysis Id": "7asdlnagsd98gfaqsgf",
"Load Date": "July 12, 2018",
"Data Source": "Study XY123-456",
"Jira Ticket": "Foo-1",
"Confluence URL": "http://myserver/wxyz"
}
the my component looks like this:
export default class TableWidget extends BaseWidget {
constructor(props) {
super(props);
const { data } = this.props;
const data2 = data;
this.state = {
data: this.getData(data2)
};
this.handleResize = this.handleResize.bind(this);
}
componentWillMount() {
super.componentWillMount();
this.props.socket.on(`widget:update:${this.props.jobName}:${this.props.name}`, datas => {
logger('info', `updating widget: ${this.props.jobName}:${this.props.name}`, datas);
this.setState({
data: this.getData(datas.value),
});
});
}
getData(data) {
const demoJson = {
"Loaded by": "Jills",
"Load id": 34,
"git id": "xxqaygqertqsg98qhpughqer",
"Analysis Id": "7asdlnagsd98gfaqsgf",
"Load Date": "July 12, 2018",
"Data Source": "Study XY123-456",
"Jira Ticket": "Foo-1",
"Confluence URL": "http://myserver/wxyz"
};
if (data == null )
return demoJson;
else
return data;
}
static get layout() {
return {
x: 0,
y: 0,
w: 4,
h: 3,
minH: 3,
maxH: 40,
minW: 4,
maxW: 10,
};
}
static get className() {
return 'TableWidget';
}
handleResize() {
this.chart.reflow();
}
render() {
const classList = classNames(...this.classList, 'widget', 'widget__table',);
return (
<div className={classList}>
<h1 className="widget__title">{this.props.title}</h1>
<JsonToTable json={this.state.data} />
</div>
);
}
}
TableWidget.propTypes = {
title: PropTypes.string.isRequired,
};
the table renders fine but i want to be albe to clikc on the "conference url". how can i archieve this?
maybe I could use one of these two libraries?
https://github.com/arqex/react-json-table
or
https://github.com/agracio/ts-react-json-table
thanks for the help and sorry if i made some English or code abominations.

Related

Display a column data from database

I have a method to query some data called read()
var data = "";
read() async {
var res = await SqlConn.readData(
"SPS_CUST1APP_1 'MW','FB','','','','',5,0");
debugPrint(res.toString());
setState(() {
data = res;
});
}
Them im display my data into Text() widget. but this is what it show in my flutter apps
[
{
"CUST_CODE": 11,
"CUST_NAME": "IMAS HALIMATUSADIYAH",
"CUST_TYPE": "MEMBER",
"OFFI_CODE": "KOPKAR ECCINDO",
"PHON_NMBR": "",
"CUST_ADDR": "TAMAN PINANG INDAH BLOK G-6/3 SIDOARJO 27-5",
"EMAI_ADDR": "",
"AREA_CODE": 03,
"SLMN_NMBR": "",
"CLMT_VALU": 1600000,
"CLMT_VAL2": 900000.0000,
"STOR_NAME": ""
},
{
"CUST_CODE": 12,
"CUST_NAME": "AGUS PRIHENDRATMO",
"CUST_TYPE": "MEMBER",
"OFFI_CODE": "KOPKAR ECCINDO",
"PHON_NMBR": "",
"CUST_ADDR": "JL.SEMERU-PEPELEGI-WARU SIDOARJO 8-3",
"EMAI_ADDR": "",
"AREA_CODE": 03,
"SLMN_NMBR": "",
"CLMT_VALU": 1600000,
"CLMT_VAL2": 900000.0000,
"STOR_NAME": ""
}
]
and I'm sure it's Json.
So is there any ways to make the return of data value into a table? Because I'm not going to show all column in my flutter.
And what widget do I need to do that?

How To Get Date Value From A JSON File in Angular6

I have a json file called data.json in my assets folder
[
{
"id": 1,
"project_name": "X project",
"project_date": "December 1, 2019 at 9:03:01 AM GMT+1",
"project_status": "vip",
"rating": "5 star"
}
]
Here Is my Angular service called home.service.ts
projectList = '../../../assets/data.json';
getProject() {
return this.httpService
.get(this.projectList)
.map(res => JSON.parse(res.text(), this.reviver));
}
reviver(key, value): any {
if ('project_date' === key) {
return new Date(value);
}
return value;
}
Here is my component.ts file
projects: string[];
showProject() {
this.homeservice.getProject().subscribe(
data => {
this.projects= data as string[];
console.log(this.projects);
},
(err: HttpErrorResponse) => {
console.log(err.message);
}
);
}
And this is my html file
<div *ngFor="let project of projects">
<h5>{{ project.project_date | date }}</h5>
</div>
The error I'm getting is:
res.text is not a function in home.service.ts
If I try it without the .map(res => JSON.parse(res.text(), this.reviver));
I get this error:
Invalid argument 'December 1, 2019 at 9:03:01 AM GMT+1' for pipe 'DatePipe'
Does anyone have a solution to how I can display this on the web page as a date? Thanks.
Your date should look like the following (without at):
"December 1, 2019 9:03:01 AM GMT+1"
There is no need to parse the response of your http request since it is done natively by angular
getProject() {
return this.httpService
.get(this.projectList)
}
To display the date using a format
{{project.project_date | date:'h:mm a z'}}

React Native json object does not show in ListView

I'm new to RN and am trying to show a ListView populated with data from a json array, If I use a simple array then I can see the data however when I use the json array as shown in the code I don't see anything populated when I run the emulator. Is there a specific way to handle the json in my example below to show it in the ListView:
class FetchExample extends Component {
constructor(props) {
super(props);
// Initialize the hardcoded test data - to be replaced by JOSN fetch
let data = {"Vehicles":[[
{"vehicle_make": "Toyota",
"vehicle_model": "Camry",
"vehicle_year": "2015",
"vehicle_price_range": "$$ (10-30)",
"car_id": 1127,
"vehicle_color": "Black",
"vehicle_car_accidents": "No",
"vehicle_no_owners": "1",
"car_vehicle_location": "Lot",
"vehicle_city_location": "L.A",
"vehicle_mileage": 10864,
"vehicle_vin": 1234,
"vehicle_off_lease": "Yes",
"vehicle_state": "CA"
}]]};
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
dataSource: ds.cloneWithRows(data)
};
console.log(data);
}
render() {
return (
<View style={{paddingTop: 22}}>
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) => <Text>{rowData.Vehicles}</Text>}
/>
</View>
);
}
}
If I refer to the docs, It looks like your data should be an array rather than an object. can you try with the following?
let data = [
{"vehicle_make": "Toyota",
"vehicle_model": "Camry",
"vehicle_year": "2015",
"vehicle_price_range": "$$ (10-30)",
"car_id": 1127,
"vehicle_color": "Black",
"vehicle_car_accidents": "No",
"vehicle_no_owners": "1",
"car_vehicle_location": "Lot",
"vehicle_city_location": "L.A",
"vehicle_mileage": 10864,
"vehicle_vin": 1234,
"vehicle_off_lease": "Yes",
"vehicle_state": "CA"
}];
edit:
you can instead replace
dataSource: ds.cloneWithRows(data)
with
dataSource: ds.cloneWithRows(data.Vehicles[0])
but I'd suggest you flatten your data as much as you can.
edit 2:
The render method also needs modification. try to change renderRow to the following:
renderRow={(rowData) => <Text>{rowData.vehicle_make}</Text>}

Sequelize update a record and it's associations

I have a model City which hasMany CitiesDescriptions.
I would like to update City, but whenever the data contains CitiesDescriptions I would like them to be updated as well.
This is what my data looks like:
{
"id": 4263,
"name": "Accra",
"country_id": 9,
"slug": "accra-5",
"code": "ACD",
"hdo_code": "",
"tourico_code": null,
"active": true,
"CitiesDescriptions": [
{
"id": 1,
"lang": "es",
"description": "text text"
}
]
}
So, in this case I want the data within CitiesDescriptions to be updated.
In the case that one of the objects inside CitiesDescriptions is a new record (doesn't have ID) I want it to be created.
Anyway, I haven't found a way to do this, whatever I found fails in some way. The closest I found that almost works is this:
var city = models.City.build(params, {
isNewRecord : false,
include : [models.CitiesDescription]
});
Promise.all([
city.save(),
city.CitiesDescriptions.map(function (description) {
if (description.getDataValue('id')) {
return description.save();
} else {
description.city_id = city.id;
return models.CitiesDescription.create(description.dataValues);
}
})
]).then(function(results) {
res.send(results);
});
This works except with the data doesn't have a CitiesDescriptions key.
Still, looks way to complicated to do, specially if tomorrow I have more associated models.
Isn't there any way to do this without so much hassle?
EDIT:
Couldnt find a solution, I made this and it works as intended.
var params = req.body;
var promises = [];
promises.push(models.City.update(params, {
where: {
id: parseInt(req.params.id)
}
}));
if(params.CitiesDescriptions) {
promises.push(
params.CitiesDescriptions.map(function (description) {
return models.CitiesDescription.upsert(description, {individualHooks: true});
})
);
}
Promise.all(promises).then(function(results) {
res.send(results);
});

HighCharts & MVC: How to load whole graph definition and data with JSON?

I'd like to know how it is possible to load options & data graph or whole graph structure returning a JSON object?
In particular, I'd like to dynamically create options, categories, axis, data, etc. with JSON; I think it is possible, but I only found informations describing how to load data& series, not options.
For example, I'd like to define title, xAxis, etc, returning a JSon Object:
[...]
title: {
text: 'Total fruit consumtion, grouped by gender'
},
xAxis: {
categories: []
},
[...]
In particular, I need to dynamically create a more complex graph, similar to this one: http://www.highcharts.com/demo/column-stacked-and-grouped
Thanks in advance!
With DotNet.Highcharts is possible to create the chart on the server side as you like without using JavaScript or JSON. Here is the example which you would like do with the library:
Highcharts chart = new Highcharts("chart")
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
.SetTitle(new Title { Text = "Total fruit consumtion, grouped by gender" })
.SetXAxis(new XAxis { Categories = new[] { "Apples", "Oranges", "Pears", "Grapes", "Bananas" } })
.SetYAxis(new YAxis
{
AllowDecimals = false,
Min = 0,
Title = new YAxisTitle { Text = "Number of fruits" }
})
.SetTooltip(new Tooltip { Formatter = "TooltipFormatter" })
.SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { Stacking = Stackings.Normal } })
.SetSeries(new[]
{
new Series
{
Name = "John",
Data = new Data(new object[] { 5, 3, 4, 7, 2 }),
Stack = "male"
},
new Series
{
Name = "Joe",
Data = new Data(new object[] { 3, 4, 4, 2, 5 }),
Stack = "male"
},
new Series
{
Name = "Jane",
Data = new Data(new object[] { 2, 5, 6, 2, 1 }),
Stack = "female"
},
new Series
{
Name = "Janet",
Data = new Data(new object[] { 3, 0, 4, 4, 3 }),
Stack = "female"
}
});
You can find a lot of ASP.NET MVC examples here: http://dotnethighcharts.codeplex.com/releases/view/80650