﻿# DataGrid: Density

See how to set a compact density mode of Blazor RadzenDataGrid.

Keywords: density, compact, small, large, tight

> API reference: [RadzenDataGrid API](https://blazor.radzen.com/docs/api/Radzen.Blazor.RadzenDataGrid-1.md)

## Examples

## Blazor DataGrid Density

Switch a Blazor DataGrid to compact density - fit more rows on screen with tighter spacing, or use the default comfortable layout.

```razor
@inherits DbContextPage

<RadzenCard Variant="Variant.Outlined" class="rz-my-4">
    <RadzenStack Orientation="Orientation.Horizontal" Gap="0.5rem" AlignItems="AlignItems.Center" Wrap="FlexWrap.Wrap">
        <div>Density:</div>
        <RadzenSelectBar @bind-Value="@Density" TextProperty="Text" ValueProperty="Value"
                         Data="@(Enum.GetValues(typeof(Density)).Cast<Density>().Select(t => new { Text = $"{t}", Value = t }))" Size="ButtonSize.Small" />
    </RadzenStack>
</RadzenCard>

<RadzenDataGrid Data="@orderDetails" Density="@Density" AllowPaging="true" AllowSorting="true">
    <Columns>
        <RadzenDataGridColumn Property="OrderID" Title="OrderID" />
        <RadzenDataGridColumn Property="ProductID" Title="ProductID" />
        <RadzenDataGridColumn Property="@nameof(OrderDetail.UnitPrice)" Title="Unit Price">
            <Template Context="detail">
                @String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", detail.UnitPrice)
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn Property="@nameof(OrderDetail.Quantity)" Title="Quantity" />
        <RadzenDataGridColumn Property="@nameof(OrderDetail.Discount)" Title="Discount">
            <Template Context="detail">
                @String.Format("{0}%", detail.Discount * 100)
            </Template>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

@code {
    Density Density = Density.Default;

    IEnumerable<OrderDetail> orderDetails;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        orderDetails = dbContext.OrderDetails;
    }
}
```
