function Home() {
const actionComplete = (args) => { //actionComplete event of Grid
if (args.requestType ===
"sorting" && !args.direction) {
var grid =
document.getElementById('Grid').ej2_instances[0]; //Grid
instances
var index =
args.target.closest("th").cellIndex;
var column
= grid.getColumnByIndex(index).field;
// here we sort the same
column with Ascending direction by using sortColumn method when a repetitive
third click on the same column
grid.sortColumn(column,
"Ascending", true);
}
}
return (
<div>
{' '}
<p>Grid-1 using
Functional Components</p>
<GridComponent
id="Grid"
dataSource={data}
allowSorting={true}
actionComplete={actionComplete}
>
<ColumnsDirective>
<ColumnDirective field="OrderID" isPrimaryKey={true}
headerText="Order ID" textAlign="Left" />
<ColumnDirective field="CustomerID" headerText="Customer
ID" textAlign="Center" />
<ColumnDirective field="ShipCity" headerText="Ship
City" textAlign="Center" />
<ColumnDirective
field="ShipCountry" headerText="Ship Country"
textAlign="Center" />
</ColumnsDirective>
<Inject services={[ Page, Search, Filter, Sort ]} />
</GridComponent>
</div>
);
}
|