File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
lib/ajax-datatables-rails
spec/ajax-datatables-rails Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,15 @@ def global_search_delimiter
111111 GLOBAL_SEARCH_DELIMITER
112112 end
113113
114+ def column_id ( name )
115+ view_columns . keys . index ( name . to_sym )
116+ end
117+
118+ def column_data ( column )
119+ id = column_id ( column )
120+ params . dig ( 'columns' , id . to_s , 'search' , 'value' )
121+ end
122+
114123 def raw_records_error_text
115124 <<-ERROR
116125
Original file line number Diff line number Diff line change @@ -222,6 +222,25 @@ def paginate_records(records)
222222 expect ( datatable . datatable . send ( :per_page ) ) . to eq ( 20 )
223223 end
224224 end
225+
226+ describe '#column_id' do
227+ let ( :datatable ) { ComplexDatatable . new ( sample_params ) }
228+
229+ it 'should return column id from view_columns hash' do
230+ expect ( datatable . send ( :column_id , :username ) ) . to eq ( 0 )
231+ expect ( datatable . send ( :column_id , 'username' ) ) . to eq ( 0 )
232+ end
233+ end
234+
235+ describe '#column_data' do
236+ let ( :datatable ) { ComplexDatatable . new ( sample_params ) }
237+ before { datatable . params [ :columns ] [ '0' ] [ :search ] [ :value ] = 'doe' }
238+
239+ it 'should return column data from params' do
240+ expect ( datatable . send ( :column_data , :username ) ) . to eq ( 'doe' )
241+ expect ( datatable . send ( :column_data , 'username' ) ) . to eq ( 'doe' )
242+ end
243+ end
225244 end
226245 end
227246end
You can’t perform that action at this time.
0 commit comments