lib/ProMotion/table/data/table_data.rb in ProMotion-2.7.0 vs lib/ProMotion/table/data/table_data.rb in ProMotion-2.7.1
- old
+ new
@@ -1,11 +1,11 @@
module ProMotion
class TableData
include ProMotion::Table::Utils
include ProMotion::TableDataBuilder
- attr_accessor :data, :filtered_data, :search_string, :original_search_string, :filtered, :table_view, :search_params
+ attr_accessor :data, :filtered_data, :table_view
def initialize(data, table_view, search_action = nil)
@search_action ||= search_action
if data.include?(nil)
@@ -25,11 +25,11 @@
def section(index)
sections.at(index) || { cells: [] }
end
def sections
- self.filtered ? self.filtered_data : self.data
+ filtered? ? self.filtered_data : self.data
end
def section_length(index)
section(index)[:cells].length
end
@@ -53,12 +53,17 @@
def default_search(cell, search_string)
cell[:searchable] != false && "#{cell[:title]}\n#{cell[:search_text]}".downcase.strip.include?(search_string.downcase.strip)
end
+ def filtered?
+ @filtered == true
+ end
+
def search(search_string)
- start_searching(search_string) # update the search string
+ @filtered = true
+ self.filtered_data = []
self.data.compact.each do |section|
new_section = {}
new_section[:cells] = section[:cells].map do |cell|
@@ -72,24 +77,12 @@
if new_section[:cells] && new_section[:cells].length > 0
new_section[:title] = section[:title]
self.filtered_data << new_section
end
end
-
- self.filtered_data
end
- def start_searching(search_string = '')
- self.filtered_data = []
- self.filtered = true
- self.search_string = search_string.downcase.strip
- self.original_search_string = search_string
- end
-
- def stop_searching
- self.filtered_data = []
- self.filtered = false
- self.search_string = false
- self.original_search_string = false
+ def clear_filter
+ @filtered = false
end
end
end