teresaleelim / intprojectmanagement

1 stars 0 forks source link

Grid Filter Memory #44

Closed junwoolee00 closed 4 months ago

junwoolee00 commented 4 months ago

Make a way to make ti so pages remember the grid filtering applied

junwoolee00 commented 4 months ago

Image

Image

Made it store current filters applied on local storage and then apply it to the grid upon loading page

junwoolee00 commented 4 months ago

https://www.evernote.com/shard/s728/sh/62d0c1ce-a4c9-ba48-b86a-56f4975c199f/N34uQOnKcznEhYnIUP4VWuzQN2D6IEzIW2CQCVn4zjBEGUoCbQaPM1_TNQ

FilterDataDTO.cs

using System.ComponentModel.DataAnnotations;

namespace IntsaWeb_Server.Service.Dto
{
    public class FilterDataDTO
    {
        public string LSKey { get; set; } = "GridFilters";
        public string PageUrl { get; set; }
        public List<FilterItem> Filters { get; set; } = new List<FilterItem>();

        public FilterDataDTO(string pageUrl)
        {
            PageUrl = pageUrl ?? throw new ArgumentNullException(nameof(pageUrl), "PageUrl is required.");
        }

        // Method to add a filter set to the Filters list
        public void AddFilter(string field, string value, string operatorString, string predicate)
        {
            Filters.Add(new FilterItem { Field = field, Value = value, Operator = operatorString, Predicate = predicate });
        }
    }

    public class FilterItem
    {
        public string Field { get; set; }
        public string Value { get; set; }
        public string Operator { get; set; }
        public string Predicate { get; set; }
    }

}
junwoolee00 commented 4 months ago

Need to refactor code, try to minimize the amount needed to put into the page and make a component maybe for it

junwoolee00 commented 4 months ago

https://www.evernote.com/shard/s728/sh/62785581-058d-35ea-9f98-9ed08494a328/

Formatted the code to remove most of it from the main page and moved it to a component

<SfGrid @ref="Grid">
    <GridEvents TValue="TItem"
                Filtering="FilteredHandler" Filtered="FilteredHandler" DataBound="DataBoundHandler" >
    </GridEvents>
</SfGrid>

<FilterPersistence @ref="filterPersistence" TItem="TItem" Grid="@Grid" pageURL="@pageURL"></FilterPersistence>

@code{
    private FilterPersistence<TItem> filterPersistence;
    public SfGrid<TItem> Grid;
    public string pageURL = "/Grid/URL/Example";

    public async Task DataBoundHandler()
    {
        await filterPersistence.SetFilter();
    }

    public void FilteredHandler(FilteredEventArgs args)
    {
        filterPersistence.SaveFilter();
    }

    public void FilterFields()
    {
        filterPersistence.SaveFilter();
    }
}