ContactGrid.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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,
  31. Action<CoreTable, Exception> action)
  32. {
  33. if (!bShowAll)
  34. criteria.Add(new Filter<Contact>(x => x.Favourite).IsEqualTo(true));
  35. base.Reload(criteria, columns, ref sort, action);
  36. }
  37. }
  38. }