Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
How to show " {0} - {1} of {3} records" in xamwebgrid pager?
posted

I am use xamwebgrid 10.1  in silverlight project, besides the default pager,  I also like to show some text like " 1 - 25 of 91 records"  on the left side of the pager area, my implement is :

 

XAML: where Items is a VirtualCollection<myType> object

 <igGrid:XamWebGrid x:Name="subscriptions"   Grid.Row="3" AutoGenerateColumns="False" RowHover="Row"  ItemsSource="{Binding Items}" >
                    <igGrid:XamWebGrid.PagerSettings>
                    <igGrid:PagerSettings PageSize="25" Style="{StaticResource customPager}" AllowPaging="Bottom" >
                    </igGrid:PagerSettings>
                </igGrid:XamWebGrid.PagerSettings>
                    <igGrid:XamWebGrid.Columns>

                  ........

 </igGrid:XamWebGrid>

 

in APP.xaml I defined style of customPager as :

<Style x:Name="customPager" TargetType="igPrim:PagerCellControl" >
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="igPrim:PagerCellControl">
                        <Grid Background="#EEE">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Margin="5,5,0,0">
                                <TextBlock Text="{Binding Mode=TwoWay, Converter={StaticResource virtualCollectionToPageSummaryConverter}, Path=Parent.Owner.Grid.ItemsSource.PageIndex, RelativeSource={RelativeSource TemplatedParent}}"  />
                                <TextBlock Text=" - " />
                                <TextBlock Text="{Binding Mode=TwoWay, Converter={StaticResource virtualCollectionToPageSummaryConverter}, ConverterParameter=1, Path=Parent.Owner.Grid.ItemsSource.PageIndex,  RelativeSource={RelativeSource TemplatedParent}}"  />
                                <TextBlock Text=" of " />
                                <TextBlock Text="{Binding Mode=TwoWay, Path=Parent.Owner.Grid.ItemsSource.TotalItemCount, RelativeSource={RelativeSource TemplatedParent} }" />
                                <TextBlock Text=" records"  />                               
                            </StackPanel>
                            <igPrim:PagerControl x:Name="PagerItemControl" Grid.Column="1">
                                <!-- Execute command on PagerCellControl when a specific PagerControl event occurs-->
                                <Controls1:Commanding.Commands>
                                    <igGrid:XamWebGridPagingCommandSource EventName="FirstPage"  CommandType="FirstPage" >
                                    </igGrid:XamWebGridPagingCommandSource>
                                    <igGrid:XamWebGridPagingCommandSource EventName="LastPage"  CommandType="LastPage" >
                                    </igGrid:XamWebGridPagingCommandSource>
                                    <igGrid:XamWebGridPagingCommandSource EventName="PreviousPage"  CommandType="PreviousPage" >
                                    </igGrid:XamWebGridPagingCommandSource>
                                    <igGrid:XamWebGridPagingCommandSource EventName="NextPage"  CommandType="NextPage" >
                                    </igGrid:XamWebGridPagingCommandSource>
                                    <igGrid:XamWebGridPagingCommandSource EventName="GoToPage"  CommandType="GoToPage" >
                                    </igGrid:XamWebGridPagingCommandSource>
                                </Controls1:Commanding.Commands>
                            </igPrim:PagerControl>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

 

And the converter default as:

 public class VirtualCollectionToPageSummaryConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int result = 0;
            var pageIndex = (int)value;
            if( parameter == null)
            {
                result = pageIndex*25 + 1;
            }
            else
            {
                result = (pageIndex + 1)*25;
            }
            return result;        
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

 

Issue:

Basic all work perfect except the one:  when you click those pager item to the last page, the text will be show as " 76 - 100 of 91 records " which should be " 76 - 91 of 91 records" for the last page.

So how to fix this issue?   Thanks!