I'm having trouble in React Js. My data table is successfully populated but still showing "No data available in table" on the first row https://i.sstatic.net/nrZaL.jpg
This is screenshot of displayed html https://i.sstatic.net/JUxkz.jpg
Also when I using the sorting and search thingy all my data will be gone and just displays "No data available in table"
Network result : https://i.sstatic.net/zTOpZ.jpg My code to display data from database
class Uptime extends Component {
constructor(props) {
super(props);
this.state = {
error: null,
isLoaded: false,
data: []
}
}
componentDidMount() {
fetch('/uptime')
.then(res => res.json())
// .then(res => res.text()) // convert to plain text
// .then(text => console.log(text))
.then(
(result) => {
this.setState({
isLoaded: true,
data: result.data
})
},
(error) => {
this.setState({
isLoaded: true,
error
})
}
)
}
render() {
const {error, isLoaded, data} = this.state;
// if (error) {
// return <div>Error: {error.message}</div>;
// } else if (!isLoaded) {
// return (
// <div className="spinner-border text-primary" role="status">
// <span className="sr-only">Loading...</span>
// </div>
// )
// } else { WHEN I ADD THIS CODE, THE SEARCH FUNCTION AND SORT FUNCtION IS GONE , SO I JUST REMOVE IT
return (
<div id="content-wrapper" className="d-flex flex-column">
<div id="content">
<div className="container-fluid">
<div className="card shadow mb-4 mt-5">
<div className="card-header py-3 text-center">
<h6 className="m-0 font-weight-bold text-primary">DataTables Example</h6>
</div>
<div className="card-body">
<div className="table-responsive">
<table className="table table-bordered" id="dataTable" width="100%"
cellSpacing="0">
<thead>
<tr>
<th width="10%">Name</th>
<th width="40%">Url</th>
<th width="10%">Downtime</th>
<th width="20%">date</th>
<th width="10%">Status Code</th>
</tr>
</thead>
<tbody>
{data.map(item => (
<tr key={item[0]}>
<td>{item[1]}</td>
<td>{item[2]}</td>
<td>{item[5]}</td>
<td>{item[4]}</td>
<td>{item[3]}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<footer className="sticky-footer bg-white">
<div className="container my-auto">
<div className="copyright text-center my-auto">
<span>Copyright © Your Website 2019</span>
</div>
</div>
</footer>
</div>
)
}
}