Explorar el Código

Fixed DynamicGridStyle Row Mapping Issue when filters are applied

frankvandenbos hace 1 mes
padre
commit
2736d903c4

+ 18 - 1
inabox.wpf/DynamicGrid/DynamicGridStyle.cs

@@ -335,7 +335,24 @@ public class DynamicGridGridCellStyleConverter<T> : IValueConverter
             if (item is DataRowView row)
             {
                 var index = row.Row.Table.Rows.IndexOf(row.Row);
-                return _grid.Data.Rows[index];
+                return _grid.GetVisibleRow(index);
+                
+                //return _grid.Data.Rows[index];
+
+                // var map = _rowMap.FirstOrDefault(x => x.Value.Index == row.Index);
+                // if (!Equals(map,default(KeyValuePair<DataRow,CoreRow>)))
+                // {
+                //     //var datarow = table.Rows[row.Index];
+                //     for (var i = 0; i < rowdata.Count; i++)
+                //         map.Key[i] = rowdata[i] ?? DBNull.Value;
+                // }
+                // else
+                // {
+                //
+                // }
+
+
+
             }
             return null;
         }

+ 2 - 0
inabox.wpf/DynamicGrid/Grids/BaseDynamicGrid.cs

@@ -379,6 +379,8 @@ public abstract class BaseDynamicGrid : ContentControl, IDynamicGridUIComponentP
     {
     }
 
+    public CoreRow GetVisibleRow(int index) => UIComponent.GetVisibleRow(index);
+
     #region IDynamicGridUIComponentParent
 
     protected virtual IDynamicGridUIComponent CreateUIComponent()

+ 2 - 0
inabox.wpf/DynamicGrid/Grids/IDynamicGrid.cs

@@ -98,6 +98,8 @@ public interface IBaseDynamicGrid
     object? GetData(CoreRow row, DynamicColumnBase column);
 
     IDynamicGridColumnFilter? GetColumnFilter(DynamicColumnBase column);
+
+    CoreRow GetVisibleRow(int index);
 }
 
 public interface IDynamicGrid : IBaseDynamicGrid

+ 18 - 0
inabox.wpf/DynamicGrid/UIComponent/DynamicGridGridUIComponent.cs

@@ -274,6 +274,8 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
         return result.ToArray();
     }
 
+    public CoreRow GetVisibleRow(int index) => _rowMap.Values.ToArray()[index];
+    
     private void SetSelectedRows(CoreRow[] rows)
     {           
         DataGrid.SelectedItems.Clear();
@@ -1501,6 +1503,22 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
         AddRows(page, false);
     }
 
+    // public CoreRow DataRowIndexToCoreRow(int index)
+    // {
+    //     var map = _rowMap.FirstOrDefault(x => x.Value.Index == row.Index);
+    //     if (!Equals(map,default(KeyValuePair<DataRow,CoreRow>)))
+    //     {
+    //         //var datarow = table.Rows[row.Index];
+    //         for (var i = 0; i < rowdata.Count; i++)
+    //             map.Key[i] = rowdata[i] ?? DBNull.Value;
+    //     }
+    //     else
+    //     {
+    //         
+    //     }
+    //
+    // }
+    
     public void InvalidateRow(CoreRow row)
     {
         var table = DataGridItems;

+ 2 - 0
inabox.wpf/DynamicGrid/UIComponent/DynamicGridTreeUIComponent.cs

@@ -1010,6 +1010,8 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
 
         return _rowMap.GetValueOrDefault(row);
     }
+    
+    public CoreRow GetVisibleRow(int index) => _rowMap.Values.ToArray()[index];
 
     private CoreTreeNode<TKey>? GetNode(CoreRow row)
     {

+ 1 - 0
inabox.wpf/DynamicGrid/UIComponent/IDynamicGridUIComponent.cs

@@ -96,6 +96,7 @@ public interface IDynamicGridUIComponent
 
     void ScrollIntoView(CoreRow row);
     CoreRow[] GetVisibleRows();
+    CoreRow GetVisibleRow(int index);
 }
 
 public interface IDynamicGridUIComponent<T> : IDynamicGridUIComponent