Preloading Data

With preloading turned on, the initial ajax call is not needed and the data will be loaded when the page loads. Subsequent calls are done with ajax.

Preloading is on by default. Below is an example of a grid with preloading turned off. If you refresh the page, you should see that an initial ajax call is made to load the table for the first time.


Inside MVCGridConfig.cs
MVCGridDefinitionTable.Add("Preloading", new MVCGridBuilder<Person>(colDefauls)
    .AddColumns(cols =>
            .WithValueExpression(p => p.Id.ToString());
        cols.Add("FirstName").WithHeaderText("First Name")
            .WithValueExpression(p => p.FirstName);
        cols.Add("LastName").WithHeaderText("Last Name")
            .WithValueExpression(p => p.LastName);
    .WithSorting(true, "LastName")
    .WithPaging(true, 10)
    .WithRetrieveDataMethod((context) =>
        var options = context.QueryOptions;
        int totalRecords;
        var repo = DependencyResolver.Current.GetService<IPersonRepository>();
        var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
            options.GetSortColumnData<string>(), options.SortDirection == SortDirection.Dsc);
        return new QueryResult<Person>()
            Items = items,
            TotalRecords = totalRecords