class EwdsUserBox extends React.Component {
constructor(props) {
super(props);
this.state = {
data: []
};
}
loadCommentsFromServer(page=0, count=25) {
const xhr = new XMLHttpRequest();
let params = "?page="+page+"&count=" + count;
xhr.open('get', this.props.url, true);
xhr.onload = function() {
var data = JSON.parse(xhr.responseText);
this.setState({ data: data});
}.bind(this);
xhr.send();
}
componentDidMount() {
this.loadCommentsFromServer(0,25);
}
render() {
const ewds = this.state.data;
var count = 0;
return (
<div className="ewdsUserBox body-content">
<EwdsUserSummary total={ewds.length} disabled={count} locked={0}/>
<EwdsUserTable data={ewds} />
</div>
);
}
}
This is for ReactJS but you'll notice I'm using an XMLHttpRequest to retrieve the JSON data. EwdsUserBox is just my container component. I'll then pass this data to subcomponents, in this case a user table and user row.
const EwdsUserTable = (props) => {
let counter = 0;
let ewdsData = props.data;
if (ewdsData) {
var ewdsUserRows = ewdsData.map(function (ewdsUser) {
return (
<EwdsUserRow ewdsUser={ewdsUser} key={counter++} />
);
});
}
return (
<div className="ewdsUserTable" >
<table id="mytable" className="table table-striped table-bordered table-condensed fixed">
<caption>EWDS Users</caption>
<thead>
<tr>
<th className="sort" type="string">User Name</th>
<th className="sort" type="string">Email Address</th>
<th>Pwd Changed</th>
<th type="date">Last Logon</th>
<th>Locked</th>
<th className="sort" type="string">Disabled</th>
<th></th>
</tr>
</thead>
<tbody>
{ewdsUserRows}
</tbody>
</table>
</div>
);
};
Here's where I'm actually displaying the data.
class EwdsUserRow extends React.Component {
render() {
const {UserName, EmailAddress, AccountCreated, PasswordChanged, AccountName,
Locked, Enabled} = this.props.ewdsUser;
return (
<tr>
<td>{UserName}</td>
<td>{EmailAddress}</td>
<td>{AccountCreated}</td>
<td>{PasswordChanged}</td>
<td>{Locked}</td>
<td>{Enabled}</td>
</tr>
);
}
}