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

Allow to provide initial order per DataTable column #1564

Merged
merged 1 commit into from
May 27, 2024

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented May 27, 2024

Add a new initialColumnsOrderDir prop to DataTable which is a partial record mapping column names with an order direction.

When a column becomes ordered, instead of always defaulting to ascending order, we now first check if that column is defined there. If not defined, we fall back to initially order in ascending direction.

default-order-dir-2024-05-27_14.22.45.mp4

Copy link

codecov bot commented May 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2a2c6ab) to head (abd4469).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1564   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           62        62           
  Lines         1036      1041    +5     
  Branches       394       397    +3     
=========================================
+ Hits          1036      1041    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@acelaya acelaya force-pushed the data-table-initial-dir branch 2 times, most recently from bd5a6b7 to 4eb0958 Compare May 27, 2024 12:29
@@ -74,7 +74,7 @@ describe('DataTable', () => {
);
}

const createComponent = (Component, props = {}) => {
const createComponent = ({ Component = DataTable, ...props } = {}) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not directly related with the main changes in this PR, but to avoid duplicating createComponent(DataTable) over and over, I added a new Component pseudo-prop/option here, which defaults to DataTable.

With this, we can just call createComponent() or createComponent(props) in most of the cases, and when a different component is needed, we can additionally pass createComponent({ Component: Whatever, ...otherProps }).

@acelaya acelaya marked this pull request as ready for review May 27, 2024 12:33
@acelaya acelaya requested a review from robertknight May 27, 2024 12:33
Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

I had some feedback on the name, but looks good otherwise.

src/components/data/DataTable.tsx Outdated Show resolved Hide resolved
src/components/data/test/DataTable-test.js Outdated Show resolved Hide resolved
src/components/data/test/DataTable-test.js Outdated Show resolved Hide resolved
src/components/data/test/DataTable-test.js Outdated Show resolved Hide resolved
@acelaya acelaya force-pushed the data-table-initial-dir branch from 4eb0958 to abd4469 Compare May 27, 2024 13:44
@acelaya acelaya merged commit 9112634 into main May 27, 2024
4 checks passed
@acelaya acelaya deleted the data-table-initial-dir branch May 27, 2024 13:53
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.

2 participants