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

Remove Column from sorting #372

Closed
sureshvarman opened this issue Mar 24, 2015 · 13 comments
Closed

Remove Column from sorting #372

sureshvarman opened this issue Mar 24, 2015 · 13 comments
Assignees
Labels
Milestone

Comments

@sureshvarman
Copy link

Is there any options to remove a particular column from sorting

@fzaninotto
Copy link
Member

Nope, not at the moment. What is your use case?

@sureshvarman
Copy link
Author

my requirement is simple that i don't want sorting for a column which is a template column

@fzaninotto
Copy link
Member

One may want to allow sorting by template, since the sort param can be tweaked in a request interceptor... We'll leave it like that.

@0xDCA
Copy link

0xDCA commented Nov 4, 2015

I believe this should be supported. In my case, the backend does not allow to sort by some fields, so trying to click on the column header just shows an error.

It would be cool if we could explicitly disable sorting for some fields

@thachp
Copy link

thachp commented Dec 21, 2015

I am open to debate on how we can best implement this enhancement. Though, I think the following adjustments would do.

@fzaninotto - Can you commit these changes to the core codes? I am dealing with the same problem as @0xDCA.

In admin-config, field.js

// https://github.com/marmelab/admin-config/blob/master/lib/Field/Field.js
add to class field attributes
this._disableSort = false; // line 9

// Add a get method and a set method.    

isDisableSort() {
    return this._disableSort;
}

disableSort() {
    this._disableSort = true;
    return this;
}

Update ng-repeat in grid template in src/javascripts/ng-admin/Crud/list/maDatagrid.js

<th ng-repeat="field in fields() track by $index"
ng-class="field.getCssClasses()" class="ng-admin-column-{{ ::field.name() }} ng-admin-type-{{ ::field.type() }}">

    // disable sort
    <a ng-if="field.isDisableSort() == false" ng-click="datagrid.sortCallback(field)">
        <span class="glyphicon {{ datagrid.sortDir === 'DESC' ? 'glyphicon-chevron-down': 'glyphicon-chevron-up' }}" ng-if="datagrid.isSorting(field)"></span>
        {{ field.label() }}
    </a>

    // remove ng-click event and replace a tag with span.    
    <span ng-if="field.isDisableSort() == true">
        {{ field.label() }}
    </span>
</th>

To disable column sort for a particular field, simply invoke disableSort().

 // for example in post.listView()
// https://github.com/marmelab/ng-admin/blob/master/examples/blog/config.js
     ....
            nga.field('tags', 'reference_many') // a Reference is a particular type of field that references another entity
                .targetEntity(tag) // the tag entity is defined later in this file
                .targetField(nga.field('name')) // the field to be displayed in this list
                .disableSort()
                .cssClasses('hidden-xs')
                .singleApiCall(ids => { return {'id': ids }; })
        ])

@seasick
Copy link

seasick commented Mar 11, 2016

Use-case for me is, that I don't want to sort fields which are references. The displayed values will not appear sorted in most cases, because its sorted by the underlying value and not by the displayed value (e.g. sort messages by user-id, but display user-name from reference).

@RichardBradley
Copy link
Contributor

+1 from me -- I have an ng-admin CRUD table which is backed by an Elasticsearch table: some columns are not sortable, and some are. I'd like to be able to disable sorting on selected fields.

@RichardBradley
Copy link
Contributor

I'll create a PR for this.

As a matter of coding style, why does ng-admin require that Field declare getters and setters for the disableSort property in the separate admin-config project? That seems to add a lot of github administration overhead. It also seems to unnecessarily couple the two projects together: the admin-config project doesn't otherwise need to know anything about field sorting, but in the current pattern it would need to declare this field just to support ng-admin.

Would a PR which omitted that change and directly set a field.disableSort = true untyped property be acceptable?

RichardBradley added a commit to RichardBradley/ng-admin that referenced this issue Mar 17, 2016
RichardBradley added a commit to RichardBradley/ng-admin that referenced this issue Mar 17, 2016
RichardBradley added a commit to RichardBradley/ng-admin that referenced this issue Mar 17, 2016
@RichardBradley
Copy link
Contributor

(If anyone else is waiting for this, you might like to have a go at tidying up my PR at #373 (see comments on that thread for what's outstanding). I'm not sure when I'll be able to get around to it.)

@mebibou
Copy link

mebibou commented Apr 3, 2016

👍

RichardBradley added a commit to RichardBradley/ng-admin that referenced this issue Apr 4, 2016
RichardBradley added a commit to RichardBradley/ng-admin that referenced this issue Apr 4, 2016
RichardBradley added a commit to RichardBradley/ng-admin that referenced this issue Apr 4, 2016
@mosasiru
Copy link

👍

RichardBradley added a commit to RichardBradley/ng-admin that referenced this issue May 24, 2016
RichardBradley added a commit to RichardBradley/ng-admin that referenced this issue Jun 15, 2016
@allentc
Copy link

allentc commented Jul 5, 2016

👍

This is so obviously necessary it's difficult to understand how it is still dragging on over a year later.

A workaround is to disable the listView heading links using CSS and the ng-admin column classes:

th.ng-admin-column-[fieldName] a {
    pointer-events: none;
    color: black;
}

@RichardBradley
Copy link
Contributor

This is so obviously necessary it's difficult to understand how it is still dragging on over a year later.

It's not really that difficult to understand -- the project is open source and free, and the maintainers work on a voluntary basis.
There is a fix available at PR #984 -- you can build and use that fork if you are in a hurry.
I'm sure the maintainers will merge it in and release a new version in due course.

(While I'm on the subject -- thanks for making ng-admin; it's saved me hundreds of hours!)

@fzaninotto fzaninotto added this to the 1.0 milestone Nov 18, 2016
@fzaninotto fzaninotto self-assigned this Dec 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants