We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DropDownList in the ToolBar of Grid

Hi, i'm doing a grid in MVC and i need to create a dropdownlist with categories to filter the grid data.

Could you provide me an example?

        .Datasource(x => x.Json((IEnumerable<MyModel>)Model.Outros)
                .UpdateURL(Url.Action("OutrosUpdate", "MyController"))
                .InsertURL(Url.Action("OutrosInsert", "MyController"))
                .RemoveURL(Url.Action("OutrosDelete", "MyController"))
        .EditSettings(edit =>
        .ToolbarSettings(tool =>
            tool.ShowToolbar().ToolbarItems(x =>
                .PageSettings(Page => { Page.PageSize(5); })
        .Columns(col =>

1 Reply

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 2, 2016 08:51 AM UTC

Hi Marlon, 

We suspect that you would like to filter the Grid data by selecting values in the dropdown which has been rendered in the toolbar of the Grid.  

You can place the DropDownList control in Grid toolbar using “CustomToolbarItem” property of Grid ToolbarSettings. In the change event of the DropDownlist, you can filter the Grid using the filterColumn Grid method. To clear the filtered records, you can use the clearFiltering method of the Grid. We have rendered the ejDropDownlist control in the DataBound event of the Grid. Refer to the following code example. 

<script id="Drop" type="text/x-jsrender"> 
    <input id="dropDown" /> 
        .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource) 
             . . . 
        .ToolbarSettings(toolbar => 
              . . .  
            new List<object>() {  
                new Syncfusion.JavaScript.Models.CustomToolbarItem() { TemplateID = "#Drop" }  
             . . . ..  
        .ClientSideEvents(events => events.DataBound("dataBound")) 
    var filterQuery = [ 
        { text: "Filter EmployeeID lt 5", value: "EmployeeIDlt5" }, 
        { text: "Filter EmployeeID gt 5", value: "EmployeeIDgt5" }, 
        { text: "Clear Filterting", value: "clearFilterting" } 
    function dataBound(args) { 
            dataSource: filterQuery, 
            change: function (args) { 
                var obj = $("#Editing").ejGrid("instance"); 
                if (args.selectedValue == "EmployeeIDlt5") 
                    obj.filterColumn("EmployeeID", "lessthan", 5, "and"); 
                else if (args.selectedValue == "EmployeeIDgt5") 
                    obj.filterColumn("EmployeeID", "greaterthan", 5, "and"); 
                else obj.clearFiltering(); 

Note: To use the filterColumn Grid method, you must enable the AllowFiltering API of the Grid.  

Refer to the following Help Documents. 

We have also prepared a sample that can be downloaded from the following location. 

Seeni Sakthi Kumar S. 

Live Chat Icon For mobile
Up arrow icon