【问题标题】:Vaadin7 table sort label column numericallyVaadin7表格按数字排序标签列
【发布时间】:2017-10-25 16:19:25
【问题描述】:

我有多个列的 vaadin 表。其中一列属于标签类

container.addContainerProperty(ID_COLUMN, Label.class, "");

然后我把它填满

referenceItem.getItemProperty(ID_COLUMN).setValue(new Label(new Integer(reference.getId()).toString()));

当我通过点击这个表格对表格进行排序时,它会像这样对数据进行排序

1
10
100
2
200
7

所以,我尝试将类更改为整数,然后它工作正常,但我得到的数字像逗号

1
2
...
..
7,456
8,455

我怎样才能让数据按数字排序并且没有逗号。

【问题讨论】:

  • 我尝试将类更改为整数。怎么样,比如container.addContainerProperty(ID_COLUMN, Integer, "");?还有referenceItem.getItemProperty(ID_COLUMN).setValue(reference.getId());
  • 点赞referenceItem.getItemProperty(ID_COLUMN).setValue(new Integer(reference.getId()));
  • 只是为了确认它是Vaadin7?
  • 是的,它的 vaadin 7

标签: vaadin number-formatting vaadin7


【解决方案1】:

我能够弄清楚。我使用 Integer 作为我的专栏的类,并使用以下

referenceTable = new Table()
    {
        @Override
        protected String formatPropertyValue(final Object a_row_id, final Object a_col_id, final Property<?> a_property)
        {
            if (a_property.getType() == Integer.class && null != a_property.getValue())
            {
                DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(getLocale());
                df.applyLocalizedPattern("#0");
                return df.format(a_property.getValue());
            }
            return super.formatPropertyValue(a_row_id, a_col_id, a_property);
        }
    };

【讨论】:

    【解决方案2】:

    我已经有一段时间没有和 Vaadin Table 玩得开心了。

    有属性格式化程序、生成器等......但在这种情况下,最简单的方法可能是:

    container.addContainerProperty(ID_COLUMN, String.class, "");
    referenceItem.getItemProperty(ID_COLUMN).setValue(""+reference.‌​getId());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-03
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多