File tree 2 files changed +28
-0
lines changed
lib/ajax-datatables-rails
spec/ajax-datatables-rails
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
111
111
GLOBAL_SEARCH_DELIMITER
112
112
end
113
113
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
+
114
123
def raw_records_error_text
115
124
<<-ERROR
116
125
Original file line number Diff line number Diff line change @@ -222,6 +222,25 @@ def paginate_records(records)
222
222
expect ( datatable . datatable . send ( :per_page ) ) . to eq ( 20 )
223
223
end
224
224
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
225
244
end
226
245
end
227
246
end
You can’t perform that action at this time.
0 commit comments