This is a migrated thread and some comments may be shown as answers.

Preventing a grid's action event on client-side

2 Answers 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ImNotTed
Top achievements
Rank 1
Iron
ImNotTed asked on 12 Dec 2013, 03:15 PM
@(Html.Kendo().Grid<SearchViewModel>()
    .Name("searchGrid")
    .Columns(columns =>
    {
      columns.Bound(x => x.ProductId);
      columns.Bound(x => x.ProductName);
    })
    .AutoBind(false)
    .DataSource(ds => ds
      .Ajax()
      .Read(read => read.Action("Search", "Product").Data("getSearchCriteria"))
      )
    )
)
function getSearchCriteria() {
  var product = $("#ProductName").data("kendoAutoComplete").value();
  var productType = $("#ProductType").data("kendoDropDownList").select();
 
  if (product || productType) {
    return { ProductName: product, ProductType: productType };
  } else {
    // TODO: Figure out how to cancel this request.
    alert("You must provide at least one search parameter.");
    return false;
  }
}
I have a Kendo grid that I'm using to display search results on an MVC page. I'm using a function called "getSearchCriteria" to gather the search criteria from the page so it can all be sent to the controller's search method.

Everything works great when search criteria is supplied. However, I can't find a way to cancel the request from the client side if no search criteria was supplied. Returning either "false" or "null" from the "getSearchCriteria" function has no effect.

Is there any way to tell the Kendo grid not to invoke the controller's action at this point in time?

2 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 13 Dec 2013, 11:16 AM
Hello Brian,

The Data method is used to pass additional data to the Controller and cannot prevent sending the request. I would recommend not calling the Grid's dataSource.read method unless there is at least one search parameter.

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ImNotTed
Top achievements
Rank 1
Iron
answered on 13 Dec 2013, 01:13 PM
I suppose I could put some javascript into the button's event to handle this. I was just hoping that there was another way around this without having to look at the same fields multiple times.

Thanks!
Tags
Grid
Asked by
ImNotTed
Top achievements
Rank 1
Iron
Answers by
Alexander Popov
Telerik team
ImNotTed
Top achievements
Rank 1
Iron
Share this question
or