Fix search on hidden columns in samples table

Closes SCI-813.
This commit is contained in:
Luka Murn 2016-12-23 19:56:54 +01:00
parent 4b50c73474
commit fbc2be890c
2 changed files with 29 additions and 7 deletions

View file

@ -1,5 +1,22 @@
//= require jquery-ui
// Extend datatables API with searchable options
// (http://stackoverflow.com/questions/39912395/datatables-dynamically-set-columns-searchable)
$.fn.dataTable.Api.register('isColumnSearchable()', function(colSelector) {
var idx = this.column(colSelector).index();
return this.settings()[0].aoColumns[idx].bSearchable;
});
$.fn.dataTable.Api.register('setColumnSearchable()', function(colSelector, value) {
if (value !== this.isColumnSearchable(colSelector)) {
var idx = this.column(colSelector).index();
this.settings()[0].aoColumns[idx].bSearchable = value;
if (value === true) {
this.rows().invalidate();
}
}
return value;
});
var rowsSelected = [];
// Tells whether we're currently viewing or editing table
@ -81,7 +98,8 @@ function dataTableInit() {
columns.push({
data: String(i),
defaultContent: '',
visible: visible
visible: visible,
searchable: visible
});
}
return columns;
@ -140,6 +158,7 @@ function dataTableInit() {
visibility = (visibility === 'true');
}
table.column(i).visible(visibility);
table.setColumnSearchable(i, visibility);
}
oSettings._colReorder.fnOrder(myData.ColReorder);
table.on('mousedown', function() {
@ -1017,11 +1036,13 @@ function changeToEditMode() {
self.removeClass('glyphicon-eye-open');
li.addClass('col-invisible');
column.visible(false);
table.setColumnSearchable(column.index(), false);
} else {
self.addClass('glyphicon-eye-open');
self.removeClass('glyphicon-eye-close');
li.removeClass('col-invisible');
column.visible(true);
table.setColumnSearchable(column.index(), true);
}
});
}

View file

@ -72,14 +72,15 @@ class SampleDatatable < AjaxDatatablesRails::Base
private
# filters the search array by checking if the the column is visible
def filter_search_array input_array
def filter_search_array(input_array)
param_index = 2
filtered_array =[]
filtered_array = []
input_array.each do |col|
unless params[:columns].to_a[param_index] == nil
filtered_array.push(col) unless params[:columns].to_a[param_index][1]["searchable"] == "false"
param_index += 1
end
next if params[:columns].to_a[param_index].nil?
params_col =
params[:columns].to_a.find { |v| v[1]['data'] == param_index.to_s }
filtered_array.push(col) unless params_col[1]['searchable'] == 'false'
param_index += 1
end
filtered_array
end