Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid view cannot sort asc/desc on calculated values #4572

Open
NiklasBr opened this issue Jun 26, 2019 · 8 comments

Comments

Projects
None yet
4 participants
@NiklasBr
Copy link
Contributor

commented Jun 26, 2019

Bug Report

Expected behavior

To be able to sort by calculated fields

Actual behavior

The grid view does not sort at all

Steps to reproduce

  1. Add a calculated value field (and the corresponding class and method) to an object
  2. Create at least two of those objects
  3. Open the grid view, configure it to show the calculated value's column
  4. Attempt to sort by that column, result: Sorting is not done at all.
@weisswurstkanone

This comment has been minimized.

Copy link
Contributor

commented Jun 26, 2019

Did you save the objects first? Sorting is still based on the query table.

@NiklasBr

This comment has been minimized.

Copy link
Contributor Author

commented Jun 26, 2019

All objects are saved, yes.

@prugala

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2019

I tried to reproduce it. I used calcaulated value field with text and numbers only.
In both cases sort works.

@NiklasBr

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2019

Still cannot get it to work with this class in Pimcore 6 which should return the content of IfsName if displayName is empty. Both fields are regular input fields with "regular" human-readable product names like "Green sock size L".

class DisplayNameCalculator
{
    public static function compute($object, $context): ?string
    {
        if ($context->getFieldname() === 'displayNameCalculated') {
            /** @var \Pimcore\Model\DataObject\Product $object */
            $displayName = $object->getDisplayName();
            return $displayName ?? $object->getIfsName();
        }

        Logger::error("Tried to calculate unkown field displayNameCalculated for object id: {$object->getId()} of class {$object->getClassName()}");
        return null;
    }
}

Have cleared caches and re-saved objects countless times by now, sorting does not work.

@prugala

This comment has been minimized.

Copy link
Contributor

commented Jul 1, 2019

I cant still reproduce problem.

I have 2 object with field name and names:
Green Sock size L and Green Sock size S

After save I can sort with my calculated field.

My compute method:

public static function compute($object, $context): ?string
{
        /** @var \Pimcore\Model\DataObject\Test $object */
        return $object->getName();
}```
@NiklasBr

This comment has been minimized.

Copy link
Contributor Author

commented Jul 2, 2019

Skärmbild (63)

Skärmbild (70)

Skärmbild (71)

Skärmbild (72)

Skärmbild (73)

Note how the last two are identical (and by all appearances randomly sorted the same way) even though I switched the ASC/DESC sort order. All other columns work fine for sorting both ascending and descending.

@AlekMosingiewicz

This comment has been minimized.

Copy link
Contributor

commented Jul 3, 2019

@NiklasBr Basically, I've set everything up as you did, using the latest version of dev-master. Everything seems to work correctly.
Maybe the problem is with UTF signs in the name?

class NameCalculator
{
    public static function compute($object, $context) {
        if ($context->getFieldname() === "realname") {
            $displayName = $object->getOthername();
            return $displayName ?? $object->getName();
        }

        Logger::error("Tried to calculate unkown field realname for object id: {$object->getId()} of class {$object->getClassName()}");
        return null;
    }
}

calcval
calcval(1)
calcval(2)

@AlekMosingiewicz

This comment has been minimized.

Copy link
Contributor

commented Jul 3, 2019

Nope:
calcval2
calcval3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.