Ver Fonte

Fixed paging problems with export

Kenric Nugteren há 8 meses atrás
pai
commit
b9867eef47

+ 0 - 2
inabox.wpf/DynamicGrid/DynamicDataGrid.cs

@@ -169,8 +169,6 @@ public class DynamicDataGrid<TEntity> : DynamicGrid<TEntity>, IDynamicDataGrid w
     
     public event OnReloadEventHandler? OnReload;
 
-    protected bool IsPaging { get; private set; } = false;
-
     protected override string FormatRecordCount(int count)
     {
         return IsPaging 

+ 46 - 20
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -1008,6 +1008,8 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
 
     #region Refresh / Reload
 
+    protected bool IsPaging { get; set; } = false;
+
     protected abstract void Reload(
         Filters<T> criteria, Columns<T> columns, ref SortOrder<T>? sort,
         CancellationToken token, Action<CoreTable?, Exception?> action);
@@ -2163,36 +2165,60 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
             reloadColumns.Add(column);
         }
 
-        var sort = LookupFactory.DefineSort<T>();
-        Reload(filters, reloadColumns, ref sort, CancellationToken.None, (data, err) => Dispatcher.Invoke(() =>
+        CoreTable? data = null;
+
+        void LoadExport()
         {
-            if (data is not null)
-            {
-                var newData = new CoreTable();
-                newData.LoadColumns(columns);
+            var newData = new CoreTable();
+            newData.LoadColumns(columns);
 
-                FilterRows(data.Rows, newData, filter: row =>
+            FilterRows(data.Rows, newData, filter: row =>
+            {
+                foreach(var (_, predicate) in predicates)
                 {
-                    foreach(var (_, predicate) in predicates)
+                    if (!predicate(row))
                     {
-                        if (!predicate(row))
-                        {
-                            return false;
-                        }
+                        return false;
                     }
-                    return true;
-                });
+                }
+                return true;
+            });
 
-                var list = new List<Tuple<Type?, CoreTable>>() { new(typeof(T), newData) };
-                list.AddRange(LoadExportTables(filters, otherColumns));
-                DoExportTables(list);
+            var list = new List<Tuple<Type?, CoreTable>>() { new(typeof(T), newData) };
+            list.AddRange(LoadExportTables(filters, otherColumns));
+            DoExportTables(list);
+        }
+
+        var sort = LookupFactory.DefineSort<T>();
+        Reload(filters, reloadColumns, ref sort, CancellationToken.None, (table, err) =>
+        {
+            if (table is not null)
+            {
+                if (table.Offset == 0 || data is null)
+                {
+                    data = table;
+                    if (!IsPaging)
+                    {
+                        Dispatcher.Invoke(LoadExport);
+                    }
+                }
+                else
+                {
+                    data.AddPage(table);
+                    if (!IsPaging)
+                    {
+                        Dispatcher.Invoke(LoadExport);
+                    }
+                }
             }
             else if (err is not null)
             {
-                Logger.Send(LogType.Error, "", $"Error in export: {CoreUtils.FormatException(err)}");
-                MessageBox.Show(err.Message);
+                Dispatcher.Invoke(() =>
+                {
+                    MessageWindow.ShowError("Error in export.", err);
+                });
             }
-        }));
+        });
     }
 
     private void Export_Click(object sender, RoutedEventArgs e)

+ 0 - 1
inabox.wpf/DynamicGrid/DynamicOneToManyGrid.cs

@@ -217,7 +217,6 @@ public class DynamicOneToManyGrid<TOne, TMany> : DynamicGrid<TMany>,
         Client.Delete(item, typeof(TMany).Name + " Deleted by User");
     }
 
-
     protected override CoreTable LoadImportKeys(string[] fields)
     {
         var result = base.LoadImportKeys(fields);