REACT.JS populating a custom table head and body The Next CEO of Stack OverflowAdd table row in jQueryJSON, Javascript & Dynamically Created & Populated TablesPopulating dropdown menus using XMLHTTPREQUEST objectXML Parser and Google Maps Geocoding - Array Won't PopulatePass props to parent component in React.jsPerform debounce in React.jsReact.js inline style best practicesUnderstanding unique keys for array children in React.jsGenerate table body rows using ng-repeatTable inside Modal is populated every row and not individually
Players Circumventing the limitations of Wish
Can Sneak Attack be used when hitting with an improvised weapon?
How to find image of a complex function with given constraints?
Can this note be analyzed as a non-chord tone?
Point distance program written without a framework
What difference does it make using sed with/without whitespaces?
Why do we say 'Un seul M' and not 'Une seule M' even though M is a "consonne"
How to use ReplaceAll on an expression that contains a rule
In the "Harry Potter and the Order of the Phoenix" video game, what potion is used to sabotage Umbridge's speakers?
Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?
It is correct to match light sources with the same color temperature?
Is it correct to say moon starry nights?
Can I board the first leg of the flight without having final country's visa?
Help! I cannot understand this game’s notations!
Yu-Gi-Oh cards in Python 3
(How) Could a medieval fantasy world survive a magic-induced "nuclear winter"?
Is there a difference between "Fahrstuhl" and "Aufzug"?
My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?
Is it okay to majorly distort historical facts while writing a fiction story?
how one can write a nice vector parser, something that does pgfvecparseA=B-C; D=E x F;
What was Carter Burke's job for "the company" in Aliens?
Can I calculate next year's exemptions based on this year's refund/amount owed?
What happened in Rome, when the western empire "fell"?
Defamation due to breach of confidentiality
REACT.JS populating a custom table head and body
The Next CEO of Stack OverflowAdd table row in jQueryJSON, Javascript & Dynamically Created & Populated TablesPopulating dropdown menus using XMLHTTPREQUEST objectXML Parser and Google Maps Geocoding - Array Won't PopulatePass props to parent component in React.jsPerform debounce in React.jsReact.js inline style best practicesUnderstanding unique keys for array children in React.jsGenerate table body rows using ng-repeatTable inside Modal is populated every row and not individually
I'm trying to populate a table header and body with an array of objects. I feel that this is really inefficient. Is there a better way to do this?
clients:
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
]
let headers = [];
let body = [];
let i = 0;
for (var client of clients)
if (i === 0)
for (var key in client)
headers.push(key);
i++;
var ar = [];
for (var value of headers)
ar.push(client[value]);
body.push(ar);
javascript arrays reactjs
add a comment |
I'm trying to populate a table header and body with an array of objects. I feel that this is really inefficient. Is there a better way to do this?
clients:
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
]
let headers = [];
let body = [];
let i = 0;
for (var client of clients)
if (i === 0)
for (var key in client)
headers.push(key);
i++;
var ar = [];
for (var value of headers)
ar.push(client[value]);
body.push(ar);
javascript arrays reactjs
can you post an example of the Array of Objects that you are using?
– Ricardo Gonzalez
Mar 7 at 18:25
@RicardoGonzalez updated.
– Trae Moore
Mar 7 at 18:33
add a comment |
I'm trying to populate a table header and body with an array of objects. I feel that this is really inefficient. Is there a better way to do this?
clients:
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
]
let headers = [];
let body = [];
let i = 0;
for (var client of clients)
if (i === 0)
for (var key in client)
headers.push(key);
i++;
var ar = [];
for (var value of headers)
ar.push(client[value]);
body.push(ar);
javascript arrays reactjs
I'm trying to populate a table header and body with an array of objects. I feel that this is really inefficient. Is there a better way to do this?
clients:
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
]
let headers = [];
let body = [];
let i = 0;
for (var client of clients)
if (i === 0)
for (var key in client)
headers.push(key);
i++;
var ar = [];
for (var value of headers)
ar.push(client[value]);
body.push(ar);
let headers = [];
let body = [];
let i = 0;
for (var client of clients)
if (i === 0)
for (var key in client)
headers.push(key);
i++;
var ar = [];
for (var value of headers)
ar.push(client[value]);
body.push(ar);
let headers = [];
let body = [];
let i = 0;
for (var client of clients)
if (i === 0)
for (var key in client)
headers.push(key);
i++;
var ar = [];
for (var value of headers)
ar.push(client[value]);
body.push(ar);
javascript arrays reactjs
javascript arrays reactjs
edited Mar 7 at 18:32
Trae Moore
asked Mar 7 at 18:18
Trae MooreTrae Moore
1,24621427
1,24621427
can you post an example of the Array of Objects that you are using?
– Ricardo Gonzalez
Mar 7 at 18:25
@RicardoGonzalez updated.
– Trae Moore
Mar 7 at 18:33
add a comment |
can you post an example of the Array of Objects that you are using?
– Ricardo Gonzalez
Mar 7 at 18:25
@RicardoGonzalez updated.
– Trae Moore
Mar 7 at 18:33
can you post an example of the Array of Objects that you are using?
– Ricardo Gonzalez
Mar 7 at 18:25
can you post an example of the Array of Objects that you are using?
– Ricardo Gonzalez
Mar 7 at 18:25
@RicardoGonzalez updated.
– Trae Moore
Mar 7 at 18:33
@RicardoGonzalez updated.
– Trae Moore
Mar 7 at 18:33
add a comment |
2 Answers
2
active
oldest
votes
Here is a solution with 2 one-liners
const clients =
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
];
const header = Object.keys(clients[0]).map(key => key);
const body = clients.map(client => header.map(id => client[id]));
console.log(header)
console.log(body)
I didn't implement it in React because I think your issue is not React specific.
1
thank you very much. This was exactly what i was hoping for. Thanks for helping me learn something about JS.
– Trae Moore
Mar 7 at 19:25
thanks for your kind comment!
– Quentin C
Mar 7 at 19:27
add a comment |
Here is how you can do this.
Table
component takes the data as prop. The head section of the table is generated by getting the keys from the first object of the data array and mapping over them. Each table row is generated by mapping over the data and rendering a list of Row
components.
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
const data = [
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null
]
const Table = props =>
return (
<table>
<thead>
<tr>
Object.keys(data[0]).map(header => (
<th>header</th>
))
</tr>
</thead>
<tbody>
props.data.map(row => (
<Row column=row />
))
</tbody>
</table>
);
;
const Row = props =>
return (
<tr>
<td>props.column.Id</td>
<td>props.column.Name</td>
<td>props.column.Country</td>
<td>props.column.City</td>
<td>props.column.Salary</td>
<td>props.column.Actions == null ? "N.A" : props.column.Actions </td>
</tr>
);
;
function App()
return (
<div className="App">
<Table data=data />
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Hope this helps !
add a comment |
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050391%2freact-js-populating-a-custom-table-head-and-body%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is a solution with 2 one-liners
const clients =
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
];
const header = Object.keys(clients[0]).map(key => key);
const body = clients.map(client => header.map(id => client[id]));
console.log(header)
console.log(body)
I didn't implement it in React because I think your issue is not React specific.
1
thank you very much. This was exactly what i was hoping for. Thanks for helping me learn something about JS.
– Trae Moore
Mar 7 at 19:25
thanks for your kind comment!
– Quentin C
Mar 7 at 19:27
add a comment |
Here is a solution with 2 one-liners
const clients =
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
];
const header = Object.keys(clients[0]).map(key => key);
const body = clients.map(client => header.map(id => client[id]));
console.log(header)
console.log(body)
I didn't implement it in React because I think your issue is not React specific.
1
thank you very much. This was exactly what i was hoping for. Thanks for helping me learn something about JS.
– Trae Moore
Mar 7 at 19:25
thanks for your kind comment!
– Quentin C
Mar 7 at 19:27
add a comment |
Here is a solution with 2 one-liners
const clients =
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
];
const header = Object.keys(clients[0]).map(key => key);
const body = clients.map(client => header.map(id => client[id]));
console.log(header)
console.log(body)
I didn't implement it in React because I think your issue is not React specific.
Here is a solution with 2 one-liners
const clients =
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
];
const header = Object.keys(clients[0]).map(key => key);
const body = clients.map(client => header.map(id => client[id]));
console.log(header)
console.log(body)
I didn't implement it in React because I think your issue is not React specific.
const clients =
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
];
const header = Object.keys(clients[0]).map(key => key);
const body = clients.map(client => header.map(id => client[id]));
console.log(header)
console.log(body)
const clients =
[
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null,
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null,
];
const header = Object.keys(clients[0]).map(key => key);
const body = clients.map(client => header.map(id => client[id]));
console.log(header)
console.log(body)
answered Mar 7 at 19:08
Quentin CQuentin C
22810
22810
1
thank you very much. This was exactly what i was hoping for. Thanks for helping me learn something about JS.
– Trae Moore
Mar 7 at 19:25
thanks for your kind comment!
– Quentin C
Mar 7 at 19:27
add a comment |
1
thank you very much. This was exactly what i was hoping for. Thanks for helping me learn something about JS.
– Trae Moore
Mar 7 at 19:25
thanks for your kind comment!
– Quentin C
Mar 7 at 19:27
1
1
thank you very much. This was exactly what i was hoping for. Thanks for helping me learn something about JS.
– Trae Moore
Mar 7 at 19:25
thank you very much. This was exactly what i was hoping for. Thanks for helping me learn something about JS.
– Trae Moore
Mar 7 at 19:25
thanks for your kind comment!
– Quentin C
Mar 7 at 19:27
thanks for your kind comment!
– Quentin C
Mar 7 at 19:27
add a comment |
Here is how you can do this.
Table
component takes the data as prop. The head section of the table is generated by getting the keys from the first object of the data array and mapping over them. Each table row is generated by mapping over the data and rendering a list of Row
components.
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
const data = [
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null
]
const Table = props =>
return (
<table>
<thead>
<tr>
Object.keys(data[0]).map(header => (
<th>header</th>
))
</tr>
</thead>
<tbody>
props.data.map(row => (
<Row column=row />
))
</tbody>
</table>
);
;
const Row = props =>
return (
<tr>
<td>props.column.Id</td>
<td>props.column.Name</td>
<td>props.column.Country</td>
<td>props.column.City</td>
<td>props.column.Salary</td>
<td>props.column.Actions == null ? "N.A" : props.column.Actions </td>
</tr>
);
;
function App()
return (
<div className="App">
<Table data=data />
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Hope this helps !
add a comment |
Here is how you can do this.
Table
component takes the data as prop. The head section of the table is generated by getting the keys from the first object of the data array and mapping over them. Each table row is generated by mapping over the data and rendering a list of Row
components.
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
const data = [
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null
]
const Table = props =>
return (
<table>
<thead>
<tr>
Object.keys(data[0]).map(header => (
<th>header</th>
))
</tr>
</thead>
<tbody>
props.data.map(row => (
<Row column=row />
))
</tbody>
</table>
);
;
const Row = props =>
return (
<tr>
<td>props.column.Id</td>
<td>props.column.Name</td>
<td>props.column.Country</td>
<td>props.column.City</td>
<td>props.column.Salary</td>
<td>props.column.Actions == null ? "N.A" : props.column.Actions </td>
</tr>
);
;
function App()
return (
<div className="App">
<Table data=data />
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Hope this helps !
add a comment |
Here is how you can do this.
Table
component takes the data as prop. The head section of the table is generated by getting the keys from the first object of the data array and mapping over them. Each table row is generated by mapping over the data and rendering a list of Row
components.
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
const data = [
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null
]
const Table = props =>
return (
<table>
<thead>
<tr>
Object.keys(data[0]).map(header => (
<th>header</th>
))
</tr>
</thead>
<tbody>
props.data.map(row => (
<Row column=row />
))
</tbody>
</table>
);
;
const Row = props =>
return (
<tr>
<td>props.column.Id</td>
<td>props.column.Name</td>
<td>props.column.Country</td>
<td>props.column.City</td>
<td>props.column.Salary</td>
<td>props.column.Actions == null ? "N.A" : props.column.Actions </td>
</tr>
);
;
function App()
return (
<div className="App">
<Table data=data />
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Hope this helps !
Here is how you can do this.
Table
component takes the data as prop. The head section of the table is generated by getting the keys from the first object of the data array and mapping over them. Each table row is generated by mapping over the data and rendering a list of Row
components.
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
const data = [
Id: 0,
Name: "Camren Moore",
Country: "Wierdo Land",
City: "Oud-Turnhout",
Salary: "$36,738",
Actions: null
,
Id: 1,
Name: "Adison Moore",
Country: "Crazy Land",
City: "Oud-Turnhout",
Salary: "$23,738",
Actions: null
]
const Table = props =>
return (
<table>
<thead>
<tr>
Object.keys(data[0]).map(header => (
<th>header</th>
))
</tr>
</thead>
<tbody>
props.data.map(row => (
<Row column=row />
))
</tbody>
</table>
);
;
const Row = props =>
return (
<tr>
<td>props.column.Id</td>
<td>props.column.Name</td>
<td>props.column.Country</td>
<td>props.column.City</td>
<td>props.column.Salary</td>
<td>props.column.Actions == null ? "N.A" : props.column.Actions </td>
</tr>
);
;
function App()
return (
<div className="App">
<Table data=data />
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Hope this helps !
answered Mar 7 at 18:38
Hemant ParasharHemant Parashar
883414
883414
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050391%2freact-js-populating-a-custom-table-head-and-body%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
can you post an example of the Array of Objects that you are using?
– Ricardo Gonzalez
Mar 7 at 18:25
@RicardoGonzalez updated.
– Trae Moore
Mar 7 at 18:33