Adding Search Filter to Content List

Topics: Customizing Orchard
Dec 22, 2014 at 8:43 PM
I need to add a search filter to the Content tab similar to the filter in the Modules tab that allows you to start typing in the field and it will hide any modules that don't have a name containing the text you typed in. I got this working by incorporating it in the current theme. I overrode the List.cshtml file in Orchard.Core/Contents/Admin and it works but I would like to make this a module instead so it isn't dependant upon a theme being installed. Is there a way to override the view using a module instead of the theme? Thank you.
Dec 22, 2014 at 10:09 PM
I think there is no another solution than override view in theme, but i'm not sure what if you try suppress/add shape table where list is created. Maybe it could works.
Dec 24, 2014 at 12:24 AM
Edited Dec 24, 2014 at 12:51 AM
Indeed, it works if you copy this List.cshtml file in your current front end theme/Views/List.cshtml. So, I tried to do the same in TheAdmin theme, but it failed. With the debugger, I saw that, in fact, I was overriding other shapes of List type. At the end of the List.cshtml file, you can see: Display(Model.ContentItems). I was overriding this part, but here the model isn't the same, e.g there is no Model.Options as it is used in our List.cshtml. I was also overriding this part: Display(Model.Pager), because the pager shape is also a "List" (Shape.Metadata.Type = "List"). So, with not the right model with the right view, the program fails

Indeed, we can override shape templates in a module (e.g by implementing an IShapeTableProvider). For the "List" shapes, you will have to differentiate between list types, e.g by checking metadata of child list items... But, here, our global List.cshtml isn't used to render a "List" shape, it's an MVC view that is used to render the "List" action of the Admin controller (area = Contents, controller = Admin, action = List). So, here, there are different patterns to override the default view (as in the Orchard doc). The most specialized is
{Active theme}/Views/{Area}/{Controller}/{View}.cshtml => FrontEndThemeOrTheAdmin/Views/Contents/Admin/List.cshtml
With this pattern (tested on a 1.x version) it works even if I use it in the TheAdmin theme. So, you can override the List.cshtml without being dependent on a current front end theme

In our case, with a less specialized pattern, it may not work or may override a "List" shape in place of our "List" MVC view


Note: If you really want to override this view via a module feature, you need to use your own contoller simply derived from the Orchard base AdminController (Orchard.Core.Contents.Controllers.AdminController), define a RouteDescriptor with a higher priority for the "List" action, and add your own "List" view in YourModule/Views/Admin/List.cshtml (area is not required here)... But it's not recommended
Marked as answer by emeraldarcher on 12/24/2014 at 3:40 PM