DynamicItemsListGrid.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using InABox.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace InABox.DynamicGrid
  8. {
  9. public class DynamicItemsListGrid<T> : DynamicGrid<T>
  10. where T : BaseObject, new()
  11. {
  12. public List<T> Items { get; set; }
  13. public DynamicItemsListGrid() : this(new()) { }
  14. public DynamicItemsListGrid(List<T> items) : base()
  15. {
  16. Items = items;
  17. }
  18. protected override void DeleteItems(params CoreRow[] rows)
  19. {
  20. foreach (var row in rows.OrderByDescending(x => x.Index))
  21. {
  22. Items.RemoveAt(_recordmap[row].Index);
  23. }
  24. }
  25. protected override T LoadItem(CoreRow row)
  26. {
  27. return Items[_recordmap[row].Index];
  28. }
  29. protected override void Reload(Filters<T> criteria, Columns<T> columns, ref SortOrder<T>? sort, Action<CoreTable?, Exception?> action)
  30. {
  31. var result = new CoreTable();
  32. result.LoadColumns(typeof(T));
  33. result.LoadRows(Items);
  34. action.Invoke(result, null);
  35. }
  36. public override void SaveItem(T item)
  37. {
  38. if (!Items.Contains(item))
  39. {
  40. Items.Add(item);
  41. }
  42. }
  43. }
  44. }