mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-05-26 04:06:52 +08:00
Expose search_string to the table_view
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
module ProMotion
|
||||
class TableData
|
||||
attr_accessor :data, :filtered_data, :filtered, :table_view
|
||||
attr_accessor :data, :filtered_data, :search_string, :filtered, :table_view
|
||||
|
||||
def initialize(data, table_view)
|
||||
self.data = data
|
||||
@@ -45,14 +45,14 @@ module ProMotion
|
||||
self.filtered_data = []
|
||||
self.filtered = true
|
||||
|
||||
search_string = search_string.downcase.strip
|
||||
self.search_string = search_string.downcase.strip
|
||||
|
||||
self.data.compact.each do |section|
|
||||
new_section = {}
|
||||
new_section[:cells] = []
|
||||
|
||||
new_section[:cells] = section[:cells].map do |cell|
|
||||
cell[:searchable] != false && "#{cell[:title]}\n#{cell[:search_text]}".downcase.strip.include?(search_string) ? cell : nil
|
||||
cell[:searchable] != false && "#{cell[:title]}\n#{cell[:search_text]}".downcase.strip.include?(self.search_string) ? cell : nil
|
||||
end.compact
|
||||
|
||||
if new_section[:cells] && new_section[:cells].length > 0
|
||||
@@ -67,6 +67,7 @@ module ProMotion
|
||||
def stop_searching
|
||||
self.filtered_data = []
|
||||
self.filtered = false
|
||||
self.search_string = false
|
||||
end
|
||||
|
||||
def set_data_cell_defaults(data_cell)
|
||||
|
||||
@@ -59,6 +59,10 @@ module ProMotion
|
||||
@promotion_table_data.filtered
|
||||
end
|
||||
|
||||
def search_string
|
||||
@promotion_table_data.search_string
|
||||
end
|
||||
|
||||
def update_table_view_data(data)
|
||||
create_table_view_from_data(data) unless @promotion_table_data
|
||||
@promotion_table_data.data = data
|
||||
@@ -242,9 +246,9 @@ module ProMotion
|
||||
PM.logger.warn "ProMotion expects you to use 'delete_cell(index_paths, animation)'' instead of 'deleteRowsAtIndexPaths(index_paths, withRowAnimation:animation)'."
|
||||
delete_row(index_paths, animation)
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def map_row_animation_symbol(symbol)
|
||||
symbol ||= UITableViewRowAnimationAutomatic
|
||||
{
|
||||
@@ -288,7 +292,7 @@ module ProMotion
|
||||
def get_refreshable_params
|
||||
@refreshable_params ||= nil
|
||||
end
|
||||
|
||||
|
||||
# Indexable
|
||||
def indexable(params = {})
|
||||
@indexable_params = params
|
||||
|
||||
Reference in New Issue
Block a user