Add search functionality to transactions page

Added a search bar that allows users to filter transactions by:
- Transaction name
- Memo
- Category
- Notes
- Merchant name

The search uses a case-sensitive contains filter across all these
fields. The search parameter is preserved across pagination links and
included in the "Clear Filters" button logic.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
AJ
2025-10-12 11:06:50 -04:00
parent 158ae139f0
commit 61c9490eeb
2 changed files with 23 additions and 1 deletions

View File

@@ -13,6 +13,10 @@
<div class="card shadow-sm mb-3">
<div class="card-body">
<form method="get" class="row g-3">
<div class="col-md-12 mb-2">
<label for="Search" class="form-label">Search</label>
<input asp-for="Search" type="text" class="form-control" placeholder="Search by name, memo, category, notes, or merchant..." />
</div>
<div class="col-md-2">
<label for="Category" class="form-label">Category</label>
<select asp-for="Category" class="form-select">
@@ -55,7 +59,7 @@
<button type="submit" class="btn btn-primary w-100">Filter</button>
</div>
</form>
@if (!string.IsNullOrWhiteSpace(Model.Category) || !string.IsNullOrWhiteSpace(Model.Merchant) || !string.IsNullOrWhiteSpace(Model.CardId) || Model.StartDate.HasValue || Model.EndDate.HasValue)
@if (!string.IsNullOrWhiteSpace(Model.Search) || !string.IsNullOrWhiteSpace(Model.Category) || !string.IsNullOrWhiteSpace(Model.Merchant) || !string.IsNullOrWhiteSpace(Model.CardId) || Model.StartDate.HasValue || Model.EndDate.HasValue)
{
<div class="mt-2">
<a asp-page="/Transactions" class="btn btn-sm btn-outline-secondary">Clear Filters</a>
@@ -207,6 +211,7 @@ else
<a class="page-link"
asp-page="/Transactions"
asp-route-pageNumber="@(Model.PageNumber - 1)"
asp-route-search="@Model.Search"
asp-route-category="@Model.Category"
asp-route-merchant="@Model.Merchant"
asp-route-cardId="@Model.CardId"
@@ -223,6 +228,7 @@ else
<a class="page-link"
asp-page="/Transactions"
asp-route-pageNumber="1"
asp-route-search="@Model.Search"
asp-route-category="@Model.Category"
asp-route-merchant="@Model.Merchant"
asp-route-cardId="@Model.CardId"
@@ -241,6 +247,7 @@ else
<a class="page-link"
asp-page="/Transactions"
asp-route-pageNumber="@i"
asp-route-search="@Model.Search"
asp-route-category="@Model.Category"
asp-route-merchant="@Model.Merchant"
asp-route-cardId="@Model.CardId"
@@ -259,6 +266,7 @@ else
<a class="page-link"
asp-page="/Transactions"
asp-route-pageNumber="@Model.TotalPages"
asp-route-search="@Model.Search"
asp-route-category="@Model.Category"
asp-route-merchant="@Model.Merchant"
asp-route-cardId="@Model.CardId"
@@ -274,6 +282,7 @@ else
<a class="page-link"
asp-page="/Transactions"
asp-route-pageNumber="@(Model.PageNumber + 1)"
asp-route-search="@Model.Search"
asp-route-category="@Model.Category"
asp-route-merchant="@Model.Merchant"
asp-route-cardId="@Model.CardId"

View File

@@ -19,6 +19,9 @@ namespace MoneyMap.Pages
_db = db;
}
[BindProperty(SupportsGet = true)]
public string? Search { get; set; }
[BindProperty(SupportsGet = true)]
public string? Category { get; set; }
@@ -58,6 +61,16 @@ namespace MoneyMap.Pages
.AsQueryable();
// Apply filters
if (!string.IsNullOrWhiteSpace(Search))
{
query = query.Where(t =>
t.Name.Contains(Search) ||
(t.Memo != null && t.Memo.Contains(Search)) ||
(t.Category != null && t.Category.Contains(Search)) ||
(t.Notes != null && t.Notes.Contains(Search)) ||
(t.Merchant != null && t.Merchant.Name.Contains(Search)));
}
if (!string.IsNullOrWhiteSpace(Category))
{
if (Category == "(blank)")