Порядок столбцов таблицы Vaadin меняется автоматически

Я создал таблицу, в которой есть несколько столбцов. я дал имена заголовков для каждого столбца. После инициализации таблицы я вижу, что столбцы не отображаются в том порядке, в котором они добавляются в таблицу. Имена столбцов переупорядочены в алфавитном порядке. Пожалуйста, найдите ниже код того же самого.

private Table createGridTable() {
    Table grid = new FilterAndPagedTable(this.generateTableOptions());
    grid.addContainerProperty("previousPeriod", String.class, null);
    grid.addContainerProperty("prevchannelA", Float.class, null);
    grid.addContainerProperty("prevchannelB", Float.class, null);
    grid.addContainerProperty("prevchannelC", Float.class, null);
    grid.addContainerProperty("prevchannelD", Float.class, null);
    grid.addContainerProperty("prevAllChannelCons", Float.class, null);
    grid.addContainerProperty("presentPeriod", String.class, null);
    grid.addContainerProperty("presentchannelA", Float.class, null);
    grid.addContainerProperty("presentchannelB", Float.class, null);
    grid.addContainerProperty("presentchannelC", Float.class, null);
    grid.addContainerProperty("presentchannelD", Float.class, null);
    grid.addContainerProperty("presentAllChannelCons", Float.class, null);
    grid.addContainerProperty("diffOfPrevNPresent", Float.class, null);
    grid.addContainerProperty("percentageChangeOfPrevNPresent", String.class, null);

    grid.setColumnHeader("previousPeriod", PrevYearConstants.PREVIOUS_PERIOD);
    grid.setColumnHeader("prevchannelA", IemsConstants.A_DC_Power);
    grid.setColumnHeader("prevchannelB", IemsConstants.B_Essential_Cooling);
    grid.setColumnHeader("prevchannelC", IemsConstants.C_UPS_Power);
    grid.setColumnHeader("prevchannelD", IemsConstants.D_Non_Essential_Cooling);
    grid.setColumnHeader("prevAllChannelCons", "A + B + C + D");
    grid.setColumnHeader("presentPeriod", PrevYearConstants.PRESENT_PERIOD);
    grid.setColumnHeader("presentchannelA", IemsConstants.A_DC_Power);
    grid.setColumnHeader("presentchannelB", IemsConstants.B_Essential_Cooling);
    grid.setColumnHeader("presentchannelC", IemsConstants.C_UPS_Power);
    grid.setColumnHeader("presentchannelD", IemsConstants.D_Non_Essential_Cooling);
    grid.setColumnHeader("presentAllChannelCons", "A + B + C + D");
    grid.setColumnHeader("diffOfPrevNPresent", PrevYearConstants.DIFFERENCE);
    grid.setColumnHeader("percentageChangeOfPrevNPresent", PrevYearConstants.PERCENTAGE);
    System.out.println(grid.isSortAscending());
    System.out.println(grid.isSortEnabled());
    grid.setVisibleColumns(new Object[] { "previousPeriod", "prevchannelA", "prevchannelB", "prevchannelC",
            "prevchannelD", "prevAllChannelCons", "presentPeriod", "presentchannelA", "presentchannelB",
            "presentchannelC", "presentchannelD", "presentAllChannelCons", "diffOfPrevNPresent",
            "percentageChangeOfPrevNPresent" });



    grid.setSizeFull();
    return grid;
}

public FilterAndPagedTableOptions generateTableOptions() {
    FilterAndPagedTableOptions fptOptions = new FilterAndPagedTableOptions();
    fptOptions.setCollapseAllowed(false);
    fptOptions.setColumnReorderingAllowed(false);
    fptOptions.setSortAllowed(false);
    fptOptions.setShowInbuiltFilterBar(false);
    return fptOptions;
}

я загружаю данные в таблицу, как показано ниже

List<PrevYearConsumption> tableContainer = viewElements.get(PrevYearConstants.PREV_YEAR_TABLE_CONFIG)
                    .getTableContainer();
            this.grid.setPageLength(tableContainer.size());
            BeanItemContainer container = new BeanItemContainer<PrevYearConsumption>(PrevYearConsumption.class);
            container.addAll(tableContainer);
            this.grid.setContainerDataSource(container);

Порядок столбцов в таблице не соответствует тому, который я добавил в заголовке таблицы. Он приходит случайным образом. Я использую ваадин 8.

Пожалуйста, помогите здесь. Дайте мне знать, если потребуется какая-либо дополнительная информация.


person Ashish Ranjan    schedule 14.11.2019    source источник
comment
Порядок столбцов такой же, как в setVisibleColumns(..)? Это метод, который устанавливает порядок.   -  person Tatu Lund    schedule 14.11.2019
comment
@TatuLund да, порядок полей в классе компонента, порядок столбца заголовка и видимых столбцов одинаковы.   -  person Ashish Ranjan    schedule 15.11.2019


Ответы (1)


Это чистый Vaadin 8 или Vaadin 7 или Vaadin 8 с пакетами совместимости?

я бы попробовал вызвать

grid.setVisibleColumns(new Object[] { "previousPeriod", "prevchannelA", "prevchannelB", "prevchannelC",
        "prevchannelD", "prevAllChannelCons", "presentPeriod", "presentchannelA", "presentchannelB",
        "presentchannelC", "presentchannelD", "presentAllChannelCons", "diffOfPrevNPresent",
        "percentageChangeOfPrevNPresent" });

после загрузки данных в таблицу.

person tremendous7    schedule 14.01.2021