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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid: add access to columns #2148

Closed
ksbecker opened this issue Jun 4, 2024 · 2 comments
Closed

DataGrid: add access to columns #2148

ksbecker opened this issue Jun 4, 2024 · 2 comments
Labels
community:contribution Issue will/can be addressed by community contribution

Comments

@ksbecker
Copy link
Contributor

ksbecker commented Jun 4, 2024

馃檵 Feature Request

Give developers access to the collection of columns in a DataGrid.

馃 Expected Behavior

In order to programmatically set the sort, remove sort, or show column options, you need to pass in a ColumnBase<TGridItem> into one of the methods, RemoveSortByColumnAsync, ShowColumnOptionsAsync, and SortByColumnAsync. As far as I can tell, there is no way to get a reference to the columns.

馃槸 Current Behavior

Currently there is way to access this collection.

馃拋 Possible Solution

There is a private field that contains a list of ColumnBase<TGridItem> that could be exposed through a getter property.

馃敠 Context

What I'm trying to accomplish is to store the state of the DataGrid and restore it when navigating back to the page. I have filters and paging working, now I need to be able to restore the previous sort order. I can accomplish this by storing an index/unique id of the column that was sorted and then applying the SortByColumnAsync method.

馃捇 Examples

I think this is fairly straight-forward. Basically add a new property in fluentui-blazor/src/Core/Components/DataGrid/FluentDataGrid.razor.cs

public List<ColumnBase<TGridItem>> Columns { get => _columns; }

Alternatively, methods could be created to give access to these columns, GetColumnByTitle or GetColumnByIndex

@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Jun 4, 2024
@vnbaaij
Copy link
Collaborator

vnbaaij commented Jun 4, 2024

By exposing a getter, you would have read only access to the collection of columns. But then nothing would stop you from manipulating the individuial columns from that collection, right?

I see more value in providing the other type of methods you mention.

As we only have limited time for working on this, care to work on a PR?

@vnbaaij vnbaaij added community:contribution Issue will/can be addressed by community contribution and removed triage New issue. Needs to be looked at labels Jun 4, 2024
@vnbaaij
Copy link
Collaborator

vnbaaij commented Jun 6, 2024

Closing this as the PR is merged

@vnbaaij vnbaaij closed this as completed Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community:contribution Issue will/can be addressed by community contribution
Projects
None yet
Development

No branches or pull requests

2 participants