Module: MotionTable::SearchableTable

Included in:
PlainTable
Defined in:
lib/motion-table/searchable_table.rb

Instance Method Summary collapse

Instance Method Details

#makeSearchable(params = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/motion-table/searchable_table.rb', line 3

def makeSearchable(params={})
  params[:frame] ||= CGRectMake(0, 0, 320, 44)
  params[:contentController] ||= self
  params[:delegate] ||= self
  params[:searchResultsDataSource] ||= self
  params[:searchResultsDelegate] ||= self

  searchBar = UISearchBar.alloc.initWithFrame(params[:frame])
  if params[:searchBar] && params[:searchBar][:placeholder]
    searchBar.placeholder = params[:searchBar][:placeholder]
  end

  @contactsSearchDisplayController = UISearchDisplayController.alloc.initWithSearchBar(searchBar, contentsController: params[:contentController])
  @contactsSearchDisplayController.delegate = params[:delegate]
  @contactsSearchDisplayController.searchResultsDataSource = params[:searchResultsDataSource]
  @contactsSearchDisplayController.searchResultsDelegate = params[:searchResultsDelegate]
  
  self.tableView.tableHeaderView = searchBar
end

#searchDisplayController(controller, shouldReloadTableForSearchString: searchString) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/motion-table/searchable_table.rb', line 23

def searchDisplayController(controller, shouldReloadTableForSearchString:searchString)
  @mt_table_view_groups = []

  @original_data.each do |section|
    newSection = {}
    newSection[:cells] = []

    section[:cells].each do |cell|
      if cell[:title].to_s.downcase.strip.include?(searchString.downcase.strip)
        newSection[:cells] << cell
      end
    end

    if newSection.count > 0
      newSection[:title] = section[:title]
      @mt_table_view_groups << newSection
    end
  end
  true
end

#searchDisplayControllerWillBeginSearch(controller) ⇒ Object



49
50
51
# File 'lib/motion-table/searchable_table.rb', line 49

def searchDisplayControllerWillBeginSearch(controller)
  @original_data = @mt_table_view_groups.clone
end

#searchDisplayControllerWillEndSearch(controller) ⇒ Object



44
45
46
47
# File 'lib/motion-table/searchable_table.rb', line 44

def searchDisplayControllerWillEndSearch(controller)
  @mt_table_view_groups = @original_data.clone
  @original_data = nil
end