Skip to content

SyncfusionExamples/create-a-custom-data-grid-column-in-maui-datagrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Create a Custom DataGridColumn in MAUI DataGrid

In.NET MAUI DataGrid (SfDataGrid) allows you to create custom DataGridColumn by following the below steps.

Step 1 - To create a custom column, you must inherit from the DataGridColumn class and specify the DataGridColumn.CellType property.

Step 2 - A Custom CellRenderer cclass must be created for the custom column by customizing the DataGridCellRenderer<D, E>.

Step 3 - In the created cell renderer class, you should override the following methods. OnCreateDisplayUIView() – Generate the data to be placed in the grid cell. OnInitializeDisplayView() – To set up the cell content loaded in the grid cell with the necessary settings.

Step 4 - You must add the custom column to the SfDataGrid.Columns collection and its renderer to SfDataGrid.CellRenderers collection.

For example, refer the below example in which a custom column is created for loading a Stepper control in the grid columns. A custom renderer class is written to load Stepper control as display.

XAML

<syncfusion:SfDataGrid x:Name="dataGrid"  
                           ItemsSource="{Binding Employees}"       
                           ColumnWidthMode="Auto"
                           AutoGenerateColumnsMode="None">
        <syncfusion:SfDataGrid.Columns>
            <local:StepperColumn MappingName="OrderID"/>
        </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

C#

Creating Stepper Column

public class StepperColumn : DataGridColumn
{
    public StepperColumn()
    {
        var cellType = typeof(DataGridColumn).GetRuntimeProperties().FirstOrDefault((property) => property.Name == "CellType");
        cellType.SetValue(this, "Stepper");
    }
}

Custom cell renderer for StepperColumn

public class StepperColumnRenderer : DataGridCellRenderer<Stepper, Stepper>
{
    public StepperColumnRenderer()
    {
    }

    protected override Stepper OnCreateDisplayUIView()
    {
        return new Stepper();
    }
}

MainPage

public partial class MainPage : ContentPage
{
    
    public MainPage()
    {
        InitializeComponent();
        dataGrid.CellRenderers.Add("Stepper", new StepperColumnRenderer());
    }	
}

How to create a Custom DataGridColumn

Conclusion

I hope you enjoyed learning about how to create custom DataGridColumn in MAUI DataGrid (SfDataGrid).

You can refer to our .NET MAUI DataGrid’s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components. If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac or feedback portal. We are always happy to assist you!

About

create a custom data grid column in maui datagrid

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages