You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RightAlignComparableNumericalFields.asciidoc 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ---
  2. title: Right Align Comparable Numerical Fields
  3. order: 63
  4. layout: page
  5. ---
  6. [[right-align-comparable-numeric-fields]]
  7. = Right-align comparable numeric fields
  8. In the table below, the various numerical fields are kind of hard to
  9. compare and easy misinterpret, because of the alignment of the values:
  10. image:img/table1.png[Table with left alignment]
  11. By right-aligning numerical fields, the values become easier to compare
  12. and less prone to misinterpretation, since the least significant digits
  13. are vertically aligned:
  14. [source,java]
  15. ....
  16. Table tblExpenses = new Table();
  17. tblExpenses.setContainerDataSource(expensesData);
  18. tblExpenses.setColumnAlignment("cost", Table.Align.RIGHT);
  19. tblExpenses.setColumnAlignment("vat", Table.Align.RIGHT);
  20. ....
  21. image:img/table2.png[Table with right alignment]
  22. This effect is of course ruined if the formats of these fields are
  23. different, such as different number of decimals. Make sure that you’re
  24. using the same format for fields that should be easy to compare.
  25. Even though this example was of a table, the same principles also apply
  26. to input fields. Right-aligning a text field indicates to the user that
  27. a numerical value is expected, and makes multiple numerical fields in
  28. the same form easier to compare. To do this, you’ll need to set up a
  29. custom theme for your application (which you’ll probably end up doing at
  30. some point anyway), set a custom stylename to the field, such as
  31. _“numerical”_ or _“right-aligned”_...
  32. [source,java]
  33. ....
  34. TextField tfExpensesLodging = new TextField(“Lodging”);
  35. tfExpensesLodging.addStyleName(“numerical”);
  36. ....
  37. ...and get your hands dirty with a bit of CSS:
  38. [source,css]
  39. ....
  40. .v-textfield.numerical {
  41. text-align: right;
  42. }
  43. ....
  44. Note that right-aligning non-comparable numerical fields, such as
  45. product IDs or ISBNs is kind of pointless, and probably best to avoid.