I have a Kendo UI Grid instance that has an inline DataSource making a call to a RESTful web service.
I have set the "autoBind": false
property of the Grid because I don't want to pull the data when the page loads.
I want to manually trigger the dataSource.read()
method, but don't know how to using React.
I'm using create-react-app to set up my environment, which uses webpack.
I would like to trigger the Grid's DataSource read method when a button is pressed.
I have tried calling this.state.grid.ds.read
, which should call the read method of the DataSource, but it seems to only access the property value.
I'm not sure if I need to get an instance of the Grid object or DataSource object so that I can call the read() method and not reference the property.
I have tried read(), but I get an console error saying that read is not defined as a method.
this.state.grid.ds.read()
Below is a snippet of the code for reference:
class App extends Component {
constructor(props) {
super(props);
this.state = {
gridOptions: {
autoBind: false,
dataSource: {
transport: {
read: {
url: "http://localhost:8080/students",
dataType: "json"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "id",
fields: {
id: { type: "string" },
firstName: { type: "string"},
lastName: { type: "string"},
country: { type: "string" }
}
}
}
},
pageable: true,
height: 550,
columns: [
{ field: "id", title: "Student/Teacher" },
{ field: "firstName", title: "First Name" },
{ field: "lastName", title: "Last Name" },
{ field: "country", title: "Country" },
{ command: ["edit", "destroy"], title: " ", width: "250px" }
],
editable: "inline"
}
}
}
refreshDS(){
this.state.grid.ds.read
}
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
<button
onClick={this.refreshDS()}>
Refresh Grid
</button>
</p>
<br />
<Grid
{...this.state.gridOptions} />
</div>
);
}
}
Any help is appreciated.