[Lada-commits] [PATCH] LadaPrint enabled dynamic printing of tables

Wald Commits scm-commit at wald.intevation.org
Wed Sep 30 15:24:40 CEST 2015


# HG changeset patch
# User Dustin Demuth <dustin at intevation.de>
# Date 1443619465 -7200
# Node ID 6739bfdb743e022803348b1045219ca02b571dc8
# Parent  e7270963947cfc44abb348277d41fb28fea735fa
LadaPrint enabled dynamic printing of tables.

diff -r e7270963947c -r 6739bfdb743e app/controller/FilterResult.js
--- a/app/controller/FilterResult.js	Wed Sep 30 11:53:52 2015 +0200
+++ b/app/controller/FilterResult.js	Wed Sep 30 15:24:25 2015 +0200
@@ -223,16 +223,35 @@
         var i18n = Lada.getApplication().bundle;
         var me = this;
         var columns = [];
+        var columnNames = [];
+        var visibleColumns = {}
         var data = [];
+
         // Write the columns to an array
         try {
             for (key in selection[0].data) {
-                // Do not write owner or readonly
-                if (["owner", "readonly"].indexOf(key) == -1){
+                // Do not write owner or readonly or id
+                if (["owner", "readonly", "id"].indexOf(key) == -1){
                     columns.push(key);
                 }
             }
-        } catch (e) {
+        }
+        catch (e) {
+            console.log(e);
+        }
+
+        //Retrieve visible columns' id's and names.
+        try {
+            var grid = button.up('filterresultgrid');
+            var cman = grid.columnManager;
+            var cols = cman.getColumns();
+            for (key in cols) {
+                if (cols[key].dataIndex) {
+                    visibleColumns[cols[key].dataIndex] = cols[key].text;
+                }
+            }
+        }
+        catch (e) {
             console.log(e);
         }
 
@@ -245,34 +264,52 @@
                 //Lookup every column and write to data array.
                 for (key in columns){
                     var attr = columns[key];
-                    if (row[attr] != null) {
+                    //Only write data to output when the column is not hidden.
+                    if (row[attr] != null &&
+                        visibleColumns[attr] != null) {
                         out.push(row[attr].toString());
                     }
-                    else {
+                    else if (visibleColumns[attr] != null) {
                         out.push('');
                     }
                 }
                 data.push(out);
             }
-        } catch (e){
+        }
+        catch (e){
             console.log(e);
         }
-        console.log(columns);
-        console.log(data);
+
+        //Retrieve the names of the columns.
+        try {
+            var grid = button.up('filterresultgrid');
+            var cman = grid.columnManager;
+            var cols = cman.getColumns();
+            //Iterate columns and find column names for the key...
+            // This WILL run into bad behaviour when column-keys exist twice.
+            for (key in columns){
+                for (k in cols){
+                    if (cols[k].dataIndex == columns[key]){
+                        columnNames.push(cols[k].text);
+                        break;
+                    }
+                }
+            }
+        }
+        catch (e) {
+            console.log(e);
+        }
 
         var printData = {
             'layout': 'A4 landscape',
             'outputFormat': 'pdf',
             'attributes': {
                 'title': 'Auszug aus LADA',
-                'datasource': [{
-                    'displayName': 'Proben',
-                    'table': {
-                        'columns': columns,
-                        'data': data
-                    }
-
-                }]
+                'displayName': 'Proben',
+                'table': {
+                    'columns': columnNames,
+                    'data': data
+                }
             }
         }
 


More information about the Lada-commits mailing list