I am currently implementing a custom PageControl for a XamWebGrid and I am stumped trying to add a drop down list to allow the user to change the PageSize.
Is this possible?
This was sent directly to my email and not posted, but I wanted to reply and this seemed the easiest way to do it.
There is a sample called "Pager Customization" in our Silverlight samples that shows exactly how to do this:
http://samples.infragistics.com/silverlight
Basically you have to re-template the PagerControl control, drop in a combobox, then you can use the grids commands to tell the grid to change pages.
Devin
Thanks, that is the example that I am following, but I don't want to change pages. I want to change the number of records per page by Drop down list.
Thanks
Grrr. Ya, my bad. I realized I didn't really answer your question about 5 seconds after I hit the send button, but the forums had apparently already sent the email. Sorry for the confusion.
I am working on a sample to answer your real question...
No Problem, thanks for the help!
OK..so basically what you can do is add a ComboBox to the PagerCellControl template and bind its SelectedItem property to the grids PageSize property using a RelativeSource binding:
<ComboBox x:Name="pageSizeComboBox" SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Cell.Row.ColumnLayout.PagerSettings.PageSize, Mode=TwoWay, Converter={StaticResource myItemToIntConverter}}"> <ComboBoxItem Content="0" /> <ComboBoxItem Content="5" /> <ComboBoxItem Content="10" /> <ComboBoxItem Content="15" /> <ComboBoxItem Content="20" /> <ComboBoxItem Content="25" /></ComboBox>
Note that I also had to write a converter to convert the ComboBoxItems to/from Int32.
Hope that helps.
I just viewed the video on customizing the pager template.
http://forums.infragistics.com/silverlight/media/p/125441.aspx
It shows how to change the pager to add additional boxes and buttons to do whatever you want, including changing the page size. It let me move the page size box and my save, cancel buttons onto the pager bar. I adjusted it to use my logic to maintain the present location in the RIA domaindatasource, which is lost if you use the code as it was presented.
I have figured this out, but I am still trying to get it to hit the correct row, based on where you started. I have no idea if this is the most efficient, but it is working.
First I had to define some variables in the code behind, and I had to add this line to the loadeddata event.. Without this line it kept going back to page 1.
customerXamGrid.PagerSettings.CurrentPageIndex = newPage;
I also want to add another line here to set the current row to newLine, but I cannot figure out how to set the current line on the grid. grid.activecell.row.index is read only.
newPage is set at 0 when the page is loaded.
Then I have a textbox with the lines per page. I am currently setting it to 20 as a default, as well as using that constant in the xaml.
This is the event when the user changes the value in that textbox.
{
if (rpp.Text != null & customerDomainDataSource.CanLoad & rpp.Text.Length==2)
//can load makes sure we don't have unsaved changes
int rppvalue = int.Parse(rpp.Text);
int rownum;
// null if no activecell, so use first row
// curpos is the row in the entire dataset
customerDomainDataSource.LoadSize = customerDomainDataSource.PageSize = customerXamGrid.PagerSettings.PageSize = rppvalue;
newPage = (int)decimal.Truncate(curpos / rppvalue);
newLine = curpos - customerDomainDataSource.PageSize * newPage;
}}}
Thanks for reply, Stevez.
But binding on Cell.Row.ColumnLayout.PagerSettings.PageSizeResolved or Cell.Row.ColumnLayout.Grid.PagerSettings.PageSize
is works only one time, when table loading, TwoWay binding is not working, so when i change value on face, no changes on XamGrid's PagerSize.
Have you ideas how i can solve that problem: i can use Loaded event on TextBox that binds to PageSize and set PageSize manually, but i have 2 tables whith one PagerCellControlTemplate?
Hi,
So to get the PageSize, you want to bind to:Cell.Row.ColumnLayout.PagerSettings.PageSizeResolvedor Cell.Row.ColumnLayout.Grid.PagerSettings.PageSize.
The PagerSettings on the ColumnLayout defaults to 0 unless specified directly.
As for showing the filtered row count via a binding, i'm actually not sure about that one. The Collection does actually have the right count, the issue is that Count doesn't raise a PropertyChanged event, which is why it'll show a stale value.
-SteveZ