The code below is working fine and it display record from Monday API.
Here is the outputed JSON record via JSON.stringify()
[ { "id": "3150569213", "name": "Task 1", "column_values": [ { "id": "fullname", "value": null }, { "id": "status", "value": null }, { "id": "email", "value": null }, { "id": "phone_number", "value": null }, { "id": "address", "value": null }, { "id": "product", "value": null }, { "id": "quantity", "value": null }, { "id": "reward", "value": null } ] }, { "id": "3150569636", "name": "Recycle Products Share By ann balling", "column_values": [ { "id": "fullname", "value": "\"ann balling\"" }, { "id": "status", "value": "{\"index\":0}" }, { "id": "email", "value": "{\"text\":\"nancy#gmail.com\",\"email\":\"nancy#gmail.com\",\"changed_at\":\"2022-08-27T12:16:47.728Z\"}" }, { "id": "phone_number", "value": "{\"phone\":\"1234567890\",\"countryShortName\":null}" }, { "id": "address", "value": "{\"lat\":\"Texas,\",\"lng\":\"US\",\"address\":\"unknown\"}" }, { "id": "product", "value": "{\"text\":\"Paper,Bottles,Plastic Cans\"}" }, { "id": "quantity", "value": "\"200\"" }, { "id": "reward", "value": "\"Gift\"" } ] } ]
The property i.column_values[0].value displays record "Nancy More" and I remove the double quotes around it using json.parse() hence JSON.parse(i.column_values[0].value) and its okay.
Here is my issue. The property i.column_values[1].value display record object
{"text":"nancy#gmail.com","email":"nancy#gmail.com","changed_at":"2022-08-27T12:16:47.728Z"}
How do I get email value hence nancy#gmail.com.
Here is the code
import React from "react";
import "./App.css";
import mondaySdk from "monday-sdk-js";
const monday = mondaySdk();
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false,
datax: [],
};
}
componentDidMount() {
monday.api(`query {boards (ids: 34443234) {items(limit: 3 page: 1) {id name column_values {
id
value
} }}}`).then(res => {
console.log(res);
this.setState({datax: res.data.boards[0].items});
});
}
render() {
const {loading } = this.state;
return (
<div>
<table class="table table-hover">
<thead>
<tr>
<th>Fullname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{this.state.datax.map((i, index) => (
<tr key={index}>
<td>{JSON.parse(i.column_values[0].value)}</td>
<td>{i.column_values[1].value}</td>
</tr>
))}
</tbody>
</table>
{JSON.stringify(this.state.datax, null, 2)}
<br />
</div>
);
}
}
export default App;
The code below is how I got the email address value working
<td>{i.column_values[2].value.split(':')[1].split('"')[1]}</td>
Related
I have the following code which displays record from Monday API successfully.
I can get the JSON record via {JSON.stringify(this.state.datax, null, 2)} as per below
[ { "items": [ { "id": "3150569213", "name": "Task 1", "column_values": [ { "id": "fullname", "value": null }, { "id": "status", "value": null }, { "id": "email", "value": null }, { "id": "phone_number", "value": null }, { "id": "address", "value": null }, { "id": "product", "value": null }, { "id": "quantity", "value": null }, { "id": "reward", "value": null } ] }, { "id": "3150569636", "name": "Recycle Products Share By ann balling", "column_values": [ { "id": "fullname", "value": "\"ann balling\"" }, { "id": "status", "value": "{\"index\":0}" }, { "id": "email", "value": "{\"text\":\"ann1#gmail.com\",\"email\":\"ann1#gmail.com\",\"changed_at\":\"2022-08-27T12:16:47.728Z\"}" }, { "id": "phone_number", "value": "{\"phone\":\"1234567890\",\"countryShortName\":null}" }, { "id": "address", "value": "{\"lat\":\"Texas,\",\"lng\":\"US\",\"address\":\"unknown\"}" }, { "id": "product", "value": "{\"text\":\"Paper,Bottles,Plastic Cans\"}" }, { "id": "quantity", "value": "\"200\"" }, { "id": "reward", "value": "\"Gift\"" } ] } ] } ]
How do I get values for name, fullname, email?
Here is the code:
import React from 'react';
import './App.css';
import mondaySdk from 'monday-sdk-js';
import 'monday-ui-react-core/dist/main.css';
const monday = mondaySdk();
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false,
datax: [],
};
}
componentDidMount() {
monday
.api(
`query {boards (ids: 3150569212) {items(limit: 3 page: 1) {id name column_values {
id
value
} }}}`
)
.then((res) => {
console.log(res);
this.setState({ datax: res.data.boards });
//this.setState({datax: res.data.boards[0].items});
});
}
render() {
const { loading } = this.state;
return (
<div>
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Fullname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{this.state.datax.map((i, index) => (
<tr key={index}>
<td>{i.name}</td>
<td>{i.fullname}</td>
<td>{i.email}</td>
</tr>
))}
</tbody>
</table>
{JSON.stringify(this.state.datax, null, 2)}
<br />
</div>
);
}
}
export default App;
You need to map the first element in that case items and then map column_values since it is an array:
{this.state.datax[0].items.map((i, index) => (
<tr key={index}>
<td>{i.name}</td>
<td>{i.fullname}</td>
<td>{i.column_values.map((val) => val.value)}</td>
</tr>
))}
I have try it with the example you send and the output I get is like this, not very clean:
I am creating forms using React-json-schema-form. I don't understand how am I suppose to change the layout of the forms I create. They appear in rows by default and adding classes to each field in the uiSchema does not reflect the desired change. I tried adding col-3 etc and they neither change size nor stop appearing in rows.
Its so complex to figure out. My understand would be to change the default behaviour of the fields. But, I'm sure it should be able to be designed out of the box right?
This is what I want to do but its outdated and I still don't know how to use it. https://github.com/audibene-labs/react-jsonschema-form-layout.
How do I change the layout?
import React, { Component, Fragment } from "react";
import axios, { existing_api, new_api, public_path } from "../../../Api/api";
import 'bootstrap/dist/css/bootstrap.css';
//import Form from "#rjsf/core";
import Form from "#rjsf/bootstrap-4";
class POSView extends Component {
constructor(props) {
super(props);
this.state = {
hotelId: 1,
isActive: 1,
formData: { 'recordIn': 10096 },
schema: props.schema || {
"title": "POS",
"description": "Add POS Invoice - Rooms",
"type": "object",
"properties": {
"customer": { "title": "Customer", "type": 'string', "default": '' },
"room": { "title": "Room", "type": 'integer', "default": '' },
"address": { "title": "Address", "type": 'string' },
"company": { "title": "Company", "type": 'string' },
"dueAmount": { "title": "Due Amount", "type": 'string' },
"roomRate": { "title": "Room Rate", "type": 'string' },
"recordIn": { "title": "Record In", "type": 'number', enum: [10096, 10097], enumNames: ["Guest Ledger Control A/c", "Accounts Receivable"] },
"department": { "title": "Department", "type": 'number', enum: [1, 2], enumNames: ["Head Office", "Accounts"] },
"id": { "title": "ID", "type": 'string' },
"invoiceNumber": { "title": "Invoice Number", "type": 'string' },
"invoiceDate": { "title": "Invoice Date", "type": 'string', "format": "date-time" },
"btcCompany": { "title": "BTC Company", "type": 'number', enum: [1, 2], enumNames: ["Limited Standard", "Standard Limited"] },
"itemsAndServices":
{
"title": "Item And Service",
"description": "Add items and Services",
"type": "array",
"items": {
"type": "object",
//"required": [''],
"properties":
{
"Number": { "type": "number" },
"Item Name": {
"title": "Item Name",
"type": "string"
},
"Item Notes": {
"title": "Item Notes",
"type": "string"
},
"Qty": {
"title": "Qty",
"type": "number"
},
"Unit": {
"title": "Unit",
"type": "string"
},
"Price": {
"title": "Price",
"type": "number"
},
"%": {
"title": "%",
"type": "number"
},
"Extended": {
"title": "Extended",
"type": "number"
}
}
}
},
"payment":
{
"title": "Payment",
"description": "",
"type": "array",
"items": {
"type": "object",
//"required": [''],
"properties":
{
"date": { "title": "Date", "type": "string", format: "date-time" },
"amount": { "title": "Amount", "type": "number" },
"cheque": { "title": "Cheque #", "type": "integer" },
"memo": { "title": "Memo", "type": "string" },
"recordIn": { "title": "Record In", "type": 'number', enum: [10096, 10097], enumNames: ["Guest Ledger Control A/c", "Accounts Receivable"] },
// dynamically populate
}
}
}
}
},
uiSchema: props.uiSchema || {
// customer:{'className':""},
// room:{'className':"", },
// address: {'className':"", "ui:disabled": true, },
// company: {'className':"", "ui:disabled": true, },
// dueAmount: {'className':"", "ui:disabled": true, },
// roomRate: {'className':"", "ui:disabled": true, },
// recordIn:{'className':"", },
// department:{'className':"", },
// id:{'className':"", },
// invoiceNumber: {'className':"", "ui:disabled": true, },
// invoiceDate:{'className':"", },
// btcCompany:{'className':"", },
// itemsAndServices:{'className':""},
//items: { className: "container col-offset-6 col-md-3" }
// 'ui:field': 'layout', HOW I expected the default library to work
// 'ui:layout': [
// {
// customer: { md: 6 },
// room: { md: 6 }
// }, {
// address: { md: 12 }
// }, {
// company: { md: 6 },
// dueAmount: { md: 6 }
// }
// ]
// },
// fields:
// {
// layout: LayoutField
}
};
this.onChange = this.onChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
};
onChange({ formData }) {
formData.address = "";
console.log(formData);
this.state.schema.description = "this is beta plus plus";
this.setState({
formData: formData,
});
}
handleSubmit({ formData }) {
// Submit to an api
console.log(formData);
}
render() {
return (
<div className="container">
<div className="col-4">
{/* <div class="row">
<h1 class="col">First Form</h1>
</div><br /> */}
<div>
<Form
schema={this.state.schema}
formData={this.state.formData}
uiSchema={this.state.uiSchema}
//fields={this.state.fields}
onChange={this.onChange}
onSubmit={this.handleSubmit} />
</div>
</div>
</div>
);
}
}
export default POSView;
I am coding an application and the purpose of it is to show two tables: one with elements from an array and the others one with input that are suggesting elements from an another array.
I don't know how to put my data from OldData.json into my input suggestion which is -> const RecentResearches
import React from 'react';
import { Component } from 'react';
import ReactDOM from 'react-dom';
import NewData from '../../api/data/cities.json'
import OldData from '../../api/data/historical.json'
import Pagination from './Pagination.js'
import SuggestionInputSearch from 'suggestion-react-input-search';
react class NewDataTable extends React.Component {
constructor() {
super();
this.state = {
NewData: NewData,
pageOfItems: []
};
this.onChangePage = this.onChangePage.bind(this);
}
onChangePage(pageOfItems) {
// update state with new page of items
this.setState({ pageOfItems: pageOfItems });
}
render() {
const recentSearches = [{OldData.name}];
return (
<div>
<nav><Pagination items={this.state.NewData} onChangePage={this.onChangePage} /></nav>
<table>
<tbody>
<tr>
<th>New Data</th>
<th>Old Data</th>
</tr>
{this.state.pageOfItems.map(item =>
<tr key={item.id}><td key={item.id}>{item.name}</td>
<td><SuggestionInputSearch
recentSearches={recentSearches}
/></td></tr>
)}
</tbody>
</table>
</div>
);
}
}
OldData.json :
[
{
"id": 2900000,
"name": "Randu",
"admin_area": "lomu",
"country": "Portugal"
},
{
"id": 2900001,
"name": "Randu",
"admin_area": "lomu",
"country": "Portugal"
},
{
"id": 2900002,
"name": "Randu",
"admin_area": "lomu",
"country": "Portugal"
},
{
"id": 2900003,
"name": "Isis",
"admin_area": "lomu",
"country": "Portugal"
},
{
"name": "Randu",
"admin_area": "lomu",
"country": "Portugal"
},
{
"id": 2900005,
"name": "Satimola",
"admin_area": "Thuringen",
"country": "Taiwan"
},
...
NewData.json :
[
{
"id": 13610,
"name": "Satimola",
"admin_area": "USA"
},
{
"id": 4129,
"name": "Isis",
"admin_area": "UK"
},
{
"id": 14698,
"name": "Reban",
"admin_area": "Russia"
},
{
"id": 8194,
"name": "Randu",
"admin_area": "USA"
},
{
"id": 18867,
"name": "Randu",
"admin_area": "USA"
},
...
I have an object array and i am filtering it against property name "username" like this.
array = [{
"id": 1,
"username": "admin",
"roles": [{
"name": "Administrator"
},
{
"name": "agent"
}
]
},
{
"id": 2,
"username": "admin2",
"roles": [{
"name": "Administrator2"
},
{
"name": "agent2"
}
]
},
{
"id": 3,
"username": "admin3",
"roles": [{
"name": "Administrator3"
},
{
"name": "agent3"
}
]
}
]
and the filter function is like this
transform(array: any, valueToSearch: string): any[] {
return array.filter(e =>
e.username.toLowerCase().indexOf(valueToSearch.toLowerCase())
!== -1);
}
everything works fine, but now i want to filter against the property name "name" in "roles" array in the object. for example i would like to return an object whose "roles" array contains "name" = agent3 , so it should return the whole object which is located at the last in my example. i tried like
return agents.filter(e => e.roles.filter(ee =>
ee.valueToSearch.toLowerCase()) !== -1));
but it didn't work.
this is dmeo
https://stackblitz.com/edit/angular-txchxs?embed=1&file=src/app/agentFilter.pipe.ts
As per the example given by you in the question, i was able to change your existing function like this and i hope this is your requirement..
ngOnInit() {
this.transform(this.array,'agent3');
}
transform(array: any, valueToSearch: string): any[] {
return this.array.filter(e => {
e.roles.filter(ee => {
if(ee.name.toLowerCase() === valueToSearch.toLowerCase() ) {
console.log(e);
this.finalResult = e;
}
})
})
}
Working Stackblitz: https://stackblitz.com/edit/angular-uzgni7
myarray = [{
"id": 1,
"username": "admin",
"roles": [{
"name": "Administrator"
},
{
"name": "agent"
}
]
},
{
"id": 2,
"username": "admin2",
"roles": [{
"name": "Administrator2"
},
{
"name": "agent2"
}
]
},
{
"id": 3,
"username": "admin3",
"roles": [{
"name": "Administrator3"
},
{
"name": "agent3"
}
]
}
];
function myFunction(){
var filtered= myarray.filter((obj)=>{
return obj.username.match(new RegExp(document.getElementById('search').value,'ig'));
});
console.log(filtered);
};
<input type="text" id="search" onkeyup="myFunction()"/>
In angular 1, I have a tree list that I can filter at any level by searching a textbox. Here is a fiddle with a working demo.
I am trying to convert this to angular 2 with the results as shown in the provided picture.
I am stuck on converting this line of code to angular 2:
lvl_2.children = $filter('filter')(lvl_2.children, newVal);
Here is a Plunker with my current progress.
menu.components.ts
import { Component, OnInit, Injectable } from '#angular/core';
import { FilterArrayPipe } from '../shared/pipes/filter.pipe';
#Component({
selector: 'appc--menu',
templateUrl: './menu.component.html',
providers: [FilterArrayPipe]
})
export class MenuComponent implements OnInit {
constructor(private pipe: FilterArrayPipe) { }
ngOnInit() {
}
// todo: get data from a service
data: any = [{
"name": "Trade",
"children": [{
"name": "May 2013",
"children": [{
"name": "2013-05-12 Project X",
"children": []
}]
}, {
"name": "October 2013",
"children": [{
"name": "2013-10-12 Visualization project",
"children": []
}]
}, {
"name": "September 2013",
"children": [{
"name": "2013-09-12 Angular project",
"children": []
}]
}]
}, {
"name": "Logistics",
"children": [{
"name": "April 2014",
"children": [{
"name": "2014-04-14 Party fun project",
"children": []
}]
}, {
"name": "November 2014",
"children": [{
"name": "2014-11-01 Random project",
"children": []
}, {
"name": "2014-11-03 Arbitrary project",
"children": []
}, {
"name": "2014-11-14 Fun project",
"children": []
}]
}, {
"name": "October 2014",
"children": [{
"name": "2014-10-01 Another fun project",
"children": []
}, {
"name": "2014-10-03 Typing excercise",
"children": []
}, {
"name": "2014-10-05 No project",
"children": []
}, {
"name": "2014-10-07 Well paid project",
"children": []
}, {
"name": "2014-10-08 Even more awesome project",
"children": []
}]
}, {
"name": "September 2014",
"children": [{
"name": "2014-09-14 Last project",
"children": []
}]
}]
}];
filteredData: any = (this.data);
updateFilteredData = (newVal: string) => {
alert(newVal);
var filtered = (this.data);
filtered = filtered.map((lvl_1) => {
lvl_1.children = lvl_1.children.map((lvl_2) => {
lvl_2.children = this.pipe.transform(lvl_2.children, newVal);
return lvl_2;
});
return lvl_1;
});
this.filteredData = filtered.filter((lvl_1) => {
lvl_1.children = lvl_1.children.filter((lvl_2) => {
return lvl_2.children.length > 0;
});
return lvl_1.children.length > 0;
});
}
}
filter.pipe.ts
import { Pipe, PipeTransform } from '#angular/core';
#Pipe({
name: 'filter'
})
export class FilterArrayPipe {
transform(value, args) {
if (value && args && args != '') {
if (!args[0]) {
return value;
} else if (value) {
return value.filter(item => {
for (let key in item) {
if ((typeof item[key] === 'string' || item[key] instanceof String) &&
(item[key].toUpperCase().indexOf(args.toUpperCase()) !== -1)) {
return true;
}
else if ((typeof item[key] === 'number' || item[key] instanceof Number) &&
(item[key].toString().indexOf(args) !== -1)) {
return true;
}
}
});
}
}
return value;
}
}
menu.component.html
<div>
Welcome to the menu component!
<input type="search" #query (keyup)="updateFilteredData(query.value)" placeholder="Search..." />
<ul *ngFor="let lvl1 of filteredData ">
<li>
<h1>{{lvl1.name}}</h1>
<ul *ngFor="let lvl2 of lvl1.children ">
<li>
<h3>{{lvl2.name}}</h3>
<ul *ngFor="let lvl3 of lvl2.children ">
<li>
<p>{{lvl3.name}}</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>