diff --git a/samples/SampleApp/ViewModels/MainWindowViewModel.cs b/samples/SampleApp/ViewModels/MainWindowViewModel.cs index cbe4916..ddad899 100644 --- a/samples/SampleApp/ViewModels/MainWindowViewModel.cs +++ b/samples/SampleApp/ViewModels/MainWindowViewModel.cs @@ -17,68 +17,68 @@ namespace SampleApp.ViewModels; public class MainWindowViewModel : ReactiveObject { - private string? _filterText; - - public MainWindowViewModel() { - //Set the randomizer seed to generate repeatable data sets. - Randomizer.Seed = new Random(8675309); - var data = new ObservableCollection(new Faker() - .RuleFor(person => person.Id, faker => faker.IndexFaker) - .RuleFor(person => person.Name, faker => faker.Name.FullName()) - .RuleFor(person => person.DateOfBirth, faker => faker.Date.Past(80)) - .RuleFor(person => person.Height, faker => faker.Random.Double()) - .RuleFor(person => person.Gender, faker => faker.Person.Gender) - .RuleFor(person => person.Money, faker => faker.Finance.Amount(-1000M, 1000M, 5)) - .RuleFor(person => person.IsChecked, faker => faker.Random.Bool()) - .Generate(300)).ToObservableChangeSet(person => person.Id); - - - var searchFilter = this.WhenValueChanged(t => t.FilterText) - .Throttle(TimeSpan.FromMilliseconds(500)) - .Select(BuildSearchFilter); - - var filteredData = data.Filter(searchFilter); - - DataSource = new DynamicFlatTreeDataGridSource(filteredData, RxApp.MainThreadScheduler) { - Columns = { - new DynamicTextColumn("Id", "Id", person => person.Id), - new DynamicTextColumn("Name", "Name", person => person.Name), - new DynamicTextColumn("Date-of-Birth", "DoB", person => person.DateOfBirth), - new DynamicTemplateColumn("Height", "Height", "HeightCell"), - new DynamicTextColumn("Height-Raw", "Raw Height", person => person.Height), - new DynamicTextColumn("Gender", "Gender", person => person.Gender), // To Template - new DynamicTextColumn("Money", "Money", person => person.Money), - new DynamicCheckBoxColumn("Checked", "Checked", person => person.IsChecked), - }, - }; - } - - public DynamicFlatTreeDataGridSource DataSource { get; set; } - - public string? FilterText { - get => _filterText; - set => this.RaiseAndSetIfChanged(ref _filterText, value); - } - - public void PrintColumnStates() { - Console.WriteLine(JsonSerializer.Serialize(DataSource.Columns.GetColumnStates(), - new JsonSerializerOptions(JsonSerializerOptions.Default) { WriteIndented = true })); - } - - private static Func BuildSearchFilter(string? text) { - if (string.IsNullOrEmpty(text)) - return _ => true; - - return t => t.Name.Contains(text, StringComparison.OrdinalIgnoreCase); - } + private readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerOptions.Default) { WriteIndented = true }; + private string? _filterText; + + public MainWindowViewModel() { + //Set the randomizer seed to generate repeatable data sets. + Randomizer.Seed = new Random(8675309); + var data = new ObservableCollection(new Faker() + .RuleFor(person => person.Id, faker => faker.IndexFaker) + .RuleFor(person => person.Name, faker => faker.Name.FullName()) + .RuleFor(person => person.DateOfBirth, faker => faker.Date.Past(80)) + .RuleFor(person => person.Height, faker => faker.Random.Double()) + .RuleFor(person => person.Gender, faker => faker.Person.Gender) + .RuleFor(person => person.Money, faker => faker.Finance.Amount(-1000M, 1000M, 5)) + .RuleFor(person => person.IsChecked, faker => faker.Random.Bool()) + .Generate(300)).ToObservableChangeSet(person => person.Id); + + + var searchFilter = this.WhenValueChanged(t => t.FilterText) + .Throttle(TimeSpan.FromMilliseconds(500)) + .Select(BuildSearchFilter); + + var filteredData = data.Filter(searchFilter); + + DataSource = new DynamicFlatTreeDataGridSource(filteredData, RxApp.MainThreadScheduler) { + Columns = { + new DynamicTextColumn("Id", "Id", person => person.Id), + new DynamicTextColumn("Name", "Name", person => person.Name), + new DynamicTextColumn("Date-of-Birth", "DoB", person => person.DateOfBirth), + new DynamicTemplateColumn("Height", "Height", "HeightCell"), + new DynamicTextColumn("Height-Raw", "Raw Height", person => person.Height), + new DynamicTextColumn("Gender", "Gender", person => person.Gender), // To Template + new DynamicTextColumn("Money", "Money", person => person.Money), + new DynamicCheckBoxColumn("Checked", "Checked", person => person.IsChecked), + }, + }; + } + + public DynamicFlatTreeDataGridSource DataSource { get; set; } + + public string? FilterText { + get => _filterText; + set => this.RaiseAndSetIfChanged(ref _filterText, value); + } + + public void PrintColumnStates() { + Console.WriteLine(JsonSerializer.Serialize(DataSource.GetGridState(), _jsonOptions)); + } + + private static Func BuildSearchFilter(string? text) { + if (string.IsNullOrEmpty(text)) + return _ => true; + + return t => t.Name.Contains(text, StringComparison.OrdinalIgnoreCase); + } } public record Person { - public int Id { get; set; } - public string Name { get; set; } = ""; - public DateTime DateOfBirth { get; set; } - public double Height { get; set; } - public Name.Gender Gender { get; set; } - public decimal Money { get; set; } - public bool IsChecked { get; set; } + public int Id { get; set; } + public string Name { get; set; } = ""; + public DateTime DateOfBirth { get; set; } + public double Height { get; set; } + public Name.Gender Gender { get; set; } + public decimal Money { get; set; } + public bool IsChecked { get; set; } } diff --git a/src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs b/src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs index c833e2d..75fa9b4 100644 --- a/src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs +++ b/src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs @@ -72,7 +72,7 @@ public DynamicFlatTreeDataGridSource(IObservable> IDynamicColumns IDynamicTreeDataGridSource.Columns => Columns; IColumns ITreeDataGridSource.Columns => Columns.DisplayedColumns; - public GridState GetCurrentGridState() => new() { ColumnStates = Columns.GetColumnStates() }; + public GridState GetGridState() => new() { ColumnStates = Columns.GetColumnStates() }; public bool ApplyGridState(GridState state) => Columns.ApplyColumnStates(state.ColumnStates); diff --git a/src/DynamicTreeDataGrid/DynamicHierarchicalTreeDataGridSource.cs b/src/DynamicTreeDataGrid/DynamicHierarchicalTreeDataGridSource.cs index 3638157..ae09224 100644 --- a/src/DynamicTreeDataGrid/DynamicHierarchicalTreeDataGridSource.cs +++ b/src/DynamicTreeDataGrid/DynamicHierarchicalTreeDataGridSource.cs @@ -53,7 +53,7 @@ public DynamicHierarchicalTreeDataGridSource(IObservable Columns; IColumns ITreeDataGridSource.Columns => Columns.DisplayedColumns; - public GridState GetCurrentGridState() => throw new NotImplementedException(); + public GridState GetGridState() => throw new NotImplementedException(); public bool ApplyGridState(GridState state) => throw new NotImplementedException(); #region Override base sorted logic with IChangeSet sorting diff --git a/src/DynamicTreeDataGrid/Models/IDynamicTreeDataGridSource.cs b/src/DynamicTreeDataGrid/Models/IDynamicTreeDataGridSource.cs index 03ebaa0..000864b 100644 --- a/src/DynamicTreeDataGrid/Models/IDynamicTreeDataGridSource.cs +++ b/src/DynamicTreeDataGrid/Models/IDynamicTreeDataGridSource.cs @@ -18,7 +18,7 @@ public interface IDynamicTreeDataGridSource : ITreeDataGridSource { /// public IObservable TotalCount { get; } - GridState GetCurrentGridState(); + GridState GetGridState(); bool ApplyGridState(GridState state); // TODO: Add filter, state, maybe sort?