changeset 7602:c50dbbe17950

issue1596: Store table (cell) data twice: Once as (formatted) string as coming from server, once transformed into float (or string). The benefit is that now we can sort table data numerically, while keeping the formatted and i18ned display of values.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 27 Nov 2013 14:55:25 +0100
parents 46aeac6901d5
children 25bce6e8beea
files gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java	Wed Nov 27 14:36:35 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java	Wed Nov 27 14:55:25 2013 +0100
@@ -142,6 +142,7 @@
 
         String[] header      = list.get(0);
         String[] firstValues = list.get(1);
+        String[] displayField = new String[header.length];
 
         ListGridField[] fields = new ListGridField[header.length];
 
@@ -157,6 +158,14 @@
             catch (NumberFormatException nfe) {
                 f.setType(ListGridFieldType.TEXT);
             }
+            // To keep server-side formatting and i18n also of
+            // float values, we will store the value once formatted 'as is'
+            // to be displayed and once as e.g. float to allow functions like
+            // sorting on it.
+            displayField[i] = i + "_displayField";
+            f.setDisplayField(displayField[i]);
+            f.setValueField(String.valueOf(i));
+            f.setSortByDisplayField(false);
         }
 
         dataTable.setFields(fields);
@@ -165,7 +174,15 @@
             String[] sItem = list.get(i);
             ListGridRecord r = new ListGridRecord();
             for(int j = 0; j < sItem.length; j++) {
-                r.setAttribute(String.valueOf(j), sItem[j]);
+                // See above, display 'as is' from server, but keep value
+                // in machine-usable way (float), to allow numeric sorting.
+                r.setAttribute(displayField[j], sItem[j]);
+                if (fields[j].getType() == ListGridFieldType.TEXT) {
+                    r.setAttribute(String.valueOf(j), sItem[j]);
+                }
+                else {
+                    r.setAttribute(String.valueOf(j), nf.parse(sItem[j]));
+                }
             }
             dataTable.addData(r);
         }

http://dive4elements.wald.intevation.org