[PATCH 4 of 4] issue1596: Store table (cell) data twice: Once as (formatted) string

Wald Commits scm-commit at wald.intevation.org
Wed Nov 27 14:54:56 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1385560525 -3600
# Node ID c50dbbe17950a773fe1bb28ed8431c7bd1ae89a0
# Parent  46aeac6901d52609b7849bfea621d1bc16d6f4a1
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.

diff -r 46aeac6901d5 -r c50dbbe17950 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java
--- 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);
         }


More information about the Dive4elements-commits mailing list