Hi I have tried implementing this Incrementing loading option, but it is causing the GetPagedItemsAsync() multiple time at once and causes the list view to load entire items at once.
This is my IncrementalSourceClass
public class CourseIncrementalSource : IIncrementalSource<Course>
{
public CourseIncrementalSource() { }
public async Task<IEnumerable<Course>> GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default)
{
List<Course> items = new List<Course>();
// Establish a connection to the MySQL database
string connectionString = GlobalDatabaseConfiguration.Url;
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
await connection.OpenAsync();
// Create a MySQL command to retrieve the items
MySqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM courses ORDER BY id LIMIT @startIndex, @pageSize";
command.Parameters.AddWithValue("@startIndex", pageIndex * pageSize);
command.Parameters.AddWithValue("@pageSize", pageSize);
// Execute the command and retrieve the data
using (MySqlDataReader reader = (MySqlDataReader)await command.ExecuteReaderAsync())
{
while (await reader.ReadAsync())
{
// Map the data to a MyDataItem object
Course item = new Course();
item.Id = reader.GetInt32(0);
item.Name = reader.GetString("name");
items.Add(item);
}
}
}
return items;
}
}
Does anybody have any idea about it. i searched through internet, but no sample codes seems to be available.