|
@@ -19,38 +19,31 @@ public class DynamicGridCustomColumnsComponent<T>
|
|
{
|
|
{
|
|
private readonly DynamicGrid<T> Grid;
|
|
private readonly DynamicGrid<T> Grid;
|
|
|
|
|
|
- public Func<DynamicGridColumns> DefaultColumns { get; set; }
|
|
|
|
-
|
|
|
|
public string? Tag { get; set; }
|
|
public string? Tag { get; set; }
|
|
|
|
|
|
- public DynamicGridCustomColumnsComponent(DynamicGrid<T> grid, string? tag, Func<DynamicGridColumns> defaultColumns)
|
|
|
|
|
|
+ public DynamicGridCustomColumnsComponent(DynamicGrid<T> grid, string? tag)
|
|
{
|
|
{
|
|
Grid = grid;
|
|
Grid = grid;
|
|
Tag = tag;
|
|
Tag = tag;
|
|
- DefaultColumns = defaultColumns;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public DynamicGridColumns LoadColumns()
|
|
public DynamicGridColumns LoadColumns()
|
|
{
|
|
{
|
|
- var tag = GetTag();
|
|
|
|
-
|
|
|
|
|
|
+ var tag = GetTag(Grid.IsDirectEditMode());
|
|
|
|
+
|
|
var user = Task.Run(() => new UserConfiguration<DynamicGridColumns>(tag).Load());
|
|
var user = Task.Run(() => new UserConfiguration<DynamicGridColumns>(tag).Load());
|
|
- user.Wait();
|
|
|
|
-
|
|
|
|
var global = Task.Run(() => new GlobalConfiguration<DynamicGridColumns>(tag).Load());
|
|
var global = Task.Run(() => new GlobalConfiguration<DynamicGridColumns>(tag).Load());
|
|
- global.Wait();
|
|
|
|
- //Task.WaitAll(user, global);
|
|
|
|
|
|
+ Task.WaitAll(user, global);
|
|
|
|
+
|
|
var columns = user.Result.Any() ? user.Result : global.Result;
|
|
var columns = user.Result.Any() ? user.Result : global.Result;
|
|
|
|
|
|
- //if (!columns.Any())
|
|
|
|
- // GenerateColumns(columns); //override this to provide specific columns on startup
|
|
|
|
|
|
+ if (!columns.Any())
|
|
|
|
+ columns = Grid.GenerateColumns();
|
|
|
|
|
|
var removes = columns.Where(x => x is null || string.IsNullOrWhiteSpace(x.ColumnName) || DatabaseSchema.Property(typeof(T), x.ColumnName) == null || GetColumnEditor(x) is NullEditor)
|
|
var removes = columns.Where(x => x is null || string.IsNullOrWhiteSpace(x.ColumnName) || DatabaseSchema.Property(typeof(T), x.ColumnName) == null || GetColumnEditor(x) is NullEditor)
|
|
.ToArray();
|
|
.ToArray();
|
|
foreach (var remove in removes)
|
|
foreach (var remove in removes)
|
|
columns.Remove(remove);
|
|
columns.Remove(remove);
|
|
- if (columns.Count == 0)
|
|
|
|
- columns.AddRange(DefaultColumns());
|
|
|
|
|
|
|
|
foreach (var column in columns)
|
|
foreach (var column in columns)
|
|
try
|
|
try
|
|
@@ -77,7 +70,7 @@ public class DynamicGridCustomColumnsComponent<T>
|
|
|
|
|
|
public void SaveColumns(DynamicGridColumns columns)
|
|
public void SaveColumns(DynamicGridColumns columns)
|
|
{
|
|
{
|
|
- var tag = GetTag();
|
|
|
|
|
|
+ var tag = GetTag(Grid.IsDirectEditMode());
|
|
new UserConfiguration<DynamicGridColumns>(tag).Save(columns);
|
|
new UserConfiguration<DynamicGridColumns>(tag).Save(columns);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -96,13 +89,11 @@ public class DynamicGridCustomColumnsComponent<T>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private string GetTag()
|
|
|
|
|
|
+ private string GetTag(bool directEdit)
|
|
{
|
|
{
|
|
var tag = Tag ?? typeof(T).Name;
|
|
var tag = Tag ?? typeof(T).Name;
|
|
- if (Grid.IsDirectEditMode())
|
|
|
|
- {
|
|
|
|
|
|
+ if (directEdit)
|
|
tag += ":DirectEdit";
|
|
tag += ":DirectEdit";
|
|
- }
|
|
|
|
return tag;
|
|
return tag;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -133,7 +124,7 @@ public class DynamicGridCustomColumnsComponent<T>
|
|
|
|
|
|
private void UpdateDefaultColumnsClick(object sender, RoutedEventArgs e)
|
|
private void UpdateDefaultColumnsClick(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
- var tag = GetTag();
|
|
|
|
|
|
+ var tag = GetTag(Grid.IsDirectEditMode());
|
|
new GlobalConfiguration<DynamicGridColumns>(tag).Save(Grid.VisibleColumns);
|
|
new GlobalConfiguration<DynamicGridColumns>(tag).Save(Grid.VisibleColumns);
|
|
new UserConfiguration<DynamicGridColumns>(tag).Delete();
|
|
new UserConfiguration<DynamicGridColumns>(tag).Delete();
|
|
Grid.Refresh(true, true);
|
|
Grid.Refresh(true, true);
|