I build a simple site where you can select a city from a drop down menu and it will fetch the data and show all the banks in the city. But there are so many banks in a city that the page becomes really long and loading takes too much time. I want to add pagination. How am I suppose to do that? Below is my code
App.js
import './App.css';
import BankRow from './bankRows.js'
import $ from 'jquery';
class App extends Component {
constructor(props){
super(props)
this.state={}
this.performSearch("")
}
performSearch(searchTerm){
const urlString="https://.herokuapp.com/banks?city="+searchTerm
$.ajax({
url: urlString,
success: (searchResults)=>{
console.log("Fetched data successfully")
var bankRows=[]
searchResults.forEach((bank)=>{
const bankRow=<BankRow key={bank.ifsc} bank={bank}/>
bankRows.push(bankRow)
})
this.setState({rows: bankRows})
},
error: (xhr, status, err)=>{
console.error("Failed to fetch data")
}
})
}
searchChangeHandler(event){
const boundObject=this
const searchTerm=event.target.value.toUpperCase()
boundObject.performSearch(searchTerm)
}
render(){
return (
<div>
<table className="titleBar">
<tbody>
<tr>
<td>
<h1>Bank Search</h1>
</td>
</tr>
</tbody>
</table>
<select className="broad-input" onChange={this.searchChangeHandler.bind(this)}>
<option value="Choose">Choose</option>
<option value="#">#</option>
<option value="#">##</option>
</select>
{this.state.rows}
</div>
);
}
}
export default App;