Merge pull request #344 from okriuchykhin/ok_SCI_779

Fix adding new samples columns [SCI-779]
This commit is contained in:
okriuchykhin 2016-12-12 09:29:27 +01:00 committed by GitHub
commit 420daf3a6a
2 changed files with 32 additions and 29 deletions

View file

@ -26,7 +26,8 @@ function dataTableInit() {
processing: true,
serverSide: true,
colReorder: {
fixedColumnsLeft: 2
fixedColumnsLeft: 2,
realtime: false
},
destroy: true,
ajax: {
@ -89,55 +90,54 @@ function dataTableInit() {
},
preDrawCallback: function() {
animateSpinner(this);
$(".sample_info").off("click");
$('.sample_info').off('click');
},
stateLoadCallback: function (settings) {
stateLoadCallback: function(settings) {
// Send an Ajax request to the server to get the data. Note that
// this is a synchronous request since the data is expected back from the
// function
var org = $("#samples").attr("data-organization-id")
var user = $("#samples").attr("data-user-id")
var org = $('#samples').attr('data-organization-id');
var user = $('#samples').attr('data-user-id');
$.ajax( {
url: '/state_load/'+org+'/'+user,
$.ajax({
url: '/state_load/' + org + '/' + user,
data: {org: org},
async: false,
dataType: "json",
type: "POST",
success: function (json) {
dataType: 'json',
type: 'POST',
success: function(json) {
myData = json.state;
}
} );
return myData
});
return myData;
},
stateSaveCallback: function (settings, data) {
stateSaveCallback: function(settings, data) {
// Send an Ajax request to the server with the state object
var org = $("#samples").attr("data-organization-id")
var user = $("#samples").attr("data-user-id")
var org = $('#samples').attr('data-organization-id');
var user = $('#samples').attr('data-user-id');
// Save correct data
if (loadFirstTime == true) {
data = myData;
}
$.ajax( {
url: '/state_save/'+org+'/'+user,
$.ajax({
url: '/state_save/' + org + '/' + user,
data: {org: org, state: data},
dataType: "json",
type: "POST"
} );
dataType: 'json',
type: 'POST'
});
loadFirstTime = false;
},
fnInitComplete: function(oSettings, json) {
// Reload correct column order and visibility (if you refresh page)
oSettings._colReorder.fnOrder(myData.ColReorder);
for (var i = 0; i < table.columns()[0].length; i++) {
var visibility = myData.columns[i].visible;
if (typeof(visibility) === "string"){
var visibility = (visibility === "true");
if (typeof (visibility) === 'string') {
visibility = (visibility === 'true');
}
table.column(i).visible(visibility);
}
oSettings._colReorder.fnOrder(myData.ColReorder);
}
});
@ -813,6 +813,7 @@ function changeToEditMode() {
table.button(0).enable(false);
}
// Samples table columns dropdown handling code
(function(table) {
'use strict';
@ -852,7 +853,6 @@ function changeToEditMode() {
data.name + '</th>');
var colOrder = table.colReorder.order();
colOrder.push(colOrder.length);
table.colReorder.reset();
// Remove all event handlers as we re-initialize them later with
// new table
$('#samples').off();
@ -863,8 +863,9 @@ function changeToEditMode() {
$('div.toolbarButtons').appendTo('div.samples-table');
$('div.toolbarButtons').hide();
table = dataTableInit();
table.colReorder.order(colOrder, true);
loadColumnsNames();
table.on('init.dt', function() {
loadColumnsNames();
});
},
url: url
});
@ -986,9 +987,11 @@ function changeToEditMode() {
function initDropdown() {
table.on('init.dt', function() {
initNewColumnForm();
loadColumnsNames();
initSorting();
});
$('#samples-columns-dropdown').on('show.bs.dropdown', function() {
loadColumnsNames();
});
}
initDropdown();

View file

@ -14,7 +14,7 @@ class SamplesTable < ActiveRecord::Base
index = org_status['columns'].count
org_status['columns'][index] = SampleDatatable::
SAMPLES_TABLE_DEFAULT_STATE['columns'].first
org_status['ColReorder'] << index
org_status['ColReorder'] << index.to_s
samples_table.first.update(status: org_status)
end