pass parameter value from grid

Hi,
I have seen some examples where you use the .Query function in a grid to pass an extra parameter to the controller.  This works well for me but I can't seem to find an example of passing something other than a hardcoded value.  For example, if I had a couple of date picker control likes this:

@Html.EJ().DatePicker("ScanDateFrom").EnablePersistence(true).WatermarkText("Scan Date From").Value(ViewBag.datevalue) 
 @Html.EJ().DatePicker("ScanDateTo").EnablePersistence(true).WatermarkText("Scan Date To").Value(ViewBag.datevalue)

How would I pass those values to the controller when rendering my grid?

 @(Html.EJ().Grid<object>("ResponseRatesByState")
                    .ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>
                    {
                        items.AddTool(ToolBarItems.ExcelExport);
                    }))
                    .Mappers(map => map.ExportToExcelAction("ExportStateGrid"))
                   // .ClientSideEvents(events => events.Load("onLoad").DataBound("dataBound"))
                   .Datasource(ds => ds.URL(@Url.Action("ResponseRateByState"))
                   
                   .Adaptor(AdaptorType.UrlAdaptor))
                   .AllowPaging()
                   .Query("new ej.Query().addParams('scandate', ???????)")



1 Reply

MS Mani Sankar Durai Syncfusion Team November 23, 2017 11:51 AM UTC

Hi Richard, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and found that you are trying to pass the value to server side at initial time using addParams method.  

Based on your requirement we have prepared sample that can be downloaded from the below link 
Please refer the code example 
@(Html.EJ().Grid<object>("Editing") 
                   .Datasource(ds => ds.URL("/Home/UrlDataSource").Adaptor(AdaptorType.UrlAdaptor)) 
                       .AllowPaging() 
                       .Columns(col => 
        { 
... 
        }) 
 
    .ClientSideEvents(eve => eve.ActionBegin("begin")) 
) 
<script> 
    function begin(args) { 
        var value = @Html.Raw(Json.Encode(ViewBag.datevalue)) 
             this.model.query.addParams('scandate', value); 
} 
</script> 

From the above code example we have achieved it using actionBegin event in grid.  
Refer the documentation link 

Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 


Loader.
Up arrow icon