This is a migrated thread and some comments may be shown as answers.

RadDataPager and IPagedCollectionView

3 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kakone
Top achievements
Rank 1
Kakone asked on 06 May 2010, 09:38 AM
Hello,

I have a ViewModel class that implements IPagedCollectionView interface. The source property of RadDataPager is set to this ViewModel. But it doesn't work. If my ViewModel class implements also the IEnumerable interface, it works and I don't understand why. What is the explanation ?

My ViewModel class is something like that :
public class ListViewModel<TEntity> : IPagedCollectionView  
{  
  public IEnumerable<TEntity> List  
  {   
    ...   
  }  
 
  #region IPagedCollectionView Methods  
  ...  
  #endregion  

The source property of RadDataPager is set to this ViewModel and the ItemSource property of the RadDataGridView is binding to the List property of this ViewModel.
It works when I implements also IEnumerable interface like this :
IEnumerator IEnumerable.GetEnumerator() 
  IEnumerable enumerable = List as IEnumerable; 
  return (enumerable == null ? null : enumerable.GetEnumerator()); 

Why RadDataPager needs IEnumerable interface ?

Cordially,
Stéphane.

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 10 May 2010, 01:21 PM
Hello Stéphane Mitermite,

Can you please paste me the whole implementation of your ViewModel. I will try to resemble the problem here , and provide you further assistance.

Best wishes,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kakone
Top achievements
Rank 1
answered on 10 May 2010, 04:24 PM
Hello,

this is the whole implementation of my ViewModel class. The source property of the RadDataPager is set to this ViewModel and the ItemsSource property of the GridView is set to the List property of this ViewModel (I disable filtering and grouping).

    public class ListViewModelBase<TEntity> : ViewModelBase, IPagedCollectionView 
        where TEntity : Entity 
    { 
        #region Events 
        public event EventHandler<EventArgs> PageChanged; 
        public event EventHandler<PageChangingEventArgs> PageChanging; 
        #endregion 
        #region Constructor 
        public ListViewModelBase(IBusinessRepository<TEntity> repository) 
        { 
            Repository = repository; 
        } 
        #endregion 
        #region Properties 
        protected IBusinessRepository<TEntity> Repository 
        { 
            get
            private set
        } 
 
        private CollectionViewSource _source; 
        private CollectionViewSource Source 
        { 
            get 
            { 
                if (_source == null
                { 
                    _source = new CollectionViewSource(); 
                    LoadData(); 
                } 
 
                return _source; 
            } 
        } 
 
        public ICollectionView List 
        { 
            get { return Source.View; } 
        } 
 
        int _pageSize = 25; 
        public int PageSize 
        { 
            get { return _pageSize; } 
            set 
            { 
                if (_pageSize != value) 
                { 
                    _pageSize = value; 
                    RaisePropertyChanged("PageSize"); 
                } 
            } 
        } 
 
        public bool CanChangePage 
        { 
            get { return true; } 
        } 
 
        bool _isPageChanging; 
        public bool IsPageChanging 
        { 
            get { return _isPageChanging; } 
            private set 
            { 
                if (_isPageChanging != value) 
                { 
                    _isPageChanging = value; 
                    RaisePropertyChanged("IsPageChanging"); 
                } 
            } 
        } 
 
        public int ItemCount 
        { 
            get { return TotalItemCount; } 
        } 
 
        int _pageIndex = 0; 
        public int PageIndex 
        { 
            get { return _pageIndex; } 
            set 
            { 
                if (value < 0) 
                { 
                    throw new ArgumentOutOfRangeException(); 
                } 
 
                MoveToPage(value); 
            } 
        } 
 
        int _totalItemCount; 
        public int TotalItemCount 
        { 
            get { return _totalItemCount; } 
            set 
            { 
                if (_totalItemCount != value) 
                { 
                    _totalItemCount = value; 
                    RaisePropertyChanged("TotalItemCount"); 
                    RaisePropertyChanged("ItemCount"); 
                } 
            } 
        } 
        #endregion 
        #region Methods 
     public bool MoveToFirstPage() 
        { 
            return MoveToPage(0); 
        } 
 
        public bool MoveToLastPage() 
        { 
            return MoveToPage(TotalItemCount / PageSize); 
        } 
 
        public bool MoveToPreviousPage() 
        { 
            return MoveToPage(PageIndex - 1); 
        } 
 
        public bool MoveToNextPage() 
        { 
            return MoveToPage(PageIndex + 1); 
        } 
         
        public bool MoveToPage(int index) 
        { 
            if (index == PageIndex || index < 0) 
            { 
                return false
            } 
 
            IsPageChanging = true
            try 
            { 
                PageChangingEventArgs args = new PageChangingEventArgs(index); 
                if (PageChanging != null
                { 
                    PageChanging(this, args); 
                }        
                if (!args.Cancel) 
                { 
                    _pageIndex = index; 
                    LoadData(); 
 
                    RaisePropertyChanged("PageIndex"); 
                    if (PageChanged != null
                    { 
                        PageChanging(this, EventArgs.Empty); 
                    } 
                     
                    return true
                } 
 
                return false
            } 
            finally 
            { 
                IsPageChanging = false
            } 
        } 
 
        public virtual void LoadData() 
        { 
            IsBusy = true
 
            var source = Source; 
            var collectionView = source.View; 
            if (collectionView != null
            { 
                collectionView.CollectionChanged -= CollectionChanged; 
            } 
 
            Repository.Load(PageIndex, PageSize,  
                collectionView == null ? null : collectionView.SortDescriptions.ToDynamicLinq(), 
                result => 
                { 
                    if (result.Exception != null
                    { 
                        IsBusy = false
                        ShowError(result.Exception); 
                    } 
                    else 
                    { 
                        TotalItemCount = result.TotalItemCount; 
 
                        source.Source = result.Result; 
                        collectionView = source.View; 
                        if (collectionView != null
                        { 
                            collectionView.CollectionChanged += CollectionChanged; 
                        } 
                        RaisePropertyChanged("List"); 
 
                        IsBusy = false
                    } 
                }); 
        } 
 
        private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 
        { 
            LoadData(); 
        }         
        #endregion 
    } 


Cordially,
Stephane.
0
Accepted
Pavel Pavlov
Telerik team
answered on 14 May 2010, 02:51 PM
Hello Stéphane ,

I am afraid you can not avoid using IEnumerable as a source property for the RadDataPager.  As you may know the MS DataPager for Silverlight also has the Source property of type IEnumerable and we are trying to keep consistent with MS.

I am not sure if this is applicable to your scenario, but  just an idea - you may avoid using the ViewModel to do the paging logic and leave RadDataPager to do that for you.
You may feed it with the data to be paged via the RadDataPager.Source property and get the paged data from the RadDataPager.PagedSource property as described in this blog post
please see the  III. 2. Binding to RadDataPager.PagedSource  section.

Kind regards,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Kakone
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Kakone
Top achievements
Rank 1
Share this question
or