diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/static/new/javascript/table_functions.js | 93 | ||||
-rw-r--r-- | wqflask/wqflask/templates/search_result_page.html | 96 |
2 files changed, 94 insertions, 95 deletions
diff --git a/wqflask/wqflask/static/new/javascript/table_functions.js b/wqflask/wqflask/static/new/javascript/table_functions.js new file mode 100644 index 00000000..e24b3e03 --- /dev/null +++ b/wqflask/wqflask/static/new/javascript/table_functions.js @@ -0,0 +1,93 @@ +recheck_rows = function(the_table, checked_rows){
+ //ZS: This is meant to recheck checkboxes after columns are resized
+ check_cells = the_table.column(0).nodes().to$();
+ for (let i = 0; i < check_cells.length; i++) {
+ if (checked_rows.includes(i)){
+ check_cells[i].childNodes[0].checked = true;
+ }
+ }
+
+ check_rows = trait_table.rows().nodes();
+ for (let i =0; i < check_rows.length; i++) {
+ if (checked_rows.includes(i)){
+ check_rows[i].classList.add("selected")
+ }
+ }
+ }
+
+get_checked_rows = function(table_id){
+ let checked_rows = []
+ $("#" + table_id + " input").each(function(index){
+ if ($(this).prop("checked") == true){
+ checked_rows.push(index);
+ }
+ });
+
+ return checked_rows
+}
+
+function setUserColumnsDefWidths(table_id) {
+ var userColumnDef;
+
+ // Get the settings for this table from localStorage
+ var userColumnDefs = JSON.parse(localStorage.getItem(table_id)) || [];
+
+ if (userColumnDefs.length === 0 ) return;
+
+ columnDefs.forEach( function(columnDef) {
+
+ // Check if there is a width specified for this column
+ userColumnDef = userColumnDefs.find( function(column) {
+ return column.targets === columnDef.targets;
+ });
+
+ // If there is, set the width of this columnDef in px
+ if ( userColumnDef ) {
+
+ columnDef.sWidth = userColumnDef.width + 'px';
+ columnDef.width = userColumnDef.width + 'px';
+
+ $('.toggle-vis').each(function(){
+ if ($(this).attr('data-column') == columnDef.targets){
+ if ($(this).hasClass("active")){
+ columnDef.bVisible = false
+ } else {
+ columnDef.bVisible = true
+ }
+ }
+ })
+ }
+ });
+}
+
+function saveColumnSettings(table_id, trait_table) {
+var userColumnDefs = JSON.parse(localStorage.getItem(table_id)) || [];
+
+var width, header, existingSetting;
+
+trait_table.columns().every( function ( targets ) {
+
+ // Check if there is a setting for this column in localStorage
+ existingSetting = userColumnDefs.findIndex( function(column) { return column.targets === targets;});
+
+ // Get the width of this column
+ header = this.header();
+ width = $(header).width();
+
+ if ( existingSetting !== -1 ) {
+ // Update the width
+ userColumnDefs[existingSetting].width = width;
+ } else {
+
+ // Add the width for this column
+ userColumnDefs.push({
+ targets: targets,
+ width: width,
+ });
+
+ }
+});
+
+// Save (or update) the settings in localStorage
+localStorage.setItem(table_id, JSON.stringify(userColumnDefs));
+}
\ No newline at end of file diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index a351256b..436eb639 100644 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -154,6 +154,7 @@ <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='fontawesome/js/all.min.js') }}"></script> <script language="javascript" type="text/javascript" src="/static/new/javascript/search_results.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/javascript/table_tools.js"></script> <script type='text/javascript'> var trait_list = {{ trait_list|safe }}; @@ -391,34 +392,6 @@ }{% endif %} ]; - recheck_rows = function(the_table, checked_rows){ - //ZS: This is meant to recheck checkboxes after columns are resized - check_cells = the_table.column(0).nodes().to$(); - for (let i = 0; i < check_cells.length; i++) { - if (checked_rows.includes(i)){ - check_cells[i].childNodes[0].checked = true; - } - } - - check_rows = trait_table.rows().nodes(); - for (let i =0; i < check_rows.length; i++) { - if (checked_rows.includes(i)){ - check_rows[i].classList.add("selected") - } - } - } - - get_checked_rows = function(table_id){ - let checked_rows = [] - $("#" + table_id + " input").each(function(index){ - if ($(this).prop("checked") == true){ - checked_rows.push(index); - } - }); - - return checked_rows - } - loadDataTable(true); function loadDataTable(first_run=false){ @@ -541,72 +514,6 @@ trait_table.columns.adjust(); }); - function setUserColumnsDefWidths(table_id) { - var userColumnDef; - - // Get the settings for this table from localStorage - var userColumnDefs = JSON.parse(localStorage.getItem(table_id)) || []; - - if (userColumnDefs.length === 0 ) return; - - columnDefs.forEach( function(columnDef) { - - // Check if there is a width specified for this column - userColumnDef = userColumnDefs.find( function(column) { - return column.targets === columnDef.targets; - }); - - // If there is, set the width of this columnDef in px - if ( userColumnDef ) { - - columnDef.sWidth = userColumnDef.width + 'px'; - columnDef.width = userColumnDef.width + 'px'; - - $('.toggle-vis').each(function(){ - if ($(this).attr('data-column') == columnDef.targets){ - if ($(this).hasClass("active")){ - columnDef.bVisible = false - } else { - columnDef.bVisible = true - } - } - }) - } - }); - } - - function saveColumnSettings(table_id, trait_table) { - var userColumnDefs = JSON.parse(localStorage.getItem(table_id)) || []; - - var width, header, existingSetting; - - trait_table.columns().every( function ( targets ) { - - // Check if there is a setting for this column in localStorage - existingSetting = userColumnDefs.findIndex( function(column) { return column.targets === targets;}); - - // Get the width of this column - header = this.header(); - width = $(header).width(); - - if ( existingSetting !== -1 ) { - // Update the width - userColumnDefs[existingSetting].width = width; - } else { - - // Add the width for this column - userColumnDefs.push({ - targets: targets, - width: width, - }); - - } - }); - - // Save (or update) the settings in localStorage - localStorage.setItem(tableId, JSON.stringify(userColumnDefs)); - } - $('.toggle-vis').on( 'click', function (e) { e.preventDefault(); @@ -623,7 +530,6 @@ } } ); - $('#redraw').click(function() { var table = $('#' + tableId).DataTable(); table.colReorder.reset() |