Search in sources :

Example 1 with SortEvent

use of com.vaadin.event.SortEvent in project VaadinUtils by rlsutton1.

the class BasePortal method setupGridSorting.

public void setupGridSorting(final Grid grid, final String keySorting) {
    if (sortListeners.get(grid) != null) {
        grid.removeSortListener(sortListeners.get(grid));
    } else {
        SortListener sortListener = new SortListener() {

            private static final long serialVersionUID = 1L;

            @Override
            public void sort(SortEvent event) {
                String sorts = "";
                for (SortOrder sort : event.getSortOrder()) {
                    sorts += sort.getPropertyId() + "=" + sort.getDirection() + ",";
                }
                getConfigDelegate().setValue(getPortal(), keySorting, sorts);
            }
        };
        sortListeners.put(grid, sortListener);
    }
    String sorts = getConfigDelegate().getValueString(getPortal(), keySorting);
    if (StringUtils.isNotEmpty(sorts)) {
        try {
            List<SortOrder> sortList = new LinkedList<>();
            String[] sortArray = sorts.split(",");
            for (String sort : sortArray) {
                String[] parts = sort.split("=");
                sortList.add(new SortOrder(parts[0], SortDirection.valueOf(parts[1])));
            }
            grid.setSortOrder(sortList);
        } catch (Exception e) {
            logger.error(e);
        }
    }
    grid.addSortListener(sortListeners.get(grid));
}
Also used : SortEvent(com.vaadin.event.SortEvent) SortOrder(com.vaadin.data.sort.SortOrder) SortListener(com.vaadin.event.SortEvent.SortListener) LinkedList(java.util.LinkedList)

Aggregations

SortOrder (com.vaadin.data.sort.SortOrder)1 SortEvent (com.vaadin.event.SortEvent)1 SortListener (com.vaadin.event.SortEvent.SortListener)1 LinkedList (java.util.LinkedList)1