Skip to content

Commit

Permalink
feat: add column state
Browse files Browse the repository at this point in the history
  • Loading branch information
giard-alexandre committed Oct 12, 2024
1 parent 1b92bd1 commit bbb533f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using DynamicData.Aggregation;

using DynamicTreeDataGrid.Models.Columns;
using DynamicTreeDataGrid.State;

namespace DynamicTreeDataGrid;

Expand All @@ -30,6 +31,9 @@ public class DynamicFlatTreeDataGridSource<TModel, TModelKey> : NotifyingBase, I
private readonly CompositeDisposable _d = new();
private readonly ReadOnlyObservableCollection<TModel> _items;

public IObservable<int> FilteredCount { get; }
public IObservable<int> TotalCount { get; }

public DynamicFlatTreeDataGridSource(IObservable<IChangeSet<TModel, TModelKey>> changes, IScheduler mainThreadScheduler) {
_itemsFilter = _filterSource;
TotalCount = changes.Count();
Expand Down Expand Up @@ -62,9 +66,15 @@ public DynamicFlatTreeDataGridSource(IObservable<IChangeSet<TModel, TModelKey>>
// TODO: Fix CreateRows()? Does this now work since we set the comparer?
}

public IEnumerable<ColumnState> GetColumnStates() {
IList<ColumnState> states = [];
for (var i = 0; i < Columns.Count; i++) {
var column = Columns[i];
states.Add(new ColumnState(column.Name) { Visible = column.Visible, Index = i, });
}
return states;
}

public IObservable<int> FilteredCount { get; }
public IObservable<int> TotalCount { get; }

public DynamicColumnList<TModel> Columns { get; } = [];
IDynamicColumns IDynamicTreeDataGridSource.Columns => Columns;
Expand Down
3 changes: 3 additions & 0 deletions src/DynamicTreeDataGrid/IDynamicTreeDataGridSource`1.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Avalonia.Controls;

using DynamicTreeDataGrid.State;

namespace DynamicTreeDataGrid;

public interface IDynamicTreeDataGridSource<TModel> : ITreeDataGridSource<TModel>, IDynamicTreeDataGridSource {

// TODO: Add filter, state, maybe sort?
IEnumerable<ColumnState> GetColumnStates();
}
6 changes: 3 additions & 3 deletions src/DynamicTreeDataGrid/State/ColumnState.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace DynamicTreeDataGrid.State;

public class ColumnState {
public string Name { get; set; } = "";
public record ColumnState(string Name) {
public string Name { get; init; } = Name;
public int Index { get; set; }
public bool Visible { get; set; }
public bool Visible { get; set; } = true;
}

0 comments on commit bbb533f

Please sign in to comment.