Skip to content

MudTable: Add CellClass parameter#10884

Merged
ScarletKuro merged 14 commits intoMudBlazor:devfrom
boukenka:compact
Mar 6, 2025
Merged

MudTable: Add CellClass parameter#10884
ScarletKuro merged 14 commits intoMudBlazor:devfrom
boukenka:compact

Conversation

@boukenka
Copy link
Contributor

@boukenka boukenka commented Feb 15, 2025

Description

When many columns need to be displayed in a table, even using the Dense parameter, the table is too wide horizontally. This can be a problem with certain screen sizes. This is why I propose the UltraDense parameter, which makes the display of data in the table even more compact.

The UltraDense parameter takes precedence over the Dense parameter when set to true.

An example has been added in the TablePager Customization section and offers the possibility to compare the usage of Dense and UltraDense parameters.

How Has This Been Tested?

It has been tested visually. With added sorting, fixed header or comparison of the use of the Dense parameter.

UltraDense 1
UltraDense 2
UltraDense 3

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library PR: needs review labels Feb 15, 2025
@codecov
Copy link

codecov bot commented Feb 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.99%. Comparing base (470147a) to head (db63590).
Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #10884      +/-   ##
==========================================
- Coverage   91.01%   90.99%   -0.03%     
==========================================
  Files         429      429              
  Lines       13932    13934       +2     
  Branches     2691     2693       +2     
==========================================
- Hits        12680    12679       -1     
  Misses        649      649              
- Partials      603      606       +3     

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@danielchalmers danielchalmers left a comment

Choose a reason for hiding this comment

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

We shouldn't add a new type of property as our density system is already too disjointed, but we do have a Margin enum for this purpose and I think deprecating Dense and replacing it with that could work. Though it would imply zero padding, not lower (allowing the user to add their own).

@boukenka
Copy link
Contributor Author

boukenka commented Feb 16, 2025

@danielchalmers I've made a few changes. First, I've undone all previous modifications. I added a Density object with a PaddingStep property to the main Theme. I have removed the effect of the Dense parameter in the MudTable. Now padding is managed by the PaddingDensity parameter, which can have four values and apply padding to the table, including the PaddingStep value in the various calculations. Below are two examples. By default, the PaddingParameter is set to Max. It makes no changes to the default table in that case for the display. Please let me know your thoughts.

public class Density
{
    public string PaddingStep { get; set; } = "4px";
}

...

public MudTheme()
{
    Density = new Density();
    PaletteLight = new PaletteLight();
    PaletteDark = new PaletteDark();
    Shadows = new Shadow();
    Typography = new Typography();
    LayoutProperties = new LayoutProperties();
    ZIndex = new ZIndex();
    PseudoCss = new PseudoCss();
}

One
Two

@danielchalmers
Copy link
Member

Thanks for testing that - I think we need a more top-down approach with several components, but it would have to be saved for a major release regardless since it's a breaking change.

I talked to @Garderoben and we think the simplest solution would be to use MudTd.Class to change the padding, or do it directly through CSS on the app side, example: https://try.mudblazor.com/snippet/maQzYQlqKmSiBrqc.

It would mean adding the same class to each cell, so a new property (e.g. CellClass) could be added to make that easier. What do you think?

@boukenka
Copy link
Contributor Author

boukenka commented Feb 16, 2025

I think we need a more top-down approach with several components, but it would have to be saved for a major release regardless since it's a breaking change.

Totally agree with you.

I talked to @Garderoben and we think the simplest solution would be to use MudTd.Class to change the padding, or do it directly through CSS on the app side, example: https://try.mudblazor.com/snippet/maQzYQlqKmSiBrqc.

Thanks for discussing this with @Garderoben and for the snippet!

It would mean adding the same class to each cell, so a new property (e.g. CellClass) could be added to make that easier. What do you think?

Please take a look at https://try.mudblazor.com/snippet/GamfamvrcrAaNSPm. A common class is used to define cells for MudTd and for MudTh based on your previous example. Would your idea be to have something like below replace all Class="mud-table-small-cell" in the example? If so, I think it would avoid a lot of repetition and could be really useful. What about the cells when displaying supplementary information in the MudTr ?

<MudTable CellClass="mud-table-small-cell"...>

@boukenka
Copy link
Contributor Author

boukenka commented Feb 17, 2025

It would mean adding the same class to each cell, so a new property (e.g. CellClass) could be added to make that easier.

I've undone all previous changes. I've added a CellClass parameter at the <MudTable> level. It will be applied to <MudTh> and <MudTd>. Not to <MudTr>. I've also added an example. See below for the two examples. What do you think?

One
Two

PS: I've also modified three unit tests to take into account the changes brought about by this implementation.

@boukenka boukenka changed the title Add UltraDense parameter for MudTable MudTable: Add CellClass parameter Feb 17, 2025
@henon
Copy link
Contributor

henon commented Feb 18, 2025

+1 for CellClass. Look at https://mudblazor.com/components/datagrid#visual-styling for comparison. Although we might not want all the ...Style and ...StyleFunc params which were added before we decided to not add any more Style parameters.

@Garderoben
Copy link
Member

I like it, this is much better!

But lets not forget about DataGrid, i would like to have CellClass in there as well then since its very similar. Or what do you say @henon @danielchalmers

@henon
Copy link
Contributor

henon commented Feb 19, 2025

But lets not forget about DataGrid, i would like to have CellClass in there as well then since its very similar.

DataGrid has it already and in fact has even better styling suppport. I was suggesting the opposite, getting everything that datagrid supports supported in table as well (except the Style variants, we decided not to add any more Style properties and we may even remove them in the future).

@boukenka
Copy link
Contributor Author

On a side note, the CellClass property for the MudDataGrid is defined in the Column component. In this PR, the CellClass is defined at the MudTable level.

The advantage to define the CellClass at the MudTable level is that is applied everywhere. No need to define the same class in other components to apply the same class to the cells inside the MudTable component.

One solution could be to do the following, for consistency :

A - Rename CellClass and CellClassFunc for MudDataGrid component in ColumnClass and ColumnClassFunc. This is a breaking change.
B - Move CellClass (and CellClassFunc ?) for MudDataGrid component at the MudDataGrid level. This is a breaking change as the point A. These properties therefore behave in the same way as this PR.
C - Add RowClass, RowClassFunc, HeaderClass, HeaderClassFunc, FooterClass, FooterClassFunc, ColumnClass and ColumnClassFunc to MudTable component (if this is possible).
D - Add as well CellClassFunc to MudTable component.

What do you think? Or keep this PR as it is? Or another solution ?

@henon
Copy link
Contributor

henon commented Feb 19, 2025

MudGrid is column based and MudTable is not. They have a different design philosophy and so I think we're fine with the different behavior of CellClass. So I would not change MudGrid, meaning I'd not do A and B.

If you want to add C in this PR you are welcome to do so. If you don't have the time then just add CellClassFunc. It should have parameters to identify the row and column of the table so could theoretically have a different style for every cell in the table. I guess the func would also differ from MudGrid because the grid does not need information about the column as a parameter in the func.

@boukenka boukenka marked this pull request as draft February 21, 2025 08:13
@boukenka boukenka changed the title MudTable: Add CellClass parameter MudTable: Add CellClass and CellClassFunc parameters Feb 21, 2025
@boukenka
Copy link
Contributor Author

boukenka commented Feb 21, 2025

Here is an updated version of the PR. I am pretty sure there is a better way to implement the CellClassFunc parameter.

One
Two

PS : I do not know how to fix the last check.

@boukenka boukenka marked this pull request as ready for review February 21, 2025 21:36
@danielchalmers
Copy link
Member

Will leave this to @henon

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 6, 2025

@ScarletKuro ScarletKuro merged commit 95ab46b into MudBlazor:dev Mar 6, 2025
6 checks passed
@boukenka boukenka deleted the compact branch March 8, 2025 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants