Code Monkey home page Code Monkey logo

Comments (6)

vnbaaij avatar vnbaaij commented on May 27, 2024

Please supply us with reproduction code in the form of a project or repository.

We do not have capacity to craft or compose a reproduction for every issue that gets raised.

If no code or repository is provided, this issue will get closed automatically in 3 days

Help us to help you. Thanks

from fluentui-blazor.

sardar97 avatar sardar97 commented on May 27, 2024

`@page "/customer"
@rendermode @(new InteractiveAutoRenderMode(prerender:false))
@using System.Diagnostics
@Inject HttpClient _Http
@Inject NavigationManager _NavigationManager

<h1>@_ErorMsg</h1>

<FluentCard Width="100%" >
    <h3>Customer</h3>
    <FluentDataGrid ItemsProvider="@_customerProvider" ResizableColumns="false" 
                     Style="width: 100%" Loading="true" Pagination="@_pagination">
        <PropertyColumn Property="@(p=>p.name)" Sortable="true"
                        Filtered="!string.IsNullOrWhiteSpace(nameFilter)" Tooltip="true" Title="Name">
            <ColumnOptions >
                <div class="search-box">
                    <FluentSearch type="search" Autofocus=true @bind-Value="nameFilter"
                                  @oninput="HandleCountryFilter" @bind-Value:after="HandleClear" Placeholder="Name"/>
                </div>
            </ColumnOptions>
        </PropertyColumn>
        <PropertyColumn Property="@(c => c.phone)" Sortable="true" Class="multiline-text"/>
        <PropertyColumn Property="@(c => c.address)" Sortable="true" Class="multiline-text"/>

    </FluentDataGrid>

    <FluentPaginator  State="@_pagination"   >
        <SummaryTemplate >
            Total rows :  <strong>@((_pagination.TotalItemCount ?? 0).ToString("N0"))</strong>
            <p>Time to load : @_loadingTime</p>
        </SummaryTemplate>

        <PaginationTextTemplate>
            <strong>@((_pagination.CurrentPageIndex + 1).ToString("N0"))</strong> of <strong>@((_pagination.LastPageIndex + 1).Value.ToString("N0"))</strong>
        </PaginationTextTemplate>
    </FluentPaginator>

</FluentCard>

`

`@code {

PaginationState _pagination = new PaginationState { ItemsPerPage = 10 };
string? nameFilter = null; 
private string _loadingTime { get; set; }
private string _ErorMsg { get; set; } 

GridItemsProvider<Shared.Models.Customer>? _customerProvider;

 

 protected override async Task OnInitializedAsync()
{         
   await LoadData(); 
}

private async Task LoadData()
{
    _customerProvider = async req =>
    {
        
        Stopwatch _stopwatch =Stopwatch.StartNew();
        // Construct the URL with query parameters
        bool? sortingByAscending = req.SortByAscending!;
        string? column = string.Empty;
        if (req.SortByColumn is not null)
        {
            column = req.SortByColumn!.Title;
        }
        string apiUrl = $"{_NavigationManager.BaseUri}api/Customer";
        string queryParameters = 
            $"?skip={req.StartIndex}&take={req.Count}&sortingByAscending={sortingByAscending}&column={column.ToLower()}";
        Console.WriteLine("sardar url : "+queryParameters);
        if (!string.IsNullOrEmpty(nameFilter))
        {
            queryParameters += $"&where={Uri.EscapeDataString(nameFilter)}";
        }
        string fullUrl = apiUrl + queryParameters; 
        var response = await  _Http.GetFromJsonAsync<PaginationDTO.MyPaginationDTO>( fullUrl);
        _stopwatch.Stop();
        TimeSpan loadingTime2 = _stopwatch.Elapsed;
        _loadingTime = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
            loadingTime2.Hours, loadingTime2.Minutes, loadingTime2.Seconds, loadingTime2.Milliseconds);
        // Check if response is successful and contains data 
        if (response != null && response.customers != null)
        {
            if (response.customers.Count <= 0)
            {
                return GridItemsProviderResult.From(Array.Empty<Shared.Models.Customer>(), 0);
            }
            else
            {
                return GridItemsProviderResult.From(items: response.customers, totalItemCount: response.totalCount);
            }
        }
        else
        { 
            return GridItemsProviderResult.From(Array.Empty<Shared.Models.Customer>(), 0);
        }
     
    };
    
}

private async Task HandleCountryFilter(ChangeEventArgs args)
{
    if (args.Value is string value)
    {
        nameFilter = value;
    }

   await LoadData();
}

private async Task HandleClear()
{
    if (string.IsNullOrWhiteSpace(nameFilter))
    {
        nameFilter = string.Empty;
        await LoadData();
    } 
}

}`

from fluentui-blazor.

vnbaaij avatar vnbaaij commented on May 27, 2024

Hi Sadar,

Can't run this code. Don't have Shared.Models.Customer and this is also not working:

 var response = await  _Http.GetFromJsonAsync<PaginationDTO.MyPaginationDTO>( fullUrl);

But looking at your original issue, I think it is not a really good idea to use Virtualization and Pagination together. Think you can better do an 'on-demand' loading per page requested with Pagination.
See the DataGrid Custom Paging example on how you can create your own buttons and hook into the handlers.

from fluentui-blazor.

sardar97 avatar sardar97 commented on May 27, 2024

no if you look at my code for every new page I request a new http request for the API and it works fine but when I have 1M Record and sorting it take 700ms for each page. So for better user experience I want virtualize it or showing a nice loading at top of the DataGrid. if you look at this MudBlazor example you will understand what I mean.
MudBlazor Example

from fluentui-blazor.

vnbaaij avatar vnbaaij commented on May 27, 2024

That MudBlazor example has nothing to do with Virtualize. It determines which records to show on a page by doing:

pagedData = data.Skip(state.Page * state.PageSize).Take(state.PageSize).ToArray();

So returning just the exact rows that should be shown on a page. I don't think this is a component issue but more a general paging/sorting of a large data set problem.

from fluentui-blazor.

vnbaaij avatar vnbaaij commented on May 27, 2024

Closing due to no repro code provided

from fluentui-blazor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.