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

[QuickGrid] Set column title by using DataAnnotations.DisplayAttribute #47155

Open
vnbaaij opened this issue Mar 11, 2023 · 6 comments
Open

[QuickGrid] Set column title by using DataAnnotations.DisplayAttribute #47155

vnbaaij opened this issue Mar 11, 2023 · 6 comments
Labels
area-blazor Includes: Blazor, Razor Components design-proposal This issue represents a design proposal for a different issue, linked in the description enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-quickgrid
Milestone

Comments

@vnbaaij
Copy link

vnbaaij commented Mar 11, 2023

Summary

In the Microsoft.Fast.Components.FluentUI package I'm using a QuickGrid copy that is extended to define a column title by using the System.ComponentModel.DataAnnotations.DisplayAttribute on the property you want to display in a column (instead of specifying a Title parameter on the TemplateColumn or PropertyColumn)

Motivation and goals

  • Attribute can load data from a resource file which makes localization easier
  • Potentially this can later also be used for auto generating columns by leveraging the Order (and other) properties

In scope

  • Add the necessary code to enable this

Out of scope

  • Auto generating colums

Risks / unknowns

Risk is low as the original Title parameter is kept in place. This just offers an alternative way of setting a column's title. Need to document what option gets precedence over the other

Examples

For example code and implementation see the Razor tab at https://brave-cliff-0c0c93310.azurestaticapps.net/DataGrid#column-headers

Alternative approach

We could also use DisplayName attribute (from System.ComponentModel) to be able to specify a title on a property but we would lose the option to read from a resource file with that. Also, this approach would not help with a possible auto generation scenario later (no Order or other properties).

@vnbaaij vnbaaij added the design-proposal This issue represents a design proposal for a different issue, linked in the description label Mar 11, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added area-identity Includes: Identity and providers untriaged labels Mar 11, 2023
@vnbaaij vnbaaij changed the title Extend QuickGrid to set column title by using DataAnnotations.DisplayAttribute [Blazor] Extend QuickGrid to set column title by using DataAnnotations.DisplayAttribute Mar 11, 2023
@vnbaaij vnbaaij changed the title [Blazor] Extend QuickGrid to set column title by using DataAnnotations.DisplayAttribute [QuickGrid] Set column title by using DataAnnotations.DisplayAttribute Mar 12, 2023
@vnbaaij
Copy link
Author

vnbaaij commented Mar 14, 2023

@mkArtakMSFT this is incorrectly labeled as 'area-identity'. Can you re-label as 'area-blazor'? And add label 'feature-blazor-quickgrid'. Thanks!

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components and removed area-identity Includes: Identity and providers labels Mar 29, 2023
@mkArtakMSFT
Copy link
Member

@vnbaaij it's not clear what the specific ask is.
Do you want the DataAnnotations attributes to support localization so that the title changes based on the culture of the application?

@mkArtakMSFT mkArtakMSFT added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Mar 29, 2023
@ghost
Copy link

ghost commented Mar 29, 2023

Hi @vnbaaij. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@vnbaaij
Copy link
Author

vnbaaij commented Mar 29, 2023

Hi Artak,

I'm proposing an extra/alternative way to specify a Title for a column by leveraging the DataAnnotations attribute on the source of the column data. In the implementation I have in my QuickGrid copy it looks like this:

@using System.ComponentModel.DataAnnotations
<FluentDataGrid RowsData="@people">
    <PropertyColumn Property="@(p => p.PersonId)" Sortable="true" />
    <PropertyColumn Property="@(p => p.Name)" Sortable="true" />
    <PropertyColumn Property="@(p => p.BirthDate)" Format="yyyy-MM-dd" Sortable="true" />
</FluentDataGrid>

@code {
    public class Person
    {
        public Person(int personId, string name, DateOnly birthDate)
        {
            PersonId = personId;
            Name = name;
            BirthDate = birthDate;
        }

        [Display(Name="Identity")]
        public int PersonId { get; set; }

        [Display(Name = "Full name")]
        public string Name { get; set; }

        [Display(Name = "Birth date")]
        public DateOnly BirthDate { get; set; }
    }

    IQueryable<Person> people = new[]
    {
        new Person(10895, "Jean Martin", new DateOnly(1985, 3, 16)),
        new Person(10944, "António Langa", new DateOnly(1991, 12, 1)),
        new Person(11203, "Julie Smith", new DateOnly(1958, 10, 10)),
        new Person(11205, "Nur Sari", new DateOnly(1922, 4, 27)),
        new Person(11898, "Jose Hernandez", new DateOnly(2011, 5, 3)),
        new Person(12130, "Kenji Sato", new DateOnly(2004, 1, 9)),
    }.AsQueryable();
}

In contrast to the regular implementation where it looks like this:

<FluentDataGrid RowsData="@people">
    <PropertyColumn Title="Identity" Property="@(p => p.PersonId)" Sortable="true" />
    <PropertyColumn Title="Full name" Property="@(p => p.Name)" Sortable="true" />
    <PropertyColumn Title="Birthdate" Property="@(p => p.BirthDate)" Format="yyyy-MM-dd" Sortable="true" />
</FluentDataGrid>

@code {
    record Person(int PersonId, string Name, DateOnly BirthDate);

    IQueryable<Person> people = new[]
    {
        new Person(10895, "Jean Martin", new DateOnly(1985, 3, 16)),
        new Person(10944, "António Langa", new DateOnly(1991, 12, 1)),
        new Person(11203, "Julie Smith", new DateOnly(1958, 10, 10)),
        new Person(11205, "Nur Sari", new DateOnly(1922, 4, 27)),
        new Person(11898, "Jose Hernandez", new DateOnly(2011, 5, 3)),
        new Person(12130, "Kenji Sato", new DateOnly(2004, 1, 9)),
    }.AsQueryable();
}

By using the DataAnnotations, it would be possible for a developer to localize the grid for different cultures.

I'm not proposing to change the current implementation but to augment it with the described behavior. If we agree on this being a good addition, I could provide a PR for it.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Mar 29, 2023
@mkArtakMSFT mkArtakMSFT added enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Mar 30, 2023
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Mar 30, 2023
@ghost
Copy link

ghost commented Mar 30, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@Eleve2023
Copy link

Hello everyone, I just wanted to let you know that I have submitted a pull request for the feature we discussed here. Here is the link: #47993. I would appreciate your feedback and suggestions. Thank you!

@mkArtakMSFT mkArtakMSFT modified the milestones: Backlog, BlazorPlanning Nov 5, 2023
@mkArtakMSFT mkArtakMSFT modified the milestones: Planning: WebUI, Backlog Nov 19, 2023
@dotnet dotnet deleted a comment Nov 19, 2023
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components design-proposal This issue represents a design proposal for a different issue, linked in the description enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-quickgrid
Projects
None yet
Development

No branches or pull requests

5 participants
@vnbaaij @wtgodbe @mkArtakMSFT @Eleve2023 and others