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

Configure defaultSort per column #677

Open
fracz opened this issue Aug 12, 2015 · 7 comments
Open

Configure defaultSort per column #677

fracz opened this issue Aug 12, 2015 · 7 comments

Comments

@fracz
Copy link

fracz commented Aug 12, 2015

One should be able to set the defaultSort on column basis.

I.e. I want to sort dates descending and names ascending by default.

<td data-title="'Name'" sortable="'name'" default-sort-direction="asc"></td>
<td data-title="'Date'" sortable="'date'" default-sort-direction="desc"></td>
@christianacca
Copy link
Collaborator

Funny I was putting together a codepen demo of how to programatically change sort order and it showed how you can apply a default sort direction to each column.

You might be able to use some of the ideas to achieve what you want.

@fracz
Copy link
Author

fracz commented Aug 12, 2015

@christianacca, this is not exactly what I need here. I need to define a default sort direction for column.

Suppose you have ng-table with no sorting applied. When users clicks "Name" column, it should be sorted ascending first. On the second click - descending.

When user clicks "Date" column, it should be sorted descending firts and then - on the second click - ascending.

Now, I'm able to choose whether default sort should be asc or desc, but I can do it only for all columns at once.

@christianacca
Copy link
Collaborator

Try playing around with the demo a little more as it does allow you to define a different sort direction for each column independently.

Below shows that age is being sorted desc by default and name by asc:

image

image

image

@lanceonken
Copy link

@christianacca Thanks for the codepen demo laying out both ngTable and dynamic versions.

Looking to implement a feature which allows columns to be shown/hidden. The dynamic column approach works but needing take control over rendering of table cells (demo33) results in the table definition essentially being duplicated as each td needs to be again specified.

Issue 546 asked about accessing $columns from controller might allow the entire ngTable definition to exist in the html and have the js controller access the columns.

TLDR: Is there a strategy for configurable columns using ngTable? If ngTableDynamic, is there an approach to DRY up the table definition when needing control over the cells?

@lanceonken
Copy link

I think the trick is using bind-html-compile.
<td ng-repeat="col in $columns"><div bind-html-compile="col.content"></div></td>

Then in the js column definition add a field such as content with the desired directive.
{ field: "name", title: "Name", sortable: "name", sortDirection: "asc", show: true, content: $sce.trustAsHtml('{{something | filter }}'), },

nonplus added a commit to nonplus/ng-table that referenced this issue Feb 13, 2016
Allows per-column configuration of default sort order for esvit#677
@georgmu
Copy link

georgmu commented Sep 22, 2016

Is there a chance that this get merged when the conflicts are resolved?

I manually did the 3 changes of #804 and it works fine (except that parsedAttribute('defaultSort') should be parsedAttribute('default-sort') ).

If there is a chance of merging, I would create a new pull request which applies on master.

@christianacca
Copy link
Collaborator

Hi @georgmu, if you create another PR with some unit tests to support the change I'll be happy to merge...

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

No branches or pull requests

4 participants