Skip to content

fix: [ResizableColumns=true In RTL Direction] in FluentDataGrid #2836

Closed

Description

🐛 Bug Report

When Change Direction = RTL And in Data Grid ResizableColumns=true
When Move Mouse Left Or Right To move and change the size of the column, they work in the opposite way

💻 Repro or Code Sample

Company.razor

@page "/Company"
@using AppManager.Common.Resources
@using AppManager.Application.Modules.Company.Dtos
@using AppManager.WebAppV1.Common

@attribute [StreamRendering]

<PageTitle> @AppStringResource.CompanyPageTitle </PageTitle>

<FluentCard MinimalStyle="true" Width="100%" Height="100%">
    <FluentDataGrid TGridItem="CompanyDto" AutoFit="true" 
                    ItemKey="dto => { return dto.Id; }" 
                    ShowHover="true"
                    Data="@_companies"
                    Items="@_companies?.AsQueryable()"
                    Loading="@(_companies == null)"
                    ResizableColumns=true
                    ResizeType="DataGridResizeType.Exact"
                    Pagination="@UiHelper.PaginationState">
        
        <SelectColumn TGridItem="CompanyDto"
                      SelectMode="DataGridSelectMode.Single"
                      SelectFromEntireRow="true"
                      Property="dto => dto.Selected"
                      OnSelect="@(e => e.Item.Selected = e.Selected)"
                      Filtered="true"/>
                      
        <TemplateColumn Tooltip="true" Title="@AppStringResource.LogoTitle" Align="Align.Center" Sortable="false" Filtered="false" Width="50rem">
            <img class="flag" src="@context.Logo" alt="Logo @context.Name" />
        </TemplateColumn>

        <PropertyColumn
            Property="@(p => p.Name)" Sortable="true" Filtered="true"
            IsDefaultSortColumn="true" Align="Align.End" InitialSortDirection="SortDirection.Ascending"/>

        <PropertyColumn Property="@(p => p.EnName)" Sortable="true" Filtered="true"
                        Align="Align.End" InitialSortDirection="SortDirection.Ascending"/>

        <PropertyColumn Property="@(p => p.CodeName)" Sortable="true" Filtered="true"
                        Align="Align.End" InitialSortDirection="SortDirection.Ascending"/>

        <PropertyColumn Property="@(p => p.PhoneNumber)" Sortable="true" Filtered="true"
                        Align="Align.End" InitialSortDirection="SortDirection.Ascending"/>

        <PropertyColumn Property="@(p => p.Fax)" Sortable="true" Filtered="true"
                        Align="Align.End" InitialSortDirection="SortDirection.Ascending"/>

        <PropertyColumn Property="@(p => p.Email)" Sortable="true" Filtered="true"
                        Align="Align.End" InitialSortDirection="SortDirection.Ascending"/>

        <PropertyColumn Property="@(p => p.Address)" Sortable="true" Filtered="true"
                        Align="Align.End" InitialSortDirection="SortDirection.Ascending"/>

        <PropertyColumn Property="@(p => p.Description)" Sortable="true" Filtered="true"
                        Align="Align.End" InitialSortDirection="SortDirection.Ascending"/>

        <TemplateColumn Title="Actions" Align="@Align.End">
            <FluentButton Title="@AppStringResource.Edit" IconEnd="@(new Icons.Regular.Size16.Edit().WithColor(Color.Warning))" />
            <FluentButton  Title="@AppStringResource.Delete" IconEnd="@(new Icons.Regular.Size16.Delete().WithColor(Color.Error))" OnClick="async () => { await OnDeleteAsync(context.Id); }"/>
            
        </TemplateColumn>
    </FluentDataGrid>
</FluentCard>

@  Code {
public List<CompanyDto>? _selectedItems { get; set; }
public IReadOnlyList<CompanyDto>? _companies { get; set; }

[Inject] private ICompanyService _companyService { get; set; }
protected override async Task OnInitializedAsync()
{
    var result = await _companyService.GetAllAsync(CancellationToken.None);
    if (result.IsSuccess)
    {
        _companies = result.Data!;
        await InvokeAsync(StateHasChanged);
    }
    await base.OnInitializedAsync();
}

private async Task OnDeleteAsync(Guid id)
{
    //var res = await _companyService.DeleteAsync(id, CancellationToken.None);
}
}

🤔 Expected Behavior

The direction of mouse movement and the direction of changing the size of the columns should be in the same direction

😯 Current Behavior

Currently, they are not in the same direction and in the opposite direction

💁 Possible Solution

🔦 Context

Get Data From Database And display With Data Grid in RTL Direction

🌍 Your Environment

FluentUi : 4.10.2
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
DotNet 8.0.10 X64
Browser : Chrome Version 130.0.6723.59 (Official Build) (64-bit)
Editor : Visual Studio 2022 v17.10.5 X64

Activity

  1. added
    triage
    on Oct 20, 2024
  2. changed the title [-]fix: [ ResizableColumns=true In RTL Direction] in [Data Grid][/-] [+]fix: [ResizableColumns=true In RTL Direction] in FluentDataGrid[/+] on Oct 20, 2024
  3. added
    bug
    status:in-progress
    and removed
    triage
    on Oct 22, 2024
  4. added a commit that references this issue on Oct 22, 2024
    cc4bb7c
  5. added a commit that references this issue on Oct 22, 2024
    353df98
  6. NabaviFard-Mahdi commented on Oct 28, 2024

    @NabaviFard-Mahdi
    Author

    hi , thanks for new Release.
    i checked and This bug has not been fixed yet and it exists in version 4.10.3

    Image

    @using Microsoft.FluentUI.AspNetCore.Components.DesignTokens
    @inject Direction DirectionDesignToken
    @inherits LayoutComponentBase
    
    <FluentMenuProvider @rendermode="InteractiveServer" /> 
    <FluentLayout>
        <FluentHeader>
            BlazorApp1
        </FluentHeader>
        <FluentStack Class="main" Orientation="Orientation.Horizontal" Width="100%">
            <NavMenu/>
            <FluentBodyContent Class="body-content">
                <div class="content">
                    @Body
                </div>
            </FluentBodyContent>
        </FluentStack>
        <FluentFooter>
            <a href="https://www.fluentui-blazor.net" target="_blank">Documentation and demos</a>
            <FluentSpacer/>
            <a href="https://learn.microsoft.com/en-us/aspnet/core/blazor" target="_blank">About Blazor</a>
        </FluentFooter>
    </FluentLayout>
    
    <div id="blazor-error-ui">
        An unhandled error has occurred.
        <a href="" class="reload">Reload</a>
        <a class="dismiss">🗙</a>
    </div>
    
    @code
    {
        LocalizationDirection Direction { get; set; }
        protected override async Task OnAfterRenderAsync(bool f)
        {
            await base.OnAfterRenderAsync(f);
            if(!f)
                return;
            await DirectionDesignToken.WithDefault("rtl");
            Direction = LocalizationDirection.RightToLeft;
            await InvokeAsync(StateHasChanged);
        }
    
    }
    @page "/"
    @rendermode InteractiveServer
    
    
    
    <p>To test set ResizeType on the DataGrid to either DataGridResizeType.Discrete or DataGridResizeType.Exact</p>
    <p>Remove the parameter completely to get the original behavior</p>
    
    <FluentDataGrid Items="@FilteredItems"
                    ResizableColumns=true
                    ResizeType="DataGridResizeType.Discrete"
                    Pagination="@pagination"
                    GridTemplateColumns="0.2fr 1fr 0.2fr 0.2fr 0.2fr 0.2fr"
                    RowClass="@rowClass"
                    RowStyle="@rowStyle"
                    HeaderCellAsButtonWithMenu="true"
                    Style="height: 405px;overflow:auto;"
                    ColumnResizeLabels=" new ColumnResizeLabels()">
        <PropertyColumn Property="@(c => c.Id)" Sortable="true" Align="Align.Start" Tooltip="true" />
        <PropertyColumn Property="@(c => c.FirstName)" Sortable="true" Align="Align.Start" Tooltip="true" />
        <PropertyColumn Property="@(c => c.LastName)" Sortable="true" Align="Align.Start" Tooltip="true"/>
        <PropertyColumn Property="@(c => c.Age)" Sortable="true" Align="Align.Start" Tooltip="true"/>
    </FluentDataGrid>
    
    
    <FluentPaginator State="@pagination" />
    
    <FluentSwitch @bind-Value="@_clearItems"
                  @bind-Value:after="ToggleItemsAsync"
                  UncheckedMessage="Clear all results"
                  CheckedMessage="Restore all results">
    </FluentSwitch>
    
    @code {
    
        private class Person
        {
            public static List<Person> GenerateFakeData()
            {
                var list = new List<Person>();
                for (var i = 0; i < 100; i++)
                {
                    var person = new Person
                    {
                        Id = i,
                        FirstName = $"FirstName_{i}",
                        LastName = $"FirstName_{i}",
                        Age = new Random().Next(18, 60).ToString(),
                    };
                    list.Add(person);
                }
    
                return list;
            }
    
            public int Id { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string Age { get; set; }
        }
    
        bool _clearItems = false;
        IQueryable<Person>? items;
        PaginationState pagination = new PaginationState { ItemsPerPage = 10 };
        string nameFilter = string.Empty;
        int minMedals;
        int maxMedals = 130;
    
        ColumnResizeLabels customLabels = ColumnResizeLabels.Default with { DiscreteLabel = "Width (+/- 10px)", ResetAriaLabel = "Restore" };
    
        Func<Person, string?> rowClass = x => x.Id % 2 == 0 ? "highlighted-row" : null;
        Func<Person, string?> rowStyle = x => x.Id % 2 != 0 ? "background-color: var(--highlight-bg)" : null;
    
        //IQueryable<Country>? FilteredItems => items?.Where(x => x.Name.Contains(nameFilter, StringComparison.CurrentCultureIgnoreCase));
    
        IQueryable<Person>? FilteredItems
        {
            get
            {
                var result = items?.Where(x=>true).AsParallel();
    
                if (result is not null && !string.IsNullOrEmpty(nameFilter))
                {
                    result = result.Where(c => c.FirstName.Contains(nameFilter, StringComparison.CurrentCultureIgnoreCase));
                }
    
                return result.AsQueryable();
            }
        }
    
        protected override async Task OnInitializedAsync()
        {
            items = Person.GenerateFakeData().AsQueryable();
        }
    
        private void HandleCountryFilter(ChangeEventArgs args)
        {
            if (args.Value is string value)
            {
                nameFilter = value;
            }
        }
    
        private void HandleClear()
        {
            if (string.IsNullOrWhiteSpace(nameFilter))
            {
                nameFilter = string.Empty;
            }
        }
    
        private async Task ToggleItemsAsync()
        {
            if (_clearItems)
            {
                items = null;
            }
            else
            {
                items = Person.GenerateFakeData().AsQueryable();
            }
        }
    }
    
  7. vnbaaij commented on Oct 28, 2024

    @vnbaaij
    Collaborator

    You are probably walking int a script being cached too aggressively. Try forcing a hard refresh.

    This is what I am seeing on the live demo site:
    Image

  8. NabaviFard-Mahdi commented on Oct 28, 2024

    @NabaviFard-Mahdi
    Author

    yes demo site script being cached too aggressively. i refreshed With Ctrl+F5
    but in my project it not fix. i think package Microsoft.FluentUI.AspNetCore.Components.Icons depeendecies on v4.10.2 and when installing [Microsoft.FluentUI.AspNetCore.Components v4.10.3] and then installing [Microsoft.FluentUI.AspNetCore.Components.Icons v4.10.3] it downgrade package Microsoft.FluentUI.AspNetCore.Components to v4.10.2

    Image

  9. vnbaaij commented on Oct 28, 2024

    @vnbaaij
    Collaborator

    But you can update to core package 4.10.3 again after that, right?

  10. NabaviFard-Mahdi commented on Oct 28, 2024

    @NabaviFard-Mahdi
    Author

    I first install Microsoft.FluentUI.AspNetCore.Components v4.10.3
    Then install Microsoft.FluentUI.AspNetCore.Components.Icons v4.10.3, but Microsoft.FluentUI.AspNetCore.Components.Icons 4.10.3 need Microsoft.FluentUI.AspNetCore.Components v4.10.2.

    Microsoft.FluentUI.AspNetCore.Components.Icons depend on
    Microsoft.FluentUI.AspNetCore.Components v4.10.2 not v4.10.3

    Maybe I'm wrong and this is not relevant to this issues

  11. vnbaaij commented on Oct 28, 2024

    @vnbaaij
    Collaborator

    It is definitely not relevant to this issue.

    In the Icons package I see:
    Image

    So 4.10.2 or later. No idea why it should downgrade the core page

  12. NabaviFard-Mahdi commented on Oct 29, 2024

    @NabaviFard-Mahdi
    Author

    I checked again and this time I first installed the Icons package version 4.10.3 and then the Core package version 4.10.3.
    Again, there was the problem of changing the size of the columns
    Steps:

    1. Clear Obj Folder
    2. Clear Bin Folder
    3. Install Core Package v4.10.3
    4. Install Icons Package v4.10.3
    5. Check Version Of Packages Core And Icons (Both 4.10.3 )
    6. Rebuild Solution
    7. Run
    8. Check Js Scripts Of (FluentDivider.razor.js , FluentDataGrid.razor.js )

    Image
    Image

    Test Video : https://files.fm/u/rzarkf3jxj

  13. vnbaaij commented on Oct 29, 2024

    @vnbaaij
    Collaborator

    I checked again and this time I first installed the Icons package version 4.10.3 and then the Core package version 4.10.3.

    Again, this has nothing to do with the issue. Please don't mix issues

    Again, there was the problem of changing the size of the columns
    Steps:

    1. Clear Obj Folder
    2. Clear Bin Folder
    3. Install Core Package v4.10.3
    4. Install Icons Package v4.10.3
    5. Check Version Of Packages Core And Icons (Both 4.10.3 )
    6. Rebuild Solution
    7. Run
    8. Check Js Scripts Of (FluentDivider.razor.js , FluentDataGrid.razor.js )

    A local script file being cached has nothing to do with obj/bin folder. You can referee to the demo site to see that it is working as it should. If you are seeing different result, check your code please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugstatus:in-progress

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions