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

feat: add column ids to datagrid #3031

Open
svrooij opened this issue Dec 8, 2024 · 5 comments
Open

feat: add column ids to datagrid #3031

svrooij opened this issue Dec 8, 2024 · 5 comments
Labels
docs:api Additions, improvements, or fixes to API docs docs:example Tutorial and example work needs: author feedback The author of this issue needs to respond in order for us to continue investigating this issue.

Comments

@svrooij
Copy link
Contributor

svrooij commented Dec 8, 2024

🙋 Feature Request

I would the datagrid to not use the title for sorting. The title is a UI element, which might be translated. For sorting it would be useful to have a “stable” thing for the column

🤔 Expected Behavior

If I have a datagrid that is bound to a collection of users, with for instance a property GivenName, the column title might be “Given Name” or “Voornaam” or “nom d'oreille”
When querying the datasource, I need the property name. To specify in the order parameter.

😯 Current Behavior

Currently you get the title which is not stable

💁 Possible Solution

Add a ColumnId to each column which by default is set to the nameof(property) you’re using.

🔦 Context

I’m sending the property name to the server to have the server order the data for me, this does not work well if the column title is not the same as the property name.

In the feature I might also want a list of visible columns so I can generate a select parameter, and have the server only return the columns that are actually visible.

💻 Examples

  • GET /api/users?sort=givenName+desc is what we want not GET /api/users?sort=Voornaam desc
@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Dec 8, 2024
@vnbaaij
Copy link
Collaborator

vnbaaij commented Dec 8, 2024

Did you know that the DataGrid can already generate column headers by using the System.ComponentModel.DataAnnotations.DisplayAttribute on properties shown in the grid.
See https://fluentui-blazor.net/DataGrid#column headers for an example.

@vnbaaij vnbaaij added docs:example Tutorial and example work docs:api Additions, improvements, or fixes to API docs needs: author feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed triage New issue. Needs to be looked at labels Dec 8, 2024
@svrooij
Copy link
Contributor Author

svrooij commented Dec 8, 2024

@vnbaaij i didn’t know that, but that only makes the need for this even stronger.
With the new option that puts the state in the url, you don’t want that translated. You want it to have the property name for sorting not the display name.

@vnbaaij
Copy link
Collaborator

vnbaaij commented Dec 8, 2024

I don't see why that makes the need stronger.

In your API call etc. you can use the name that you have in your data/model for the property (i.e givenName). In the UI you use the [Display(Name = "Voornaam")].
If you need to work with multiple translations in the UI, you can do that with standard C#, ASP.NET Core techniques (like for example https://www.mikesdotnetting.com/article/347/localising-data-annotation-attributes-in-razor-pages). That is not really the libraries concern

@svrooij
Copy link
Contributor Author

svrooij commented Dec 8, 2024

When you're using the GridItemsProvider, you get the title of the sort column (a.k.a. display name).

To send to the server which property should be used for sorting, we would need to resolve the (localized) display name back to the property name.

The GridItemsProviderRequest<Xxx.User> gridRequest gives us the SortByColumn, which is of type ColumnBase. From this we want to construct a orderBy query parameter for the server ?orderBy={propertyName} {ASC/DESC}. But ColumnBase only has Title (which is localizable) and Index which is a number in the column.

@vnbaaij
Copy link
Collaborator

vnbaaij commented Dec 9, 2024

When you're using the GridItemsProvider, you get the title of the sort column (a.k.a. display name).

Do you have a code example of how you are using that? I'm just trying to understand the issue. It seems odd that no one has run into this before. Also thinking how this would work for TemplateColumn? These do not have a Property parameter.

For solving it, you propose we add a property to ColumnBase (which would default to be the same as the title)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs:api Additions, improvements, or fixes to API docs docs:example Tutorial and example work needs: author feedback The author of this issue needs to respond in order for us to continue investigating this issue.
Projects
None yet
Development

No branches or pull requests

2 participants