The requested page is not available for the requested platform. You are viewing the content for Default platform.

Step 1: Fetch Data and Enable Scrolling

  • 2 min to read

In this step, you create a virtual source, fetch rows from the service, and enable scrolling in the GridControl.

To Fetch Data and Enable Scrolling

  1. Add a GridControl with columns that correspond to the Issues Service's IssueData to your project:

        <Grid:GridControl Name="grid" AutoGenerateColumns="False" AllowSorting="False" AllowColumnFiltering="False">
            <Grid:GridControl.Columns>
                <Grid:GridTextColumn FieldName="Subject" />
                <Grid:GridTextColumn FieldName="User" />
                <Grid:GridDateColumn FieldName="Created" />
                <Grid:GridTextColumn FieldName="Votes"  />
                <Grid:GridTextColumn FieldName="Priority" />
            </Grid:GridControl.Columns>
        </Grid:GridControl>
    
  2. Initialize a virtual source. Create an InfiniteAsyncSource instance and set the VirtualSourceBase.ElementType property to the type of rows retrieved from the source.

        public MainPage() {
            this.InitializeComponent();
            var source = new InfiniteAsyncSource() {
                ElementType = typeof(IssueData)
            };
        }
    
Tip

If your service returns untyped objects (for example, a service returns Json which is converted to a dynamic object), specify the VirtualSourceBase.CustomProperties property.

  1. Fetch rows from the data source:

    public MainPage() {
        // ... 
        source.FetchRows += (o, e) => {
            e.Result = FetchRowsAsync(e);
        };
    }
    static async Task<FetchRowsResult> FetchRowsAsync(FetchRowsAsyncEventArgs e) {
        IssueSortOrder sortOrder = GetIssueSortOrder(e);
        IssueFilter filter = MakeIssueFilter(e.Filter);
        const int pageSize = 30;
        var issues = await IssuesService.GetIssuesAsync(
            page: e.Skip / pageSize,
            pageSize: pageSize,
            sortOrder: sortOrder,
            filter: filter);
        return new FetchRowsResult(issues, hasMoreRows: issues.Length == pageSize);
    }
    static IssueSortOrder GetIssueSortOrder(FetchRowsAsyncEventArgs e) {
        return IssueSortOrder.Default;
    }
    static IssueFilter MakeIssueFilter(CriteriaOperator filter) {
        return null;
    }
    
  2. Bind the GridControl to the virtual source by assigning the resulting virtual source's instance to the DataControlBase.ItemsSource property:

    public MainPage() {
        // ... 
        grid.ItemsSource = source;
    }