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
180
AutoPage a grid
posted

Hi,

I would like to have paging on a XamWebGrid with the PageSize auto-calculated based on the height of the grid. Is there a easy way? Should I calculate the maximum number of rows that can be displayed and set the PageSize dynamically?

I tried to use grid.RowHeight, grid[0].ActualHeight, grid[0].Height, grid[0].HeightResolved without any success of getting the row height.

Thanks.

  • 5595
    posted

    Hi,

    This is a rather hacky solution, but it works. Try the following XAML / cs:

     

    <

     

     

    igGrid:XamWebGrid x:Name="TestXamWebGrid" LayoutUpdated="TestXamWebGrid_LayoutUpdated"/>

    ==

     

     

    public partial class MainPage : UserControl

    {

     

     

    // 1 for the Pager Row and

     

     

    // 1 for any partially visible row

     

     

    private const int MinPageSize = 2;

     

     

    public MainPage()

    {

     

     

    this.Loaded += new RoutedEventHandler(MainPage_Loaded);

    InitializeComponent();

    }

     

     

    void MainPage_Loaded(object sender, RoutedEventArgs e)

    {

     

     

    ObservableCollection<ITestData> data = new ObservableCollection<ITestData>();

     

     

    for (int i = 0; i <= 10000; i++)

    data.Add(

     

    new TestData() { TextData = "data" + i });

     

     

    this.TestXamWebGrid.ItemsSource = data;

    }

     

     

    private void DeterminePaging(XamWebGrid grid)

    {

     

     

    int i = 0;

     

     

    while ((i < grid.Rows.Count) && (grid.Rows[i].Control != null))

    {

    i++;

    }

     

     

    if (i > MinPageSize)

    {

    grid.PagerSettings.PageSize = i - MinPageSize;

    grid.PagerSettings.AllowPaging =

     

    PagingLocation.Bottom;

    }

    }

     

     

    private void TestXamWebGrid_LayoutUpdated(object sender, EventArgs e)

    {

     

     

    XamWebGrid grid = this.TestXamWebGrid;

    grid.LayoutUpdated -=

     

    this.TestXamWebGrid_LayoutUpdated;

     

     

    this.DeterminePaging(grid);

    }

    }

     

    Note that this will depend on what exactly features you have enabled in the Grid and also will be performed once, initially - if you have resizing of the Grid, the page size will not change.

     

    HTH,