Sorting Text Column Which Includes Number

Hi,

I am trying to sort a table column which has the type of String. my issues is when sorting and the value contains a number in the text after 1 comes 10 not 2 how can I solve this issue.

1
10
11
12
13
14
15
16
17
18
19
2
A

Letter coming after numbers in the order is exactly what is needed our only issue is the numbers are not sorting properly.

Thanks

Hi,

Your exact case is described in the doc.

Regards,
Gleb

Hi,

I tried the following the documentation my case is a little different not sure how to get it working.

I have my class for the table FacilityItem and what I want to sort by is the property position of the property facility_detail so facility_detail.position

public class NumberAwareCollectionContainerSorter  extends CollectionContainerSorter {

    public NumberAwareCollectionContainerSorter(CollectionContainer container,
                                                @Nullable BaseCollectionLoader loader) {
        super(container, loader);
    }

    @Override
    protected Comparator<? extends Entity> createComparator(Sort sort, MetaClass metaClass) {
        MetaPropertyPath metaPropertyPath = Objects.requireNonNull(
                metaClass.getPropertyPath(sort.getOrders().get(0).getProperty()));

        if (metaPropertyPath.getMetaClass().getJavaClass().equals(FacilityItem.class)
                && "position".equals(metaPropertyPath.toPathString())) {
            boolean isAsc = sort.getOrders().get(0).getDirection() == Sort.Direction.ASC;
            return Comparator.comparing(
                    (FacilityItem e) -> e.getFacility_detail().getPosition() == null ? null : Integer.valueOf(e.getFacility_detail().getPosition()),
                    EntityValuesComparator.asc(isAsc));
        }
        return super.createComparator(sort, metaClass);
    }
}

Hi,

If something doesn’t work, please be more specific about what’s broken.

Gleb

The result is the same when sorting with the selected column position.

This is the model

FacilityItem:
Item
FacilityDetail

FacilityDetail:
Facility
Section
Position

What I am trying to do is sort the using the position which is facility_detail.position with reference to the main entity

Hi,

Unfortunately, it’s impossible to provide any solution without investigating a demo project where the problem is reproduced.

Gleb