I am very new to React and I am trying to use DataTables with table which I create in render(). So far my code looks like this- searchForm.js:
componentDidMount() {
$(this.refs.table).DataTable({});
}
render() {
var headerComponents = this.generateHeaders(),
rowComponents = this.generateRows();
return (
<div>
<form onSubmit={this.handleSubmit}>
<input className="resizedTextbox" type="text" value={this.state.searchString} onChange={this.handleChange} placeholder="Enter Material to search"/>
<br />
<br />
<input className="btn btn-primary" type="submit" value="Search" />
<button type="button" className="btn btn-primary" onClick={this.resetSearch}>Reset</button>
</form>
<br />
<div className="table-responsive">
<table ref="table" className="table">
<thead> {headerComponents} </thead>
<tbody> {rowComponents} </tbody>
</table>
</div>
</div>
);
}
Index.html:
<!DOCTYPE html>
<html>
<body>
<header style="background-color: #990000;margin-top: 0;position: relative;top: -10px;">
<h1 style="margin-top: 0;color: white;padding: 10px;">DMFT Search</h1>
</header>
<div align="center" >
<div id="main"></div>
</div>
<div id="search"></div>
<!-- scripts -->
<script src="{{ url_for('static', filename='bower_components/jquery/dist/jquery.min.js') }}"></script>
<script src="{{ url_for('static', filename='bower_components/react/react.js') }}"></script>
<script src="{{ url_for('static', filename='bower_components/react/react-dom.min.js') }}"></script>
<script src="{{ url_for('static', filename='scripts/js/searchForm.js') }}"></script>
<script src="{{ url_for('static', filename='bower_components/datatables.net/js/jquery.dataTables.js') }}"></script>
</body>
</html>
The problem is that when I load the index.html, I do not see DataTables working, I get an exception in console :
Uncaught TypeError: $(...).DataTable is not a function
at SearchForm.componentDidMount
Kindly advise if I am doing it the right way. I did not find ant help regarding this.