Skip to content

Commit

Permalink
feat: add columns
Browse files Browse the repository at this point in the history
  • Loading branch information
giard-alexandre committed Jun 4, 2024
1 parent bba2bdf commit 46d6b34
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/DynamicTreeDataGrid/Columns/DynamicCheckBoxColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Linq.Expressions;

using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Experimental.Data;

namespace DynamicTreeDataGrid.Columns;

public class DynamicCheckBoxColumn<TModel> : CheckBoxColumn<TModel>
where TModel : class {
/// <summary>
/// Initializes a new instance of the <see cref="CheckBoxColumn{TModel}"/> class.
/// </summary>
/// <param name="header">The column header.</param>
/// <param name="getter">
/// An expression which given a row model, returns a boolean cell value for the column.
/// </param>
/// <param name="setter">
/// A method which given a row model and a cell value, writes the cell value to the
/// row model. If not supplied then the column will be read-only.
/// </param>
/// <param name="width">
/// The column width. If null defaults to <see cref="GridLength.Auto"/>.
/// </param>
/// <param name="options">Additional column options.</param>
public DynamicCheckBoxColumn(object? header,
Expression<Func<TModel, bool>> getter,
Action<TModel, bool>? setter = null,
GridLength? width = null,
CheckBoxColumnOptions<TModel>? options = null) : base(header, getter, setter, width,
options) { }

/// <summary>
/// Initializes a new instance of the <see cref="CheckBoxColumn{TModel}"/> class that
/// displays a three-state check box.
/// </summary>
/// <param name="header">The column header.</param>
/// <param name="getter">
/// An expression which given a row model, returns a nullable boolean cell value for the
/// column.
/// </param>
/// <param name="setter">
/// A method which given a row model and a cell value, writes the cell value to the
/// row model. If not supplied then the column will be read-only.
/// </param>
/// <param name="width">
/// The column width. If null defaults to <see cref="GridLength.Auto"/>.
/// </param>
/// <param name="options">Additional column options.</param>
public DynamicCheckBoxColumn(object? header,
Expression<Func<TModel, bool?>> getter,
Action<TModel, bool?>? setter = null,
GridLength? width = null,
CheckBoxColumnOptions<TModel>? options = null) : base(header, getter, setter, width,
options ?? new CheckBoxColumnOptions<TModel>()) { }
}
21 changes: 21 additions & 0 deletions src/DynamicTreeDataGrid/Columns/DynamicTemplateColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Templates;

namespace DynamicTreeDataGrid.Columns;

public class DynamicTemplateColumn<TModel> : TemplateColumn<TModel> {
public DynamicTemplateColumn(object? header,
IDataTemplate cellTemplate,
IDataTemplate? cellEditingTemplate = null,
GridLength? width = null,
TemplateColumnOptions<TModel>? options = null) : base(header, cellTemplate,
cellEditingTemplate, width, options) { }

public DynamicTemplateColumn(object? header,
object cellTemplateResourceKey,
object? cellEditingTemplateResourceKey = null,
GridLength? width = null,
TemplateColumnOptions<TModel>? options = null) : base(header, cellTemplateResourceKey,
cellEditingTemplateResourceKey, width, options) { }
}
47 changes: 47 additions & 0 deletions src/DynamicTreeDataGrid/Columns/DynamicTextColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Linq.Expressions;

using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;

namespace DynamicTreeDataGrid.Columns;

public class DynamicTextColumn<TModel, TValue> : TextColumn<TModel, TValue>
where TModel : class {
/// <summary>
/// Initializes a new instance of the <see cref="TextColumn{TModel, TValue}"/> class.
/// </summary>
/// <param name="header">The column header.</param>
/// <param name="getter">
/// An expression which given a row model, returns a cell value for the column.
/// </param>
/// <param name="width">
/// The column width. If null defaults to <see cref="GridLength.Auto"/>.
/// </param>
/// <param name="options">Additional column options.</param>
public DynamicTextColumn(object? header,
Expression<Func<TModel, TValue?>> getter,
GridLength? width = null,
TextColumnOptions<TModel>? options = null) : base(header, getter, width, options) { }

/// <summary>
/// Initializes a new instance of the <see cref="TextColumn{TModel, TValue}"/> class.
/// </summary>
/// <param name="header">The column header.</param>
/// <param name="getter">
/// An expression which given a row model, returns a cell value for the column.
/// </param>
/// <param name="setter">
/// A method which given a row model and a cell value, writes the cell value to the
/// row model.
/// </param>
/// <param name="width">
/// The column width. If null defaults to <see cref="GridLength.Auto"/>.
/// </param>
/// <param name="options">Additional column options.</param>
public DynamicTextColumn(object? header,
Expression<Func<TModel, TValue?>> getter,
Action<TModel, TValue?> setter,
GridLength? width = null,
TextColumnOptions<TModel>? options = null) : base(header, getter, setter, width,
options ?? new()) { }
}

0 comments on commit 46d6b34

Please sign in to comment.