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

Add sorting to table columns #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add sorting to table columns #71

wants to merge 3 commits into from

Conversation

kkschick
Copy link

@kkschick kkschick commented Sep 3, 2016

For #11.

TODO:

  • Fix jumpy column widths on sort

};
this.resize = this.resize.bind(this);
this.prevPage = this.prevPage.bind(this);
this.nextPage = this.nextPage.bind(this);
}

componentWillMount() {
this.setState({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have to setState again, when we already have a default state? because we don't get headers until now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly. I tried to put it in the constructor, but this.props.headers wasn't defined yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would props.headers in the constructor work? this isn't defined at that point, but props does get passed in as an argument.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good call! Yeah, that worked. I'll update.

@samuelcole
Copy link
Contributor

looks awesome generally! just put some comments in line, but i would also merge as is. great work.

@kkschick
Copy link
Author

kkschick commented Sep 3, 2016

Thanks for the feedback, @samuelcole! The one issue I ran into with this is that the pagination makes it so that the columns jump in size when you sort (because there might be a longer column value on pg 2 that suddenly gets bumped to pg 1 on sort).

I'm not totally sure how to fix it and am not sure whether having sorting functionality outweighs the weirdness of the column jumpiness, so see what you think and let me know!

const values = props.values.slice(start, end);
const columns = Object.keys(values[0] || {});
values = values.slice(start, end);
const columns = props.headers;
const standardColumnWidth = 100;
const wide = (columns.length * standardColumnWidth < window.innerWidth);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have wide in the initial state, but it doesn't seem to be used anywhere -- should this calc (and standardColumnWidth) be moved to the constructor?

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

Successfully merging this pull request may close these issues.

None yet

3 participants