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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DropDownList in the ToolBar of Grid

Thread ID:

Created:

Updated:

Platform:

Replies:

125675 Sep 1,2016 06:22 PM UTC Sep 2,2016 08:51 AM UTC ASP.NET MVC 1
loading
Tags: Grid
Marlon Luft Salvador
Asked On September 1, 2016 06:22 PM UTC

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?

@(Html.EJ().Grid<MyModel>("GridOutros")
        .Datasource(x => x.Json((IEnumerable<MyModel>)Model.Outros)
                .UpdateURL(Url.Action("OutrosUpdate", "MyController"))
                .InsertURL(Url.Action("OutrosInsert", "MyController"))
                .RemoveURL(Url.Action("OutrosDelete", "MyController"))
                .Adaptor(AdaptorType.RemoteSaveAdaptor))
        .EditSettings(edit =>
        {
            edit.AllowAdding()
            .AllowDeleting()
            .AllowEditing()
            .ShowDeleteConfirmDialog(true);
        })
        .ToolbarSettings(tool =>
        {
            tool.ShowToolbar().ToolbarItems(x =>
                {
                    x.AddTool(ToolBarItems.Add);
                    x.AddTool(ToolBarItems.Edit);
                    x.AddTool(ToolBarItems.Delete);
                    x.AddTool(ToolBarItems.Update);
                    x.AddTool(ToolBarItems.Cancel);
                });
        })
        .AllowPaging()
                .PageSettings(Page => { Page.PageSize(5); })
        .Columns(col =>
         ...

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On 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" /> 
</script> 
 
 
@(Html.EJ().Grid<OrdersView>("Editing") 
        .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource) 
             . . . 
            .Adaptor(AdaptorType.RemoteSaveAdaptor)) 
        .ToolbarSettings(toolbar => 
        { 
            toolbar.ShowToolbar() 
              . . .  
            .CustomToolbarItems( 
            new List<object>() {  
                new Syncfusion.JavaScript.Models.CustomToolbarItem() { TemplateID = "#Drop" }  
            }); 
        }) 
        .AllowFiltering() 
             . . . ..  
        .ClientSideEvents(events => events.DataBound("dataBound")) 
) 
 
<script> 
    var filterQuery = [ 
        { text: "Filter EmployeeID lt 5", value: "EmployeeIDlt5" }, 
        { text: "Filter EmployeeID gt 5", value: "EmployeeIDgt5" }, 
        { text: "Clear Filterting", value: "clearFilterting" } 
    ]; 
    function dataBound(args) { 
        $('#dropDown').ejDropDownList({ 
            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(); 
            } 
        }); 
    } 
 
</script> 
 
 


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. 


Regards, 
Seeni Sakthi Kumar S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;