Add a load more button

Instead of adding 200 pictures from a json how can i add a Load more button in my listview?
Thanks for help

Attachment: listview_53475c44.zip

6 Replies 1 reply marked as answer

SS SaiGanesh Sakthivel Syncfusion Team August 24, 2020 05:25 AM UTC

Hi Mihaela,  
  
Thank you for contacting syncfusion support.  
  
We have checked the reported query “Add a load more button” from our end. we would like to inform you that we have documented ‘How to add a load more button in listview’ in our user guidance document. Please refer to the following UG Documentation for your reference.  
  
  
We hope this helps. Please let us know if you need any further assistance.  
  
Regards,  
SaiGanesh Sakthivel  


Marked as answer

MP Mihaela purav August 24, 2020 04:05 PM UTC

Thanks.
In your populateData exemple from ui kit is it possible to specify a number  and add a load more button after?
Best regards


SS SaiGanesh Sakthivel Syncfusion Team August 25, 2020 11:06 AM UTC

Hi Mihaela,  
  
Thank you for the update.  
  
We have checked the reported query “Add a load more button” from our end. we would like to inform you that you can add the load more button after specific number in the listview. Please refer to the following code snippet for your reference.  
  
public LoadMoreViewModel()  
 
    Products = new ObservableCollection<Product>();  
    AddProducts(0, 13);  
    LoadMoreItemsCommand = new Command<object>(LoadMoreItems, CanLoadMoreItems);  
 
…  
…  
…  
…  
private void AddProducts(int index, int count)  
 
    for (int i = index; i < index + count; i++)  
    {  
        var name = Names[i];  
        var p = new Product()  
        {  
            Name = name,  
            Weight = Weights[i],  
            Price = Prices[i],  
            Image = ImageSource.FromResource("SfListViewSample.LoadMore." + name.Replace(" ", string.Empty) + ".jpg" 
        };  
  
        Products.Add(p);  
    }  
 
  
Please refer to the following demo sample for your reference.  
  
We hope this helps.  
 
Regards,  
SaiGanesh Sakthivel  



MP Mihaela purav August 25, 2020 03:33 PM UTC

we can't add method in this fuction?


private static T PopulateData<T>(string fileName)
        {
            var file = "app9.Data." + fileName;

            var assembly = typeof(App).GetTypeInfo().Assembly;

            T obj;

            using (var stream = assembly.GetManifestResourceStream(file))
            {
                var serializer = new DataContractJsonSerializer(typeof(T));
                obj = (T)serializer.ReadObject(stream);
            }

            return obj;
        }


SS SaiGanesh Sakthivel Syncfusion Team August 27, 2020 03:39 AM UTC

Hi Mihaela, 
 
Thank you for the update. 
 
We have checked the reported issue “Add a load more button” from our end. We are currently working on it and update you further details on August 28, 2020. We appreciate your patience until then. 
 
Regards, 
SaiGanesh Sakthivel 



SS SaiGanesh Sakthivel Syncfusion Team August 28, 2020 04:11 PM UTC

Hi Mihaela,   
   
Thank you for the patience.   
   
We have checked the reported query “Add a load more button” from our end. we would like to inform you that you can add the load more button after specific number in the listview. Please refer to the following code snippet for your reference.   
 
Code snippet   
public PhotosViewModel PhotosViewModel  
{ 
    get { return photosViewModel; } 
    set 
    { 
        if (photosViewModel != value) 
        { 
            photosViewModel = value; 
        } 
    } 
} 
public PhotosDataService() 
{ 
    photosViewModel = PopulateData<PhotosViewModel>("navigation.json"); 
    photosViewModel.Photos1 = new ObservableCollection<Photo>(); 
    AddProducts(0, 3); 
    photosViewModel.LoadMoreItemsCommand = new Command<object>(this.LoadMoreItems, this.CanLoadMoreItems); 
} 
 
private bool CanLoadMoreItems(object obj) 
{ 
    if (photosViewModel.Photos1.Count >= photosViewModel.Photos.Count) 
        return false; 
    return true; 
} 
 
private async void LoadMoreItems(object obj) 
{ 
    var listview = obj as Syncfusion.ListView.XForms.SfListView; 
    try 
    { 
        photosViewModel.IsBusy = true; 
        await Task.Delay(1000); 
        var index = photosViewModel.Photos1.Count; 
        var count = index + 3 >= photosViewModel.Photos.Count ? photosViewModel.Photos.Count - index : 3; 
        AddProducts(index, count); 
    } 
    catch 
    { 
 
    } 
    finally 
    { 
        photosViewModel.IsBusy = false; 
    } 
} 
 
private void AddProducts(int index, int count) 
{ 
    for (int i = index; i < index + count; i++) 
    { 
        photosViewModel.Photos1.Add(photosViewModel.Photos[i]); 
    } 
 
   
Please refer to the following modified sample for your reference.   
  
We hope this helps.   
  
Regards,   
SaiGanesh Sakthivel 

Loader.
Up arrow icon