Merge branch 'master' into ml_sci_843

This commit is contained in:
mlorb 2017-01-11 11:35:41 +01:00 committed by GitHub
commit 90e644ddd9
3 changed files with 41 additions and 6 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() {
@ -441,6 +460,9 @@ function onClickEdit() {
// Adjust columns width in table header
table.columns.adjust();
$("select[name=sample_type_id]").on('change', function(){
table.columns.adjust();
});
// Adjust tables height when selecting sample type or group
$('.btn-group.bootstrap-select.show-tick').on('shown.bs.dropdown', function () {
@ -1037,11 +1059,19 @@ 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);
}
// Re-filter/search if neccesary
var searchText = $('div.dataTables_filter input').val();
if (!_.isEmpty(searchText)) {
table.search(searchText).draw();
}
sampleInfoListener();
});

View file

@ -1305,6 +1305,10 @@ table.dataTable {
tbody > tr > .selected {
background-color: $color-alto !important;
color: $color-emperor !important;
a {
color: $color-theme-primary !important;
}
}
.sorting_desc,

View file

@ -78,12 +78,13 @@ class SampleDatatable < AjaxDatatablesRails::Base
# filters the search array by checking if the the column is visible
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