We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

datagrid server side paging and sorting

am trying to follow this tutorial https://docs.abp.io/en/abp/latest/Tutorials/Part-9?UI=Blazor&DB=EF , but just with  SfGrid, i am looking for some guidance  on how to convert :


private async Task GetAuthorsAsync()

{

    var result = await AuthorAppService.GetListAsync(

        new GetAuthorListDto

        {

            MaxResultCount = PageSize,

            SkipCount = CurrentPage * PageSize,

            Sorting = CurrentSorting

        }

    );


    AuthorList = result.Items;

    TotalCount = (int)result.TotalCount;

}


private async Task OnDataGridReadAsync(DataGridReadDataEventArgs<AuthorDto> e)

{

    CurrentSorting = e.Columns

        .Where(c => c.SortDirection != SortDirection.Default)

        .Select(c => c.Field + (c.SortDirection == SortDirection.Descending ? " DESC" : ""))

        .JoinAsString(",");

    CurrentPage = e.Page - 1;


    await GetAuthorsAsync();


    await InvokeAsync(StateHasChanged);

}


to work with SfGrid, the thing a got so far is using ActionBeginHandler but then i need a way to set the grid totalcount.


1 Reply

PS Prathap Senthil Syncfusion Team December 16, 2022 12:56 PM UTC

Hi Mohammed

Greeting from Syncfusion support,

Query:” I need a way to set the grid total count

Based on your query, we suggest that you use the count method from the grid instance to get the total count from the datasource. 

Please see the attached code snippet for reference.


<SfGrid DataSource="@OrderData.GetAllOrders()"TValue="Order"ID="Grid"

        @ref="Grid"

        Toolbar="@ToolbarItems"

        AllowSorting="true"

        AllowFiltering="true"

AllowPaging="true">

     <GridPageSettings PageSize="10"></GridPageSettings>

    <GridEditSettings AllowAdding="true"

                      AllowDeleting="true"

                      AllowEditing="true">

    </GridEditSettings>

 

   <GridColumns>

        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID"  IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120">           

        </GridColumn>

        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>

    </GridColumns>

</SfGrid>
@code{

  SfGrid<Order> Grid;

 

  var count = Grid.DataSource.Count();

}


Please get back to us for further details.



Regards,
Prathap S


Loader.
Live Chat Icon For mobile
Up arrow icon