Overview
TheSearchComponent provides a reusable search and table interface with sorting capabilities. It leverages the SearchService for data management and pagination, and uses the BaseSortableHeader directive for column sorting functionality. This component is designed for displaying searchable lists of data models.
Component metadata
Component selector used in templates
This component is not standalone and must be declared in a module
Path to the component template
Path to the component styles
Properties
Observable properties
Observable stream of the current page of data models. Populated from
searchService.Pagelist.Observable stream of the total number of records. Populated from
searchService.total.View queries
Collection of sortable header directives in the template. Used to manage sorting state across multiple columns.
Configuration
String representation of the config role, likely used for permission checks or role-based rendering.
Constructor dependencies
Service that manages search state, pagination, sorting, and data retrieval. Provides observables for page list and total count.
Methods
onSort()
Handles column sort events from sortable headers.The column identifier to sort by
The sort direction (ascending, descending, or none)
- Resets all other column headers to unsorted state
- Updates the
searchService.sortColumnwith the selected column - Updates the
searchService.sortDirectionwith the selected direction - The service automatically re-fetches and sorts the data
ngOnInit()
Angular lifecycle hook for component initialization.Template structure
The template is minimal in the current implementation:The actual search UI (input fields, table, pagination controls) would typically be implemented in this template, utilizing the component’s properties and methods.
Usage examples
- Module declaration
- Template usage
- With search service
Typical implementation pattern
While the template shows placeholder content, a complete implementation would typically include:Sorting mechanism
The sorting system works through coordination between the component and directive:- User clicks on a sortable column header
BaseSortableHeaderdirective emits a_BaseSortEventonSort()method receives the event- All other headers are reset to prevent multi-column sorting
- The clicked header’s direction is preserved
- Sort parameters are passed to
SearchService - Service updates the data observables with sorted results
Integration with SearchService
The component heavily relies onSearchService for:
Reactive data stream for the current page of results
Reactive stream for total record count
Current sort column identifier
Current sort direction
Key features
Reactive data binding
Uses RxJS observables for automatic UI updates:Single-column sorting
Ensures only one column is sorted at a time by resetting other headers:Role-based configuration
Includes role string for potential permission-based features:Related types
Base model interface for data items displayed in the search results
Event interface containing
_column and _direction propertiesEnum containing role definitions including
RoleConfigSource location
- TypeScript:
~/workspace/source/src/app/_components/search/search.component.ts - Template:
~/workspace/source/src/app/_components/search/search.component.html - Styles:
~/workspace/source/src/app/_components/search/search.component.css