You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
// Copyright (c) MudBlazor 2021
|
|
// MudBlazor licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
namespace Connected.Components;
|
|
|
|
public class CellContext<T>
|
|
{
|
|
internal HashSet<T> selection;
|
|
internal HashSet<T> openHierarchies;
|
|
public T Item { get; set; }
|
|
public CellActions Actions { get; internal set; }
|
|
public bool IsSelected
|
|
{
|
|
get
|
|
{
|
|
if (selection != null)
|
|
{
|
|
return selection.Contains(Item);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public CellContext(DataGrid<T> dataGrid, T item)
|
|
{
|
|
selection = dataGrid.Selection;
|
|
openHierarchies = dataGrid._openHierarchies;
|
|
Item = item;
|
|
Actions = new CellContext<T>.CellActions
|
|
{
|
|
SetSelectedItem = async (x) => await dataGrid.SetSelectedItemAsync(x, item),
|
|
StartEditingItem = async () => await dataGrid.SetEditingItemAsync(item),
|
|
CancelEditingItem = async () => await dataGrid.CancelEditingItemAsync(),
|
|
ToggleHierarchyVisibilityForItem = async () => await dataGrid.ToggleHierarchyVisibilityAsync(item),
|
|
};
|
|
}
|
|
|
|
public class CellActions
|
|
{
|
|
public Action<bool> SetSelectedItem { get; internal set; }
|
|
public Action StartEditingItem { get; internal set; }
|
|
public Action CancelEditingItem { get; internal set; }
|
|
public Action ToggleHierarchyVisibilityForItem { get; internal set; }
|
|
}
|
|
}
|