# .NET MAUI DataGrid LoadOnDemand Collection

To load data on demand by using a collection, feed the `RadDataGrid` with a collection of type `Telerik.Maui.LoadOnDemandCollection`. The `LoadOnDemandCollection` is a generic type, so you need to specify the type of objects it will contain. The type extends the `ObservableCollection<T>` class and expects a `Func<CancellationToken, IEnumerable>` in the constructor.

## Example

The following example demonstrates a sample setup that shows how to use the collection:

1. Define the DataGrid in XAML:

```XAML
<telerik:RadDataGrid x:Name="dataGrid"
                     ItemsSource="{Binding Items}"
                     LoadOnDemandMode="{Binding LoadOnDemandMode}"
                     LoadOnDemandBufferItemsCount="{Binding Source={x:Reference slider}, Path=Value}"/>
```

2. Add the telerik namespace:

```xaml
xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
```

2. Add sample data:

```C#
public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
    public Gender Gender { get; set; }
}
```

3. Declare the `Items` property:

```C#
this.Items = new LoadOnDemandCollection<Person>((cancelationToken) =>
{
    var list = new List<Person>();
    for (int i = 0; i < 10; i++)
    {
        var person = new Person { Name = "LOD Person " + i, Age = i + 18, Gender = i % 2 == 0 ? Gender.Male : Gender.Female };
        list.Add(person);
    }

    return list;
});
```

4. Set data to the `Items` collection:

```C#
this.Items = new LoadOnDemandCollection<Person>((cancelationToken) =>
{
    var list = new List<Person>();
    for (int i = 0; i < 10; i++)
    {
        var person = new Person { Name = "LOD Person " + i, Age = i + 18, Gender = i % 2 == 0 ? Gender.Male : Gender.Female };
        list.Add(person);
    }

    return list;
});
```

> important For DataGrid LoadOnDemandCollection example, refer to the [SDKBrowser Demo application](https://www.telerik.com/maui-ui/documentation/demos-and-sample-apps/sdkbrowser-app) and go to the **DataGrid > LoadOnDemand** category.

## See Also

* [Load On Demand Overview](https://www.telerik.com/maui-ui/documentation/controls/datagrid/load-on-demand/overview)
* [Load On Demand Event](https://www.telerik.com/maui-ui/documentation/controls/datagrid/load-on-demand/event)
* [Load On Demand Command](https://www.telerik.com/maui-ui/documentation/controls/datagrid/load-on-demand/command)
* [Load On Demand Styling](https://www.telerik.com/maui-ui/documentation/controls/datagrid/load-on-demand/styling)
