Marc Howard
Marc Howard

Reputation: 425

Grid MVC multiple filters

I am using grid mvc to display my data. I created a custom widget using the example to filter for a project, however this only filters on a single project. I created a check-box version which sends the HTTP parameter multiple times.

http://localhost:1653/AMUK/Channels?grid-filter=Project__1__0587%20Decom%20Legacy%20Sys&grid-filter=Project__1__0767%20Data%20Center%20Move

I have multiple filters set to true on the grid model, but no results are returned (it works if I just check one box).

enter image description here

Upvotes: 1

Views: 5070

Answers (2)

Aman Sharma
Aman Sharma

Reputation: 1990

I finally figured this out. I have blogged the response here: Multiple Values In Grid.Mvc Single Column Filter

WithMultipleFilters() option will not help you in this. That option enables multiple filters on different columns. To have multiple filters in the same column you need to update the way filtering works in the tool itself. I have updated the "GetFilterExpression" method in the "DefaultColumnFilter.cs" file in GridMvc class library. I have also updated the custom widget javascript. I have provided the link to the complete code sample too in my blog.

I hope this helps. Please let me know if you have any questions regarding my solution.

Upvotes: 2

acivic2nv
acivic2nv

Reputation: 99

If I understand you correctly, you are selecting the options, but it only ever filters on one. I had a similar experience where I would try to filter on different columns, but it would loose the previous filter. I looked though the source code and found a undocumented option where you tell it to allow multiple columns to filter on (WithMultipleFilters()). Below is the example code snip-it.

@Html.Grid(Model).AutoGenerateColumns().WithMultipleFilters()

Upvotes: 1

Related Questions