Refactor the grid flexible sorter

| Q                   | A
| ------------------- | ---
| Bug fix?            | N
| New feature?        | N
| BC breaks?          | N
| Tests pass?         | Y
| Scenarios pass?     | Y
| Checkstyle issues?  | N
| Changelog updated?  | N
| Fixed tickets       | PIM-2035
| Doc PR              |