Collection View limit items

Posted by: kelly.ostwald on 19 November 2017, 1:22 pm EST

  • Posted 19 November 2017, 1:22 pm EST

    looking at example http://help.grapecity.com/componentone/NetHelp/Xamarin-iOS/webframe.html#CollectionViewQuickStart.html

    if i modify the example so it will only return 60 items ie

    protected override async Task<Tuple<string, IReadOnlyList>> GetPageAsync(int startingIndex, string pageToken, int? count = null, IReadOnlyList sortDescriptions = null, FilterExpression filterExpresssion = null, CancellationToken cancellationToken = default(CancellationToken))

    {

    var newItems = new List();

    await Task.Run(() =>

    {

    // create new page of items

    for (int i = startingIndex; i < 60; i++)

    {

    newItems.Add(new MyDataItem(startingIndex + i));

    }

    });

            return new Tuple<string, IReadOnlyList<MyDataItem>>("token not used", newItems);
        }
    

    how do I prevent the loading spinner from showing at the bottom of the tableview?

  • Posted 20 November 2017, 1:05 am EST

    Hi Kelly

    I don’t think there’s a way to prevent it from displaying right now, but let me talk it over with the developers. I think it’s a built in behavior that can’t be overridden right now, but maybe we can change that as an enhancement. I’ll let you know once I’ve talked it over with the developers.

    Thanks

    Kelley

  • Posted 20 November 2017, 1:33 am EST

    Also as a followup, is there a reason why you aren’t simply setting all of the items into a single page? The activity indicator is meant to display during on demand loading so it’s a little unclear what your use case is exactly. If it’s displaying too often you’d probably be better served by either setting larger page sizes or loading all of the data at once.

  • Posted 20 November 2017, 1:48 pm EST

    Hi, I wanted to only retrieve 10 items from api, then next 10 etc… but if there is no more data on server, I didn’t want the spinner to keep showing. I think the user will be expecting more data to load if they see it, but there is nothing to show them.

  • Posted 22 November 2017, 11:43 pm EST

    Hi Kelly,

    You can try returning a Tuple with null values in the GetPageAsync() method if there’s no more data to return from the server. That should hide the spinner. I’ve modified the example you’ve shared earlier to demonstrate the same.

    This hides the spinner after 100 items have been loaded.

        public class SimpleOnDemandCollectionView : C1CursorCollectionView<MyDataItem>
        {
            const int MAX = 100;
            int current;
            .........
    
    
            protected override async Task<Tuple<string, IReadOnlyList<MyDataItem>>> GetPageAsync(int startingIndex, string pageToken, int? count = null, IReadOnlyList<SortDescription> sortDescriptions = null, FilterExpression filterExpresssion = null, CancellationToken cancellationToken = default(CancellationToken))
            {
    	    //check here if there's no more data to return
                if(startingIndex >= MAX)  
                    return new Tuple<string, IReadOnlyList<MyDataItem>>(null, null);
    
                var newItems = new List<MyDataItem>();
                await Task.Run(() =>
                {
                    // create new page of items
                    for (int i = 0; i < this.PageSize; i++)
                    {
                        Thread.Sleep(100);
                        if (current >= MAX)
                            break;
                        newItems.Add(new MyDataItem(startingIndex + i));
                        current++;
                    }
                });
                return new Tuple<string, IReadOnlyList<MyDataItem>>("token not used", newItems);
            }
    }
    

    Let us know if it helps.

    Regards,

    Ankit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels