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 ordering of columns in Data Model #3720

Closed
tomsej opened this issue Nov 2, 2016 · 31 comments · Fixed by #12559
Closed

Allow ordering of columns in Data Model #3720

tomsej opened this issue Nov 2, 2016 · 31 comments · Fixed by #12559
Assignees
Labels
Administration/Table Metadata Priority:P1 Security holes w/o exploit, crashing, setup/upgrade, login, broken common features, correctness Type:New Feature
Milestone

Comments

@tomsej
Copy link

tomsej commented Nov 2, 2016

Currently it is not possible to change ordering of columns in Data Model tab. It seems that columns are ordered by database column name. If the business name is different to database column name, it is hard to find requested field.

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

@tomsej tomsej added the Proposal label Nov 7, 2016
@HelmiRifai

This comment has been minimized.

1 similar comment
@LukeAbell

This comment has been minimized.

@philip-n
Copy link

Just started to create a new issue, but found this one just in time. Since I already wrote "my" issue, I'll just paste it here anyway ;)


For my use case, preserving and/or manually arranging the order of the columns would be very useful. This could be done either during sync (i.e. to preserve the original order of the columns) or by having a possibility to manually arrange them in the Admin > Data Model view.

Example:

  • A table has four columns named "First", "Second", "Third", "Fourth".
  • Current situation: They will be listed as "First", "Fourth", "Second", "Third". This is true for both views in Admin > Data Model (show original schema turned on / off) as well as e.g. the "raw data" output for questions.
  • Proposal / wish: Add the possiblilty to define a custom ordering, to make the columns show up in their original order ("First", "Second", "Third", "Fourth") and/or in a custom order ("Fourth", "Third", "Second", "First")

Currently, there is the possibility to "customize this table" when adding a new question, where the fields can be (de)selected and their order can be arranged. However, this reordering needs to be done for each question --> having a custom order in the data model would be a much more elegant solution.

@mvrabel
Copy link

mvrabel commented Nov 26, 2018

@salsakran could you add priority to this please ?
This issue would save a lot o time for us
Each time we want to create a new question we have tu manually rearange the columns for each question.

This is especialy tedious when you have a table with ~40 columns.
If we could add a default ordering OR if the qustion would show columns in order as in the database table that would be great.
Thanks,
Martin

@mazameli
Copy link
Contributor

Thanks for the feedback; definitely makes sense. One workaround for now, if you're doing any querying with the graphical custom query builder, would be to save a question that just returns all the raw data in a particular table, but with the columns reordered the way you'd like. Then you can use that saved question as a pseudo data table for new custom questions. More on these "nested" questions here: https://www.metabase.com/blog/Nested-Queries/

@mvrabel
Copy link

mvrabel commented Nov 27, 2018

@mazameli Thanks for hte quick reply. I know about this workaround.
The problem is that it's not possible to use segments if you do that :(

@fredericocarneiro

This comment has been minimized.

@Crusader4Christ
Copy link

@mazameli Second problem is - filter id widgets not working (Not filter by name, not show name by id)

@Nico-P-FR
Copy link

Same here. It would be very useful to let us reorganize fields order or at least choose between automatic alphabetical order and database original order.

@rarup1
Copy link

rarup1 commented Oct 30, 2019

This is a very important feature for our usage too. It is fine to use the work around mentioned above but when you ask someone to use your data structure from the raw tables in the DW (which is far more complete) they will have to go through the pain of unticking and organising all over again.

Is there anyone that is looking into adding a setting within the data model that allows either alphabetical ordering as it is at the moment or db ordering as collected from the information schema?

Would try to dive into the code myself but I am sure someone who knows the project could do it in a heartbeat...

@antoine-lizee
Copy link

antoine-lizee commented Nov 7, 2019

In our case:

  • We don't need to be able to decide the order of individual fields in metabase, and I don't think most people here do.
  • We need to have the database order be kept because currently, the exploration of data is close to impossible as soon as there are more than 10 fields. The reshuffle of the fields that Metabase does completely undermines our current push for promoting the query builder to interact with the data we prepared. (we get back to SQL each time just for this reason... SELECT * FROM xxx doesn't change order!)
  • I don't see a viable use case for reshuffling the column order, so I would just remove this reordering. But if you are afraid of back-compatibility it makes sense to add a general toggle between alphabetical / database order.

🙏 Please don't let the potential of building a complete ordering feature prevent you from shipping the simple fix!

@lucascorreaaa
Copy link

This feature is theoretically simple and it would be really handy. Hope someone can fix it soon.

@mazameli mazameli added the Priority:P1 Security holes w/o exploit, crashing, setup/upgrade, login, broken common features, correctness label Nov 21, 2019
@yskolnick
Copy link

Is this feature being worked on?

@yskolnick
Copy link

I am willing to

In our case:

  • We don't need to be able to decide the order of individual fields in metabase, and I don't think most people here do.
  • We need to have the database order be kept because currently, the exploration of data is close to impossible as soon as there are more than 10 fields. The reshuffle of the fields that Metabase does completely undermines our current push for promoting the query builder to interact with the data we prepared. (we get back to SQL each time just for this reason... SELECT * FROM xxx doesn't change order!)
  • I don't see a viable use case for reshuffling the column order, so I would just remove this reordering. But if you are afraid of back-compatibility it makes sense to add a general toggle between alphabetical / database order.

🙏 Please don't let the potential of building a complete ordering feature prevent you from shipping the simple fix!

I am looking through the code to see where the reordering takes place and I am having a hard time locating it. Anyone have any idea?

@sajjadkhanGit
Copy link

This is a big issue, Did someone find any solution to this?

@sajjadkhanGit
Copy link

Metabase should have picked the order of the columns as it is coming from the Source DB table.
Imagin 50 columns of a table and re-arranging each time we click on the table is much hard-work.

@Nico-P-FR
Copy link

No, still have this problem and it is very painfull for us too. We have table with more than 100 columns... If the feature "allow ordering" is too long due to UI, a MVP could be to switch from automatic alphabetical ordering to keeping the DB Source order.
Even the Metabase field metabase_field.position is already there, it is just not used...

@mazameli
Copy link
Contributor

I agree that the incremental step we should seriously consider taking on this is to preserve the order of columns as they are in the database.

This feels similar to the "friendly field names" behavior that we undid — we're currently trying to be overly clever and in the process are undermining what people actually want and expect.

@mattarderne
Copy link

Related - is there a bug for dragging a field "selects" other fields as you move fields around? Combining that with this issue has caused me much frustration.

image

Firefox, latest Metabase

@camsaul
Copy link
Member

camsaul commented May 14, 2020

Notes from our meeting about this today:

  • There are either 3 or 4 sort styles (TBD): alphabetical, database order, custom, and "smart sort" (sort ID/names first, then sort by custom order, then alphabetically -- this is the current behavior)
  • We currently record Field position (custom sort order) -- in an older version of Metabase you could change this in the UI. Currently, it's 0 for all Fields.
  • We should add a db_position column to complement the position and set the value of this as part of sync
  • We should add a "sort style" column to Table -- when new Fields are added, the Table should be re-sorted according to these rules
    • For existing Tables, it's TBD whether what we should set as their default sort style -- and whether we want to resort everything on the next sync if we change it to something other than smart sort
    • We should be able to change this via the API -- and when the value changes, re-sort all of the Fields in the Table (i.e., update their position) according to the rule.
    • Changing the position of a Field manually should change the Table sort style back to "custom"
  • I think sync should also update the position of each column according to the sort style for the Table. That way we don't need to duplicate the sort logic in other places that need the sorted columns -- the QP and API endpoints
  • We should remove the "smart sort" logic from the QP middleware that adds the implicit :fields clause and have it use position directly instead, assuming the positions are sorted according to the Table sort style
  • API endpoint that powers data model/etc. (?) should sort Fields according to sort order rather than alphabetically

@camsaul
Copy link
Member

camsaul commented May 14, 2020

I think FE work here is just limited to making the admin data model support drag-and-drop reordering for Fields, and adding the drop-down for Table "sort style"

@camsaul camsaul self-assigned this Jun 15, 2020
@camsaul camsaul removed their assignment Jun 16, 2020
@ghomem
Copy link

ghomem commented Jan 15, 2021

I am seeing the drag and drop problem mentioned by @mattarderne . Firefox 84.0.2. Metabase v0.37.5-SNAPSHOT using this:

https://github.com/metabase/metabase/pull/13081/files

@ghomem
Copy link

ghomem commented Jan 15, 2021

Drag and drop works on some columns but does not work on others (column goes back to the initial place). Tried Firefox and Chrome.

@flamber
Copy link
Contributor

flamber commented Jan 15, 2021

@ghomem Please try an official release - I don't know what state that PR is in. And if you are still seeing it on a release, then please open a new issue after you have searched for existing issues - I have a feeling that you're seeing #12870 and perhaps #13024 too

@ghomem
Copy link

ghomem commented Jan 15, 2021

Thank you for your support again @flamber . We will check. I thought that PR would be new enough to already have this, but maybe not.

@eozturkTF
Copy link

Hello
Very interested by this feature too.

@flamber
Copy link
Contributor

flamber commented Apr 22, 2021

@eozturkTF It has been available since 0.36.0: https://www.metabase.com/blog/v36-release-announcement/index.html

@eozturkTF
Copy link

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Administration/Table Metadata Priority:P1 Security holes w/o exploit, crashing, setup/upgrade, login, broken common features, correctness Type:New Feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.