Skip to content

Commit eb32b40

Browse files
author
philippmeissner
committed
added helper methods
1 parent 2b4676a commit eb32b40

File tree

1 file changed

+15
-0
lines changed
  • lib/ajax-datatables-rails/datatable/column

1 file changed

+15
-0
lines changed

lib/ajax-datatables-rails/datatable/column/search.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ module Datatable
55
class Column
66
module Search
77

8+
SMALLEST_PQ_INTEGER = -2147483648
9+
LARGEST_PQ_INTEGER = 2147483647
10+
811
def searchable?
912
@view_column.fetch(:searchable, true)
1013
end
@@ -82,6 +85,18 @@ def numeric_search
8285
end
8386
end
8487

88+
def is_searchable_integer?
89+
return false unless table.respond_to?(:engine)
90+
table.engine.columns_hash[field.to_s].sql_type == 'integer' && is_integer?(search.value) && is_out_of_range?(search.value)
91+
end
92+
93+
def is_out_of_range? search_value
94+
Integer(search_value) > LARGEST_PQ_INTEGER || Integer(search_value) < SMALLEST_PQ_INTEGER
95+
end
96+
97+
def is_integer?(string)
98+
true if Integer(string) rescue false
99+
end
85100
end
86101
end
87102
end

0 commit comments

Comments
 (0)