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

Construct datasource URL based on search button click

1 Answer 43 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ravi
Top achievements
Rank 1
Ravi asked on 29 May 2015, 02:31 PM

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!!





1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 03 Jun 2015, 03:54 PM

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!
 
Tags
General Discussions
Asked by
Ravi
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or