How to perform a pivot grid in maui?

Kaouthar GR AOUICHAOUI 60 Reputation points
2024-05-03T16:24:46.6+00:00

Hi, i want to display data from observablecollection in a pivotgrid using .Net Maui 8 like in the picture below.pivotgrid

the columns are generated programatically. i write this code in the viewmodel:

Stockstcviews = JsonConvert.DeserializeObject<ObservableCollection<stockstcviews>>(response.Content.ToString());

if (Stockstcviews.Count != 0)

{

 await displaystockbysite(Stockstcviews);

Device.BeginInvokeOnMainThread(() =>

{

    OnPropertyChanged(nameof(Stockstcviews));

    DataGrid.ItemsSource = Stockstcviews; // Set the ItemsSource of DataGrid

}); 

}

and in my function private async Task displaystockbysite(ObservableCollection<stockstcviews> Stockstcviews)

{

try

{

     // Accéder à la DataGrid à partir du ViewModel

    var dataGrid = this.DataGrid;

    if (Stockstcviews.Count > 0)

    {

        var distinctsite = Stockstcviews.Select(x => new { x.siteordree, x.siteid, x.siteabrege }).Distinct();

        var distinctcouleurid = Stockstcviews.OrderBy(x => x.ordree).Select(x => x.couleurid).Distinct().ToList();

        var distinctcouleur = Stockstcviews.OrderBy(x => x.ordree).Where(x => distinctcouleurid.Contains(x.couleurid)).Select(x => new { x.couleurid, x.couleurlibelle, x.couleurcode, x.ordree }).Distinct().ToList();

        // Stockstcviews is an ObservableCollection 

        foreach (var det in distinctsite.OrderBy(x => x.siteordree))

        {

            var column = new DataGridTextColumn

            {

                

                AllowEditing = false,

                CellPadding = new Thickness(10, 0, 0, 0),

                HeaderPadding = new Thickness(10, 0, 0, 0),

                HeaderText = det.siteabrege,

                HeaderTextAlignment = TextAlignment.Center,

                MappingName = det.siteabrege,

                MinimumWidth = 100

            };

            dataGrid.Columns.Add(column);

        }

        // Populate rows with data

        dataGrid.ItemsSource = Stockstcviews;

}

How to performe that please?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,959 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,348 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 36,706 Reputation points Microsoft Vendor
    2024-05-08T02:09:20.6766667+00:00

    Hello,

    Microsoft Q&A does not currently support issues related to the use of third-party plug-ins.

    For DataGrid, you can refer to the sample code and videos provided by syncfusion to learn how to use it in MAUI.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful