Configure the AI Semantic Search in .NET MAUI DataGrid
This article provides information on how to configure the AI Semantic Search functionality in the .NET MAUI DataGrid control.
Semantic Search Settings
Configure the semantic search through the SemanticSearchSettings property of the RadDataGrid. The DataGridSemanticSearchSettings class inherits from DataGridSearchSettingsBase and exposes the following key members:
SearchText(string)—Defines the search text. Before a search starts, this value is trimmed, and theSearchStartingevent is raised allowing you to change the effective search text.IntermediateSearchText(string)—Specifies the text of the search entry. Changes to this value do not necessarily trigger a search—theSearchTextproperty is updated according to theSearchTriggerproperty.ProvideSearchMatchesAction(Action<DataGridSearchProbe>)—Specifies the callback invoked for each cell to determine semantic matches. The callback receives aDataGridSemanticSearchCellProbeinstance.ApplyFilter(bool)—Specifies a value indicating whether rows that do not match the search criteria are filtered out.SearchTrigger(DataGridSearchTrigger)—Specifies when a search operation is performed—TextChanged(default) triggers on every keystroke,Completedtriggers onEnter/Returnkey.
Semantic Search Cell Probe
When the ProvideSearchMatchesAction callback is invoked, it receives a DataGridSemanticSearchCellProbe object. This probe provides the following properties:
SearchText(string)—Gets the semantic-search text that should be searched for.Column(DataGridColumn)—Gets the column of the cell being evaluated for search matches.CellValue(object)—Gets the value of the cell being evaluated.IsMatch(bool)—Specifies whether the cell is a semantic match. Setting this totrueadds the cell to the search results.Item(object)—Gets the data item (business object) associated with the current row.ItemText(string)—Gets the text displayed in the DataGrid.Matches(List<DataGridSearchMatch>)—Gets a collection of search matches for the associated item.CancellationToken(CancellationToken)—A token that is canceled when the current search operation is canceled.
Events
The DataGridSemanticSearchSettings class provides the following events:
-
SearchStarting—Raised before searching starts. TheSearchStartingevent handler receives the following parameters:- The
senderargument, which is of typeobject. - A
DataGridSearchStartingEventArgsobject. TheDataGridSearchStartingEventArgsprovides the following properties:SearchTerms(IList<string>)—Gets or sets the search terms to search for.SearchTermsLogicalOperator(LogicalOperator)—Gets or sets the logical operator used when more than one search term is present.Cancel(bool)—Gets or sets a value indicating whether to cancel the search.
- The
-
SearchCompleted—Raised after searching is completed. TheSearchCompletedevent handler receives the following parameters:- The
senderargument, which is of typeobject. - An
EventArgsobject.
- The
AISettings and Semantic Search Properties
Use the following properties from the AI Settings to configure the Semantic Search functionality in the DataGrid:
ViewMode(DataGridAIViewMode)—Specifies the view mode of the AI Smart Assistant. The options areSearchandAIAssistant.Placeholder(string)—Specifies the placeholder text for the search input field.SearchMode(DataGridAISearchMode)—Specifies the search mode of the AI Assistant. The options areTextSearchandSemanticSearch.RecentTextSearches(IEnumerable<string>)—Specifies the collection of recent keyword searches.RecentSemanticSearches(IEnumerable<string>)—Specifies the collection of recent semantic searches.IsTextSearchOptionVisible(bool)—Specifies whether the keyword search mode is enabled. The default value istrue.IsSemanticSearchOptionVisible(bool)—Specifies whether the semantic search mode is enabled. The default value istrue.AreRecentTextSearchesVisible(bool)—Specifies whether the recent keyword searches are visible. The default value istrue.AreRecentSemanticSearchesVisible(bool)—Specifies whether the recent semantic searches are visible. The default value istrue.SearchDebounceDelay(TimeSpan)—Specifies the delay before a search is triggered after the user stops typing. The default value is500ms.
To hide the AI Smart Assistant functionality, set the IsSuggestedPromptsVisible and IsRecentPromptsVisible properties to false.