forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataSourceGettingStarted.cs
114 lines (98 loc) · 3.8 KB
/
DataSourceGettingStarted.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#region Copyright Syncfusion Inc. 2001-2022.
// Copyright Syncfusion Inc. 2001-2022. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using CoreGraphics;
using Syncfusion.DataSource;
using System;
using System.Collections.Generic;
using System.Text;
using UIKit;
namespace SampleBrowser
{
public class DataSourceGettingStarted : SampleView
{
#region Field
UITableView tableView;
DataSource sfDataSource;
UISearchBar searchbar;
DataSourceOptionsView option;
DataSourceGettingStartedViewModel viewModel;
#endregion
#region Constructor
public DataSourceGettingStarted()
{
tableView = new UITableView();
tableView.RowHeight = 100;
tableView.SeparatorColor = UIColor.Clear;
tableView.EstimatedRowHeight = 100;
viewModel = new DataSourceGettingStartedViewModel();
viewModel.SetRowstoGenerate(100);
sfDataSource = new DataSource();
sfDataSource.Source = viewModel.BookInfo;
sfDataSource.DisplayItems.CollectionChanged += DisplayItems_CollectionChanged;
sfDataSource.LiveDataUpdateMode = Syncfusion.DataSource.LiveDataUpdateMode.AllowDataShaping;
sfDataSource.SortDescriptors.Add(new SortDescriptor()
{
Direction = Syncfusion.DataSource.ListSortDirection.Descending,
PropertyName = "BookID",
});
tableView.Source = new TableViewSource(sfDataSource);
searchbar = new UISearchBar ();
searchbar.OnEditingStarted += HandleOnEditingStarted;
searchbar.TextChanged += HandleTextChanged;
searchbar.CancelButtonClicked += HandleCancelButtonClicked;
searchbar.EnablesReturnKeyAutomatically = false;
searchbar.Placeholder = "Search in All Columns";
viewModel.filtertextchanged = OnFilterChanged;
option = new DataSourceOptionsView (viewModel,searchbar,this);
this.OptionView = option;
this.AddSubview(searchbar);
this.AddSubview(this.tableView);
}
private void DisplayItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
tableView.ReloadData();
}
#endregion
internal void OnFilterChanged()
{
if (this.sfDataSource != null)
{
sfDataSource.Filter = viewModel.FilerRecords;
sfDataSource.RefreshFilter();
}
}
void HandleCancelButtonClicked(object sender, EventArgs e)
{
searchbar.ResignFirstResponder();
searchbar.SetShowsCancelButton(false, true);
}
void HandleTextChanged(object sender, UISearchBarTextChangedEventArgs e)
{
viewModel.FilterText = e.SearchText;
}
void HandleOnEditingStarted(object sender, EventArgs e)
{
searchbar.SetShowsCancelButton(true, true);
}
public override void LayoutSubviews()
{
searchbar.Frame = (new CGRect(0, 0, this.Frame.Width, 40));
if (UIDevice.CurrentDevice.CheckSystemVersion(7, 1))
{
searchbar.SizeToFit();
this.tableView.Frame = new CGRect(0, searchbar.Bounds.Height, this.Frame.Width, this.Frame.Height - 44);
}
else
{
searchbar.SizeToFit();
this.tableView.Frame = new CGRect(0, searchbar.Bounds.Height, this.Frame.Width, this.Frame.Height - 44);
}
base.LayoutSubviews();
}
}
}