Preventing a grid's action event on client-side

3 posts, 0 answers
  1. ImNotTed
    ImNotTed avatar
    11 posts
    Member since:
    Oct 2013

    Posted 12 Dec 2013 Link to this post

    @(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. Alexander Popov
    Admin
    Alexander Popov avatar
    1444 posts

    Posted 13 Dec 2013 Link to this post

    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!
  3. ImNotTed
    ImNotTed avatar
    11 posts
    Member since:
    Oct 2013

    Posted 13 Dec 2013 Link to this post

    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!
Back to Top