Search This Blog

Serenity Search and Filter Options

Serenity Search Options


A search box is added by default if we auto generate code from SERGEN. This search box can perform search only on first textual field of table. Sergen automatically determines first textual field of a table and adds a [QuickSearch] attribute on it that specifies that text searches should be performed on it.

We can also manually add [QuickSearch] attribute and make these fields searchable. [QuickSearch] attribute can be added on field property in classRow.cs or classColumns.cs files.

We can further customize the search by its paramaters, 

[QuickSearch(SearchType = SearchType.Auto, numericOnly = -1, isExplicit = false)]


We can also add the functionality of allowing user to choose his search field by adding a dropdown on search box. For this we add the following function in classGrid.ts file.


protected getQuickSearchFields() : Serenity.QuickSearchField[] {            
            return [
                { name: "", title: "all" },
                { name: MovieRow.Fields.Description, title: "description" },
                { name: MovieRow.Fields.Storyline, title: "storyline" },
                { name: MovieRow.Fields.Year, title: "year" }
            ];
        }


In the above function, suppose the name of our table is movie and its columns are title, description, storyline and year. And Title "all" will search in every field with [QuickSearch] attribute.



Serenity Filtering Options



To add the filter on field we can use [QuickFilter] attribute. This attribute can be add on fields in classRow.cs or classColumns.cs files. QuickFilter can be a textbox or a dropdown list. 

To make the QuickFilter Dropdowns, the field should be Enum type or a foreign key with [LookupEditor] attribute. Serenity understands these relations, and determines editor type to use by looking at attributes.


Note : In order to enable "Edit Filter" link below every grid, add @Serenity.Decorators.filterable() above the class definition in classGrid.ts file.
   

No comments:

Post a Comment

Web Statistics