- Home
- Forum
- ASP.NET MVC
- DropDownList in the ToolBar of Grid
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?
@(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 =>
...
SIGN IN To post a reply.
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" />
</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.
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
ML Marlon Luft Salvador
- Sep 1, 2016 06:22 PM UTC
- Sep 2, 2016 08:51 AM UTC