Reputation: 5941
is there any way to prevent default ajax request? I am refreshing grid after I will make all configuration in java script and then I am starting request, but somehow this kendo grid is request for data automatically when page is loaded.
@(Html.Kendo().Grid<Data>()
.Name("grid")
.HtmlAttributes(new { Class = "acceleratorGrid" })
.TableHtmlAttributes(new { Class = "styled", cellpadding = "0", border = "0", margin = "0" })
.Events(e => e.Change("onChange"))
.DataSource(dataSource => dataSource // Configure the grid data source
.Ajax() // Specify that ajax binding is used
.Read(read => read.Action("Products_Read", "Home")) // Set the action method which will return the data in JSON format
)
.Columns(columns =>
{
columns.Bound(product => product.ProductID).Template(@<text></text>).ClientTemplate("<input type='checkbox' onclick='return false' name='checkedRecords' />");
columns.Bound(product => product.ProductName);
columns.Bound(product => product.UnitsInStock);
}
).Selectable(s => s.Mode(GridSelectionMode.Single))
)
Upvotes: 4
Views: 6764
Reputation: 1989
Just as a quick intro as to why this is occurring: When the Kendo UI Grid does not have any data tied to it, but does have a read transport configuration option set up, it will trigger a request to grab data. Same goes for sorting, paging, filtering, grouping, etc., when you are working with Ajax binding and a subset of items for the page size.
Anyways, as for a solution there are a few ways you can set this up.
Maybe the easiest would just be to utilize the requestStart event of the Grid's DataSource and cancel any data request that does not fit your criteria.
You can also work with the autoBind configuration option as mentioned in the comment to your post.
Alternatively you could just define a DataSource outside of the Grid in JavaScript and then wait to assign it to the Grid once your required scenario has occurred. The Grid's DataSource property can be accessed and assigned to via some easy JS, and the Grid would not start a request until it has properly been assigned a DataSource.
Overall I recommend keeping the Kendo UI documentation close at hand for this scenario, as it will give you all of the events and configuration options for the Grid and DataSource. Mostly for the JS side of things, but you'll most likely need to use JS either way for this particular scenario.
Upvotes: 5