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

QueryableCollectionView+RadGridView+RadDataPager Autonavigation on Page of Item

3 Answers 147 Views
GridView
This is a migrated thread and some comments may be shown as answers.
papuasy
Top achievements
Rank 1
papuasy asked on 19 Oct 2011, 10:17 AM
Hello!

I have QueryableCollectionView in my view model and i bind it to RadGridView and RadDataPager. When i use MoveCurrentTo() to set current item it work if item on the current page, but if item is not on the current page it is not works.

There is XAML of test project:
<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
 
    <telerik:RadGridView Grid.Row="0" ItemsSource="{Binding Persons}"/>
     
    <telerik:RadDataPager Grid.Row="1" Source="{Binding Persons}"/>
</Grid>

There is code for test project:
public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
}
 
public class ViewModel
{
    QueryableCollectionView _Persons;
    public QueryableCollectionView Persons
    {
        get
        {
            if (_Persons == null)
            {
                _Persons = new QueryableCollectionView(GetPersons());
                _Persons.PageSize = 20;
 
                Person person = (_Persons.SourceCollection as List<Person>).FirstOrDefault(p => p.Id == 50);
                if (person != null)
                    _Persons.MoveCurrentTo(person);
            }
 
            return _Persons;
        }
    }
 
    List<Person> GetPersons()
    {
        List<Person> res = new List<Person>();
        for (int i = 1; i < 100; i++)
            res.Add(new Person() { Id = i, Name = "Name " + i });
 
        return res;
    }
}

Is there simple solutions to automatically set current page on page that contains necessary item?

Thank you.

3 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 21 Oct 2011, 02:19 PM
Hi Papuasy,

 Indeed currency will no affect paging in any way. You need to calculate the page index based on item index and move to the respective page index. 

Best wishes,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
papuasy
Top achievements
Rank 1
answered on 21 Oct 2011, 05:48 PM
Thank you for reply.

Is any recomended way to get items count after filtering and sorting is applied, but paging is not applied?
I think it necessary for calculate page index...

Thank you.
0
Vlad
Telerik team
answered on 24 Oct 2011, 07:06 AM
Hello Papuasy,

 You can use ItemCount to achieve your goal. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
papuasy
Top achievements
Rank 1
Answers by
Vlad
Telerik team
papuasy
Top achievements
Rank 1
Share this question
or