|
@@ -201,11 +201,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
DataGrid.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Visible);
|
|
|
|
|
|
DataGrid.FilterChanging += DataGrid_FilterChanging;
|
|
|
-
|
|
|
DataGrid.FilterChanged += DataGrid_FilterChanged;
|
|
|
|
|
|
- DataGrid.FilterItemsPopulating += DataGrid_FilterItemsPopulating;
|
|
|
-
|
|
|
var fltstyle = new Style(typeof(GridFilterControl));
|
|
|
fltstyle.Setters.Add(new Setter(GridFilterControl.FilterModeProperty, FilterMode.Both));
|
|
|
fltstyle.Setters.Add(new Setter(GridFilterControl.SortOptionVisibilityProperty, Visibility.Collapsed));
|
|
@@ -260,10 +257,9 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
var result = new List<CoreRow>();
|
|
|
foreach (var item in DataGrid.SelectedItems)
|
|
|
{
|
|
|
- if (item is DataRowView datarow)
|
|
|
+ if (item is DataRowView datarow && GetRow(datarow.Row) is CoreRow row)
|
|
|
{
|
|
|
- var row = datarow.Row.Table.Rows.IndexOf(datarow.Row);
|
|
|
- result.Add(Parent.Data.Rows[row]);
|
|
|
+ result.Add(row);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -352,8 +348,10 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
var rows = DataGrid.View.Records.Select(x => (x.Data as DataRowView)!).ToList();
|
|
|
foreach (var row in rows)
|
|
|
{
|
|
|
- var iRow = table.Rows.IndexOf(row.Row);
|
|
|
- result.Add(Parent.Data.Rows[iRow]);
|
|
|
+ if(GetRow(row.Row) is CoreRow coreRow)
|
|
|
+ {
|
|
|
+ result.Add(coreRow);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return result.ToArray();
|
|
@@ -458,10 +456,12 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
if (row is not DataRowView dataRowView || DataGridItems is not DataTable table)
|
|
|
return null;
|
|
|
|
|
|
- var rowIdx = table.Rows.IndexOf(dataRowView.Row);
|
|
|
- if (rowIdx < 0)
|
|
|
- return null;
|
|
|
- return Parent.Data.Rows[rowIdx];
|
|
|
+ return GetRow(dataRowView.Row);
|
|
|
+ }
|
|
|
+
|
|
|
+ private CoreRow? GetRow(DataRow row)
|
|
|
+ {
|
|
|
+ return _rowMap.GetValueOrDefault(row);
|
|
|
}
|
|
|
|
|
|
private void DataGrid_CellDoubleTapped(object? sender, GridCellDoubleTappedEventArgs e)
|
|
@@ -582,43 +582,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
UpdateRecordCount();
|
|
|
}
|
|
|
|
|
|
- private void DataGrid_FilterItemsPopulating(object? sender, GridFilterItemsPopulatingEventArgs e)
|
|
|
- {
|
|
|
- var colIdx = DataGrid.Columns.IndexOf(e.Column);
|
|
|
- var column = GetColumn(colIdx);
|
|
|
- if(column is not null)
|
|
|
- {
|
|
|
- var filterItems = Parent.GetColumnFilterItems(column);
|
|
|
- if(filterItems is not null)
|
|
|
- {
|
|
|
- e.ItemsSource = filterItems.Select(x =>
|
|
|
- {
|
|
|
- var element = new FilterElement
|
|
|
- {
|
|
|
- DisplayText = x.Item2,
|
|
|
- ActualValue = x.Item1,
|
|
|
- };
|
|
|
- if(column is DynamicActionColumn dac)
|
|
|
- {
|
|
|
- element.IsSelected = (dac.SelectedFilters is null || dac.SelectedFilters.Contains(x.Item1))
|
|
|
- && (dac.ExcludeFilters is null || !dac.ExcludeFilters.Contains(x.Item1));
|
|
|
- }
|
|
|
- return element;
|
|
|
- });
|
|
|
- }
|
|
|
- else if (column is DynamicActionColumn dac && dac.Filters is not null)
|
|
|
- {
|
|
|
- e.ItemsSource = dac.Filters.Select(x => new FilterElement
|
|
|
- {
|
|
|
- DisplayText = x,
|
|
|
- ActualValue = x,
|
|
|
- IsSelected = (dac.SelectedFilters is null || dac.SelectedFilters.Contains(x))
|
|
|
- && (dac.ExcludeFilters is null || !dac.ExcludeFilters.Contains(x))
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void UpdateRecordCount()
|
|
|
{
|
|
|
var count = DataGrid.View != null ? DataGrid.View.Records.Count : Parent.Data.Rows.Count;
|
|
@@ -753,6 +716,13 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
headStyle.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Left));
|
|
|
headStyle.Setters.Add(new Setter(Control.TemplateProperty,
|
|
|
Application.Current.Resources["VerticalColumnHeader"] as ControlTemplate));
|
|
|
+ // headStyle.AddSetter(GridHeaderCellControl.ContentTemplateProperty,
|
|
|
+ // TemplateGenerator.CreateDataTemplate(() =>
|
|
|
+ // {
|
|
|
+ // var content = new ContentPresenter();
|
|
|
+ // content.SetBinding(ContentPresenter.ContentProperty, new Binding());
|
|
|
+ // return content;
|
|
|
+ // }));
|
|
|
}
|
|
|
}
|
|
|
return headStyle;
|
|
@@ -994,6 +964,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
{
|
|
|
if (Parent.GetColumnFilter(column) is not IDynamicGridColumnFilter filter) return;
|
|
|
|
|
|
+ var vertical = column is DynamicActionColumn ac && ac.VerticalHeader && !ac.HeaderText.IsNullOrWhiteSpace();
|
|
|
+
|
|
|
var horizontalAlignment = gridColumn.HorizontalHeaderContentAlignment;
|
|
|
gridColumn.HorizontalHeaderContentAlignment = HorizontalAlignment.Stretch;
|
|
|
gridColumn.HeaderTemplate = TemplateGenerator.CreateDataTemplate(() =>
|
|
@@ -1011,6 +983,12 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
var button = new DynamicGridColumnFilterUIButton(filter);
|
|
|
grid.AddChild(button, 0, 1);
|
|
|
|
|
|
+ if(vertical)
|
|
|
+ {
|
|
|
+ button.LayoutTransform = new RotateTransform(90);
|
|
|
+ content.HorizontalAlignment = HorizontalAlignment.Stretch;
|
|
|
+ }
|
|
|
+
|
|
|
return grid;
|
|
|
});
|
|
|
|
|
@@ -1117,9 +1095,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
{
|
|
|
Sum = Aggregate(rows.Select(x =>
|
|
|
{
|
|
|
- var row = x.Row.Table.Rows.IndexOf(x.Row);
|
|
|
- return Grid.Parent.Data.Rows[row];
|
|
|
- }));
|
|
|
+ return Grid.GetRow(x.Row);
|
|
|
+ }).NotNull());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1216,13 +1193,9 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
content.SetBinding(ContentControl.ContentProperty,
|
|
|
WPFUtils.CreateMultiBinding(new MultiFuncConverter(x =>
|
|
|
{
|
|
|
- if(x[0] is DataRowView view && DataGridItems is DataTable table)
|
|
|
+ if(x[0] is DataRowView view && DataGridItems is DataTable table && GetRow(view.Row) is CoreRow row)
|
|
|
{
|
|
|
- var rowIdx = table.Rows.IndexOf(view.Row);
|
|
|
- if (rowIdx >= 0)
|
|
|
- {
|
|
|
- return tmplCol.Template(Parent.Data.Rows[rowIdx]);
|
|
|
- }
|
|
|
+ return tmplCol.Template(row);
|
|
|
}
|
|
|
return null;
|
|
|
}))
|
|
@@ -1421,6 +1394,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
#region Data
|
|
|
|
|
|
private bool _invalidating = false;
|
|
|
+ private Dictionary<DataRow, CoreRow> _rowMap = new();
|
|
|
|
|
|
public void BeforeRefresh()
|
|
|
{
|
|
@@ -1431,6 +1405,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
public void RefreshData(CoreTable data)
|
|
|
{
|
|
|
var result = new DataTable();
|
|
|
+ _rowMap.Clear();
|
|
|
|
|
|
var defaults = new List<object?>();
|
|
|
foreach (var column in data.Columns)
|
|
@@ -1456,6 +1431,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
var newrow = result.NewRow();
|
|
|
CoreRowToDataRow(newrow, row, defaults);
|
|
|
result.Rows.Add(newrow);
|
|
|
+ _rowMap[newrow] = row;
|
|
|
}
|
|
|
|
|
|
result.ColumnChanged += Result_ColumnChanged;
|
|
@@ -1482,6 +1458,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
if (clearRows)
|
|
|
{
|
|
|
table.Rows.Clear();
|
|
|
+ _rowMap.Clear();
|
|
|
}
|
|
|
|
|
|
var defaults = new List<object?>();
|
|
@@ -1496,6 +1473,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
var newRow = table.NewRow();
|
|
|
CoreRowToDataRow(newRow, row, defaults);
|
|
|
table.Rows.Add(newRow);
|
|
|
+ _rowMap[newRow] = row;
|
|
|
}
|
|
|
|
|
|
UpdateRecordCount();
|
|
@@ -1730,12 +1708,10 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
if (_invalidating) return;
|
|
|
if (sender is not DataTable table) return;
|
|
|
|
|
|
- var rowIdx = table.Rows.IndexOf(e.Row);
|
|
|
- if (rowIdx < 0)
|
|
|
+ var row = GetRow(e.Row);
|
|
|
+ if (row is null)
|
|
|
return;
|
|
|
|
|
|
- var row = Parent.Data.Rows[rowIdx];
|
|
|
-
|
|
|
var colIdx = table.Columns.IndexOf(e.Column);
|
|
|
if (colIdx < 0 || colIdx >= Parent.Data.Columns.Count)
|
|
|
return;
|
|
@@ -1925,8 +1901,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
{
|
|
|
if (x is DataRowView dataRow)
|
|
|
{
|
|
|
- var row = dataRow.Row.Table.Rows.IndexOf(dataRow.Row);
|
|
|
- return Parent.Data.Rows[row];
|
|
|
+ return GetRow(dataRow.Row);
|
|
|
}
|
|
|
else
|
|
|
{
|