[REQUEST] Adjustable Column Widths for QTables
There should be an option specify column widths in a QTable. This means there should also be an option to specify the table width.
There are many use cases where tables don't have to be flex based.
OK,I will try it!
So can you tell me what is the flex based?
The entire table seems to be. The table width will stretch to fit the page and column widths adjust to a width that seems to be even spacing. This is probably what you want on a mobile device but on a browser with more screen area, you want the ability to better format the appearance of the table.
For example, if I have a column with a number and column with a long text description, there is no way to make the number column narrow and the text column wide.
Please provide a fiddle/codepen
ok, here is the link:
https://jsfiddle.net/kerbo/vyk1xL2u/
The table has two columns: ID (number) and Description.
When displaying the first time, the ID column takes up about 40% of the table width. Why 40%? What I want (since ID is a number) is about 15% for the ID and the rest for the description.
There is an "Add Row" button. This button adds a row to the table and the description column has more text than the other rows. What happens is:
-
The columns resize. I DON'T want this. Columns should stay the same width.
-
The new column widths are still not right. The ID column is still too wide and the text in the description column truncates. Looks stupid.
-
I have no idea what is going on with the ID column header. The column data is center aligned but the header text is not centered and its not left. Its somewhere in between. After adding the row, the header text moves to left aligned.
Table column widths should be configurable to a fixed width and remain consistent.
For text that can't fit in a column, there should be two options: truncate the text and add an "..." at the end to indicate more text or wrap the text (which increases the row height).
I think most people want tables to act like tables in Excel. Column widths are fixed however the user can drag the column separator to increase/decrease the width.
Is there a problem with the normal approach? https://jsfiddle.net/qukw45gc/12/
Yes, the problem is I have to apply CSS styling to do something as simple as setting the column widths. External CSS shouldn't be needed to change the behavior of a component. Appearance maybe, but not behavior. This is the reason we have components and component frameworks.
BTW, I appreciate the tip on how to set the column widths in CSS.
Column width is not behavior, is presentation :) - it belongs in CSS.
I think you agree the ability so set column widths is useful for a table. I'm hoping this feature becomes part of the component rather than the requiring the developer to understand how to do it via CSS.
And how would you implement it? How would you implement spanned cols?
I don't have the depth of knowledge with this component to say. Maybe just internally implement the CSS you posted in Fiddle. You would add a width property to the columns definition to set the width. With regard to spanned columns, I'm not asking for that. I'm sure that would be useful but for now, column widths would help greatly.
Hi,
- You could define the header and apply a style with your width there (as width needs to be specified on thead > th in order to be taken into consideration).
- Pushed a commit to add "classes" and "style" to the column definition. Will be available in 0.17.9.
I tried adding the new style property to the column definition and it doesn't do anything. I examined the html in Chrome and style was added to the TH elements.
{
name: 'lastName',
label: 'Last Name',
align: 'left',
field: 'lastName',
style: 'width: 90px'
},
<th class="text-left" style="width: 90px;">Last Name</th>
I can change the width to any value and the actual column width never changes.
@kerbo QTable at its root is a <table> like I'm sure you noticed by using Developer Tools. So style it accordingly. Blindly adding width won't work.
I'm confused. This issue was closed because a style property was added to the column definition and the new property would allow specifying a column width.
Do I have to do something else to make column widths work?
This is what the docs for the two new props says.
....
> // v0.17.9+; if using scoped slots, apply this yourself instead
style: 'width: 500px',
classes: 'my-special-class'
....
And using scoped slots, I believe, means using the item slot in grid mode. I could be wrong though.
Scott
If so, then the Issue should not have been closed. I think the QTable should provide a configuration option where the developer can specify the column widths as the current default does not do a very good job.
This is a commonly asked for feature and will be the source of many questions going forward especially now that there is a mention of "width" in the column docs.
@kerbo Like I said, if you know how to style a native <table> then you'll know how to style QTable also, since it works on the same principle at its root. Since the width is variable, based on window size, it's better to use percentages rather than units ('30%' rather than '100px'), but specify a percentage for each column. Google about styling a table pls as there are many caveats. Please don't expect Quasar docs to also cover the basics of web development. Sorry if I am being too harsh, it's just that it's not normal to expect Quasar docs to also contain an encyclopedia of CSS and JS -- that's just knowledge you need apriori in order to use this framework (which is clearly stated in the first doc pages).
I appreciate the help. My css skills are basic which is why I'm using Quasar. I've built quite of lot of functionality without needing one line of css. QTable has been the only exception.
And as I said, I think column widths should be part of the component like many of the other configuration options for QTable. A simple example is the "align" property for the column. Why have the property? Just make the user write css. I think you will agree its much simpler for the developer to set the align property rather deal with css. It should work the same for column widths.
I'm pretty sure anyone using QTables for web apps will have an issue with column widths. Why make it harder than it needs to be?
But hey, I've got the css stuff to work so I can move on. But again, this issue won't go away. Other developers will have the same questions. In fact they already have. Its in the forum. I know because I looked there before creating this issue.
Who's making it harder than it needs to be? Quasar or web standards? You can't expect Quasar to magically sidestep web standards as they are implemented in browsers.
What would indeed help and show a little appreciate for the framework is to hit the pencil on the top-right doc page (or "Edit" link at the very bottom) and add an example which you feel it might help others. It will only take like 2 minutes of your time. You probably imagine there's a hundred developers behind Quasar and they're lazy or something -- I don't blame you, because from the outside it's very hard to get a glimpse of what almost non-stop work on Quasar means (CLI, Quasar itself, docs, Quasar Play, testing on all possible platforms and in every scenario, vue cli plugin, ... and the list goes on). If every developer would help with just 2 minutes to at least improve docs that would be totally awesome. And we're on the same boat. Helping apps get better.