Hi Valter,
Greetings from Syncfusion.
Query: I've noticed that my Search action called multiple times during the page load.
Based on the attached code Snippet we found that you have not enabled searching feature in the grid but changed the pageSize when dynamically in the load event. At initial rendering of grid when we define allowPaging as true we need to get the records from the server-side based on the pageSize. So, when we change pageSize in load event the grid will be refreshed to bind the records based on the changed pageSize on the grid.
To get required records, the grid re-fires a call back to the server to get the data. It is the default behaviour. To avoid that you can set the pageSize based on the row Height when you define the grid code itself so which will not send multiple requests to servers.
Code Snippet:
|
Index.cshtml
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
}).AllowPaging().PageSettings(page =>{page.PageSize(7)}).ActionComplete("actionComplete").DataBound("dataBind").Render() |
Query: I couldn't found any documentation that allows me to do something like this in that script
Based on your query we have prepared sample in that we have used load event and in the load event we have assigned the datamanger to the grid datasource to render the grid with data properly.
We have attached the sample So please refer the sample for your reference.
Code Snippet:
|
Index.cshtml
@Html.EJS().Grid("CommandColumn").Load("onload").Columns(col =>
{
}
</div>
<script>
function onload(args) {
var hostUrl = 'https://ej2services.syncfusion.com/production/web-services/';
var data = new ej.data.DataManager({
url: hostUrl + 'api/Orders',
adaptor: new ej.data.WebApiAdaptor(),
crossDomain: true
});
var grid = document.getElementsByClassName("e-grid")[0].ej2_instances[0];
grid.dataSource = data;
}
</script> |
Regards,
Ajith G.