Hello all,
I am running into a very interesting issue and I was hoping one of you coud help. It appears that paging with an object datasource works perfectly with sorting, but as soon as I try to implement custom filtering, paging appears to not take the "SelectCount" method on the object datasource using the number of records returned as to total number of records.
I cannot use the Enable Linq expressions as it does not meet my needs for the Entity Framework selects I am performing so I have created my on linq predicate parser based on the filter expressions provided by Telerik.
I have defined the following RadGrid:
Using the the following data source:
I have defined the 2 events in the code behind as follows:
The object data source DataObject is very simple:
I am hoping you can help in this matter as it is quite a road block for several of the pages we would like to implement.
Thank you
I am running into a very interesting issue and I was hoping one of you coud help. It appears that paging with an object datasource works perfectly with sorting, but as soon as I try to implement custom filtering, paging appears to not take the "SelectCount" method on the object datasource using the number of records returned as to total number of records.
I cannot use the Enable Linq expressions as it does not meet my needs for the Entity Framework selects I am performing so I have created my on linq predicate parser based on the filter expressions provided by Telerik.
I have defined the following RadGrid:
<telerik:RadGrid ID="rgProjects" runat="server" CommandItemDisplay="Top" GridLines="None" AllowCustomPaging="True" AllowPaging="true" PagerStyle-AlwaysVisible="true" PageSize="10" CellSpacing="0" AllowFilteringByColumn="True" EnableLinqExpressions="false" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="dsProjects" onitemcommand="rgProjects_ItemCommand" > <MasterTableView EditMode="InPlace" CommandItemDisplay="None" OverrideDataSourceControlSorting="true" PagerStyle-AlwaysVisible="true"> <NoRecordsTemplate> <asp:Label ID="lbNoUsers" runat="server" Text="There are currently no Project records in the system."></asp:Label> </NoRecordsTemplate> <Columns> <telerik:GridHyperLinkColumn DataNavigateUrlFields="ProjectKey" DataNavigateUrlFormatString="~/ProjectCreation/CreateProject.aspx?NK=3&P={0}" DataTextFormatString="Project {0}" DataTextField="ProjectKey" FilterControlAltText="Filter column column" HeaderText="Project" UniqueName="ProjectKey" SortExpression="PROJECT_KEY"> </telerik:GridHyperLinkColumn> <telerik:GridTemplateColumn FilterControlAltText="Filter PrimaryClientNumber column" HeaderText="Primary Client Number" UniqueName="PrimaryClientNumber" SortExpression="PRIMARY_CLIENT.CLIENT_NUMBER"> <ItemTemplate> <MlCts:SecuredLabel ID="lbPrimaryClientNumber" runat="server" BindingObjectTextPropertyName="ClientNumber" BindingPath=".PrimaryClient"></MlCts:SecuredLabel> </ItemTemplate> </telerik:GridTemplateColumn> ..removed for brevity <telerik:GridTemplateColumn FilterControlAltText="Filter SecondaryMatterName column" HeaderText="Secondary Matter Name" UniqueName="SecondaryMatterName" SortExpression="SECONDARY_MATTERMATTER_NAME"> <ItemTemplate> <MlCts:SecuredLabel ID="lbSecondaryMatterName" runat="server" BindingObjectTextPropertyName="MatterDescription" BindingPath=".SecondaryMatter"></MlCts:SecuredLabel> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> <EditFormSettings EditColumn-ButtonType="ImageButton" EditColumn-Display="false" EditColumn-Visible="true" EditFormType="AutoGenerated"> <EditColumn ButtonType="ImageButton" Display="False"> </EditColumn> </EditFormSettings> </MasterTableView> </telerik:RadGrid>Using the the following data source:
<asp:ObjectDataSource ID="dsProjects" EnablePaging="true" MaximumRowsParameterName="PageSize" SelectCountMethod="SelectCount" StartRowIndexParameterName="CurrentRowIndex" TypeName="PTDSA.DataSources.ProjectDatasource" SortParameterName="SortParam"runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="Select" onselecting="dsProjects_Selecting"> <SelectParameters> <asp:Parameter Name="FilterOperation" Type="String" /> <asp:Parameter Name="FilterValue" Type="Object" /> </SelectParameters> </asp:ObjectDataSource> I have defined the 2 events in the code behind as follows:
object _filtervalue = null; string _filterpredicate = null; string _operation = null; protected void dsProjects_Selecting(object sender, ObjectDataSourceSelectingEventArgs e) { e.Arguments.MaximumRows = rgProjects.MasterTableView.PageSize; if (_filtervalue != null) { if (_operation == "NoFilter") { _filtervalue = null; _filterpredicate = null; } e.Arguments.StartRowIndex = 0; e.InputParameters["FilterOperation"] = _filterpredicate; e.InputParameters["FilterValue"] = _filtervalue; } } protected void rgProjects_ItemCommand(object sender, GridCommandEventArgs e) { if (e.Item != null) { if (e.Item.ItemType == GridItemType.FilteringItem) { Pair filterPair = e.CommandArgument as Pair; if (filterPair != null) { GridColumn currentCol = e.Item.OwnerTableView.GetColumn(filterPair.Second.ToString()); if (currentCol != null) { _filtervalue = Convert.ChangeType(currentCol.CurrentFilterValue, currentCol.DataType); //This is my custom linq predicate creation _filterpredicate = e.GetDynamicLinqFilter(currentCol.SortExpression, false); _operation = filterPair.First.ToString(); } } } } } [DataObject(true)] public class ProjectDatasource { public Project[] Select( string FilterOperation, object FilterValue, string SortParam, int PageSize, int CurrentRowIndex ) { using (...Custom Data Provider) { string sortBy = String.IsNullOrWhiteSpace(SortParam) ? "PROJECT_KEY" : SortParam; sortBy = Utilities.getSortParamName(sortBy); bool isAscending = Utilities.getIsAscending(sortBy); Project[] returnItems = dataProvider.GetProjectsBySearchParams(PageSize, CurrentRowIndex, sortBy, isAscending, FilterOperation, FilterValue ); return returnItems; } } public int SelectCount( string FilterOperation, object FilterValue) { using (..Custom Data Provder) { return dataProvider.GetProjectsBySearchParamsCount( FilterOperation, FilterValue ); } } }I am hoping you can help in this matter as it is quite a road block for several of the pages we would like to implement.
Thank you