|
const loadData = () => {
const ajax = new Ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
});
ajax.send().then();
ajax.onSuccess = result => {
this.grid.dataSource = JSON.parse(result);
this.grid.hideSpinner(); // hide the spinner
};
useEffect(() => {
loadData();
});
<GridComponent
ref={r => (this.grid = r)}
dataSource={[]}
allowPaging={true}
pageSettings={{ pageSize: 6 }}
editSettings={editOptions}
toolbar={toolbarOptions}
>
.
.
.
</ GridComponent> |
|
// send request to server side method.
const ajax = new Ajax({
type: "POST",
url: ". . . . . ", // server side method url.
contentType: "application/json; charset=utf-8",
});
ajax.send().then();
ajax.onSuccess = result => {
this.grid.dataSource = JSON.parse(result);
}; |
|
<ColumnDirective field='Verified' headerText='Verified' displayAsCheckBox={true} editType='booleanedit'
width='150'/> |
|
[FetchEmployee.tsx]
return (<div className='control-section'>
<button onClick={this.handleClick}>Submit</button>
. . . .
</div>)
public handleClick(args: any) {
const ajax = new Ajax({
type: "POST",
url: "/Home/PersonnelList",
contentType: "application/json; charset=utf-8",
});
var data = JSON.stringify({ Username: 'hello', Password: 123456 });
ajax.send(data).then();
ajax.onSuccess = result => {
console.log(JSON.parse(result));
};
} |
Hi, just tried out the sample you have prepared on
https://stackblitz.com/edit/ej2-react-grids-dialog-template-modified-hj41qm?file=index.tsx
But it does not work. You have used 'this' in a functional component, like
Also, for some reason you have commented out the showSpinner function.
Making a grid show some loding indicator when loading large async data is important so I really think you should fix this example.
Tor,
Based on your requirement we have modified the shared sample in which we have dynamically set the Grid dataSource with an Ajax request. Please refer to the below sample link for more information.
https://stackblitz.com/edit/ej2-react-grids-dialog-template-modified-jdogax?file=index.tsx