ContactGrid.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Windows.Controls;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using InABox.DynamicGrid;
  6. namespace PRSDesktop
  7. {
  8. public class ContactGrid : DynamicDataGrid<Contact>
  9. {
  10. private bool bShowAll;
  11. public ContactGrid()
  12. {
  13. AddButton("Show All", null, ToggleFavourites);
  14. }
  15. protected override void DoReconfigure(FluentList<DynamicGridOption> options)
  16. {
  17. base.DoReconfigure(options);
  18. options.AddRange(
  19. DynamicGridOption.RecordCount,
  20. DynamicGridOption.FilterRows,
  21. DynamicGridOption.SelectColumns
  22. );
  23. }
  24. private bool ToggleFavourites(Button sender, CoreRow[] rows)
  25. {
  26. bShowAll = !bShowAll;
  27. UpdateButton(sender, null, bShowAll ? "Favourites" : "Show All");
  28. return true;
  29. }
  30. protected override void Reload(Filters<Contact> criteria, Columns<Contact> columns, ref SortOrder<Contact>? sort, Action<CoreTable?, Exception?> action)
  31. {
  32. if (!bShowAll)
  33. criteria.Add(new Filter<Contact>(x => x.Favourite).IsEqualTo(true));
  34. base.Reload(criteria, columns, ref sort, action);
  35. }
  36. }
  37. }