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

DataList::canSortBy can't handle dot notation properly #3842

Open
dhensby opened this issue Feb 2, 2015 · 4 comments
Open

DataList::canSortBy can't handle dot notation properly #3842

dhensby opened this issue Feb 2, 2015 · 4 comments

Comments

@dhensby
Copy link
Contributor

dhensby commented Feb 2, 2015

There are two instances using dot notation that fail where I think it should work. Take the following examples:

Example 1 - Bad sort resolution

class MyDataObject extends DataObject {

    private static $has_one = array(
        'Person' => 'Member',
    );

    private static $summary_fields = array(
        'Person.Name' => 'Person name',
    );

}

This results in a column that is identified as sortable but when a sort is attempted by clicking on the column header an error is thrown. "Unknown column Person.Name"

Example 2 - Fail to resolve formatted fields

class MyDataObject extends DataObject {

    private static $db = array(
        'Date' => 'SS_Datetime',
    );

    private static $summary_fields = array(
        'Date.Nice' => 'Date',
    );

}

In this example, the column is not sortable (though it really should be because we are just manipulating the appearance of the data from a column).


Currently GridFieldSortableHeader@getHTMLFragments is failing to correctly identify if dot notation is just a style manipulation or if it's a relationship. If it's a relationship, it's failing to correctly work out the relation field to sort on.

I think the logic in getHTMLFragments is too complex as it is written to work out an infinite level of nesting (though breaks out on SS_List instances which is surely the only time infinite nesting could work?!).

I propose we limit the logic to assume there can only be a maximum of 3 levels of nesting. (Relation.Field.Format / Field.Format / Relation.Field / Field). Perhaps even assuming that the format would default to "Nice"? [edit: removed as not a job for sortable headers]

This would allow simpler code and for clearer documentation.

@sminnee sminnee changed the title GridFieldSortableHeader can't handle dot notation properly DataList::canSortBy can't handle dot notation properly May 10, 2017
@sminnee
Copy link
Member

sminnee commented May 10, 2017

It's a missing feature more than a bug because the current behaviour is internally consistent.

Note that canFilterBy() has a similar weakness.

@dhensby
Copy link
Contributor Author

dhensby commented May 10, 2017

Hm - I think a PR was opened a while ago attempting to fix this - @kinglozzer were you involved in that?

@kinglozzer
Copy link
Member

This may have been fixed in #4812?

@dhensby
Copy link
Contributor Author

dhensby commented May 11, 2017

Hmm - I was thinking more about the GridFieldSortableHeader component - I'll look into testing this soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants