Added custom search functionality
This commit is contained in:
@@ -239,9 +239,16 @@
|
||||
|
||||
var eventResult = await PluginOrchestrator.DispatchEvent(new SearchEvent(this) {
|
||||
SearchTerm = _searchTerm,
|
||||
Table = _config!
|
||||
Table = _config!,
|
||||
CurrentPage = _currentPage
|
||||
}, _tokenSource.Token);
|
||||
if (eventResult.IsCanceled) return;
|
||||
if (eventResult.IsCanceled) {
|
||||
if (eventResult.SearchResult is null) return;
|
||||
|
||||
CurrentlyDisplayedModels = eventResult.SearchResult.ToArray();
|
||||
_totalPages = eventResult.TotalPages;
|
||||
return;
|
||||
}
|
||||
_searchTerm = eventResult.SearchTerm;
|
||||
|
||||
await Reload();
|
||||
@@ -259,7 +266,7 @@
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_searchTerm)) {
|
||||
(var query, _totalPages) = await _manager!.Search(_searchTerm, 0, PerPage);
|
||||
(var query, _totalPages) = await _manager!.Search(_searchTerm, _currentPage, PerPage);
|
||||
CurrentlyDisplayedModels = query.ToArray();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
using HopFrame.Web.Components.Pages;
|
||||
using System.Collections;
|
||||
using HopFrame.Web.Components.Pages;
|
||||
|
||||
namespace HopFrame.Web.Plugins.Events;
|
||||
|
||||
public sealed class SearchEvent(HopFrameTablePage sender) : HopFrameTablePageEventArgs(sender) {
|
||||
public required string SearchTerm { get; set; }
|
||||
public required int CurrentPage { get; init; }
|
||||
internal IEnumerable<object>? SearchResult { get; set; }
|
||||
internal int TotalPages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the new search result that is being displayed<br />
|
||||
/// The event needs to be canceled in order for the custom search results to appear
|
||||
/// </summary>
|
||||
/// <param name="result">The current page of search results</param>
|
||||
/// <param name="totalPages">The total pages of search results</param>
|
||||
public void SetSearchResult(IEnumerable result, int totalPages) {
|
||||
SearchResult = result.OfType<object>();
|
||||
TotalPages = totalPages;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user