Construct datasource URL based on search button click

2 posts, 0 answers
  1. Ravi
    Ravi avatar
    1 posts
    Member since:
    May 2015

    Posted 29 May 2015 Link to this post

    My requirement is like grid should not be loaded on page load and on click of search button it has to call WebAPI to get records, below is my code,

    @Html.DropDownList("SearchByEmployeeDropDown", new SelectList(ViewBag.EmpName, "Id", "Name"), "Select tag", htmlAttributes: new { @class = "emp-dropdown" })

    <input type="button" id="btnsearchbyemp" value="Search" onclick="BindGrid()">
      @(Html.Kendo().Grid<Employess>()
            .Name("Searchgrid")
    .Columns(columns =>
            {
                columns.Bound(c => c.EmpId).Width("15%").HtmlAttributes(new { title = " #= EmpId #" });
               columns.Bound(c => c.EmpName).Width("15%").HtmlAttributes(new { title = " #= EmployeeName# " });
            })
            .AutoBind(false) 
            .Filterable()
           .Selectable()
           .Scrollable()
            .Sortable()
            .Pageable()
            .Resizable(c=> c.Columns(true))
            .DataSource(dataSource => dataSource

               .Ajax()
               .Read(read => read.Url(**I want to construct URL based on search button click**).Type(HttpVerbs.Get))
               )    )
    //Function to read grid on search button click.

    function BindGrid() {;       
            var param1 = $("# SearchByEmployeeDropDown").val();
            $("#Searchgrid").data("kendoGrid").dataSource.read();
            $("#Searchgrid").data("kendoGrid").refresh();
    }

    //WebAPI  “/api/Search/EmployeeSearch”

    public DataSourceResult
    GetEmployeeSearchs([ModelBinder(typeof(DataSourceRequestModelBinder))]  DataSourceRequest dataRequest, string empId)
            {
                IEnumerable<Employee> searchlist = null;
                if (empId == null)
                {                return null;
                }
                return searchService.GetEmployeeDetails(empId);
            }

    My API url looks like ”/api/Search/EmployeeSearch/?empId=<<Selected value of combo>>”

    I have two question:

    1. Initially my api will return null value how will I bind null to kendo grid?

    2. How to pass data source URL on search button click?

     

    Please help me to resolve this. Thanks in advance!!





  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2565 posts

    Posted 03 Jun 2015 Link to this post

    Hello Ravi,

    Please check the following forum topic that discusses a similar problem:

    http://www.telerik.com/forums/change-data-url-on-mvc-grid

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top