changeset 937:6739bfdb743e

LadaPrint enabled dynamic printing of tables.
author Dustin Demuth <dustin@intevation.de>
date Wed, 30 Sep 2015 15:24:25 +0200
parents e7270963947c
children fe85a4d23370
files app/controller/FilterResult.js
diffstat 1 files changed, 53 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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
+                }
             }
         }
 

http://lada.wald.intevation.org