Quick help please :Radgrid Filter Problem.

2 posts, 0 answers
  1. shemein
    shemein avatar
    28 posts
    Member since:
    Mar 2014

    Posted 08 Aug 2014 Link to this post

    I am trying to use filtering in Radgrid by this codes:

    Asp:

    ​<telerik:RadGrid ID="ToolkitList" runat="server" AllowSorting="True" CssClass="RadGridCustomClass" OnNeedDataSource="ToolkitListNeedDataSource" AutoGenerateColumns="False" OnPreRender="ToolkitList_PreRender" Style="margin-right: 30px;" OnInit="ToolkitList_Init" OnUpdateCommand="ToolkitList_UpdateCommand" Width="1143px" OnItemDataBound="ToolkitList_ItemDataBound" OnItemCreated="ToolkitList_ItemCreated" OnItemCommand="ToolkitList_ItemCommand" >
    <FilterMenu OnClientShowing="MenuShowing" />
    <GroupingSettings CaseSensitive="False" />
    <ClientSettings>
    <ClientEvents OnFilterMenuShowing="filterMenuShowing" />
    </ClientSettings>

    <MasterTableView DataKeyNames="Toolkit ID,Progress,ProgressString,IsDistributed" GridLines="Vertical" EditMode="InPlace">
    <PagerStyle Mode="NumericPages"></PagerStyle>
    <RowIndicatorColumn Visible="False">
    </RowIndicatorColumn>
    <ExpandCollapseColumn Created="True">
    </ExpandCollapseColumn>
    <Columns>
    <telerik:GridHyperLinkColumn DataNavigateUrlFields="Toolkit ID" SortExpression="Entity Name" AllowFiltering="true" AutoPostBackOnFilter="true" FilterControlAltText="Filter Entity Name column" DataNavigateUrlFormatString="~/Section/ToolkitIndex.aspx?_toolkitId={0}" DataTextField="Entity Name" DataTextFormatString="{0}" HeaderText="Entity Name" DataType="System.String" UniqueName="EntityName">

    <HeaderStyle HorizontalAlign="Left" CssClass="gridheaderdark" ForeColor="white" />

    </telerik:GridHyperLinkColumn>

    <Telerik:GridImageColumn UniqueName="GridImageColumn" ShowFilterIcon="False" SortExpression="RestrictAccess" HeaderText="Restrict" DataImageUrlFields="RestrictAccess" HeaderImageUrl="~\Images\Restricted.png">
    <HeaderStyle HorizontalAlign="Center" CssClass="gridheaderlight" ForeColor="white" />
    </Telerik:GridImageColumn>

    <telerik:GridBoundColumn AutoPostBackOnFilter="True" CurrentFilterFunction="Contains" DataField="Client Name" FilterControlAltText="Filter ClientName column" Groupable="False" HeaderText="Client Name" HtmlEncode="True" ReadOnly="true" SortExpression="Client Name" UniqueName="ClientName" DataType="System.String">
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    <HeaderStyle HorizontalAlign="Left" CssClass="gridheaderdark" ForeColor="white" />
    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn AutoPostBackOnFilter="True" CurrentFilterFunction="Contains" DataField="Client Number" FilterControlAltText="Filter Client # column" Groupable="False" HeaderText="Client #" HtmlEncode="True" ReadOnly="true" SortExpression="Client Number" UniqueName="ClientNumber" DataType="System.String">
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    <ItemStyle HorizontalAlign="Center" Width="80px" />
    <HeaderStyle HorizontalAlign="Center" Width="90px" CssClass="gridheaderlight" ForeColor="white"/>
    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn AllowFiltering="true" AllowSorting="False" AutoPostBackOnFilter="True" CurrentFilterFunction="Contains" DataField="BKD Office" FilterControlAltText="Filter BKD Office column" Groupable="False" HeaderText="BKD Office" HtmlEncode="True" ReadOnly="true" SortExpression="BKD Office" UniqueName="BKDOffice" DataType="System.String">
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    <ItemStyle HorizontalAlign="Center" Width="80px" />
    <HeaderStyle HorizontalAlign="Center" Width="90px" CssClass="gridheaderdark" ForeColor="white"/>
    </telerik:GridBoundColumn>

    <telerik:GridTemplateColumn AllowFiltering="False" DataField="Progress" FilterControlAltText="Filter ProgressBar column" Groupable="False" HeaderText="Progress" ReadOnly="True" Reorderable="False" Resizable="False" UniqueName="ProgressBar">
    <EditItemTemplate>
    <telerik:RadHtmlChart ID="ProgressBarChart" runat="server" Height="25px">
    <Legend>
    <Appearance Visible="false">
    </Appearance>
    </Legend>
    <PlotArea>
    <Appearance Visible="False">
    </Appearance>
    <XAxis Visible="False">
    <MajorGridLines Visible="False" />
    <MinorGridLines Visible="False" />
    </XAxis>
    <YAxis MaxValue="100" MinValue="0" Visible="False">
    <MajorGridLines Visible="False" />
    <MinorGridLines Visible="False" />
    </YAxis>
    <Series>
    <telerik:BarSeries DataFieldY="Progress" Gap="0" Spacing="0">
    <LabelsAppearance Position="InsideBase">
    </LabelsAppearance>
    <Appearance>
    <FillStyle BackgroundColor="Green" />
    </Appearance>
    <TooltipsAppearance Color="White" DataFormatString="{0}%" />
    </telerik:BarSeries>
    </Series>
    </PlotArea>
    <Navigator>
    <SelectionHint Visible="False">
    </SelectionHint>
    </Navigator>
    </telerik:RadHtmlChart>
    </EditItemTemplate>
    <ItemTemplate>
    <telerik:RadHtmlChart ID="ProgressBarChart" runat="server" Height="25px">
    <Legend>
    <Appearance Visible="false">
    </Appearance>
    </Legend>
    <PlotArea>
    <Appearance Visible="False">
    </Appearance>
    <XAxis Visible="False">
    <MajorGridLines Visible="False" />
    <MinorGridLines Visible="False" />
    </XAxis>
    <YAxis MaxValue="100" MinValue="0" Visible="False">
    <MajorGridLines Visible="False" />
    <MinorGridLines Visible="False" />
    </YAxis>
    <Series>
    <telerik:BarSeries DataFieldY="Progress" Gap="0" Spacing="0">
    <LabelsAppearance Position="InsideBase">
    </LabelsAppearance>
    <Appearance>
    <FillStyle BackgroundColor="Green" />
    </Appearance>
    <TooltipsAppearance Color="White" DataFormatString="{0}%" />
    </telerik:BarSeries>
    </Series>
    </PlotArea>
    <Navigator>
    <SelectionHint Visible="False">
    </SelectionHint>
    </Navigator>
    </telerik:RadHtmlChart>
    </ItemTemplate>
    <ItemStyle Width="120px" />
    <HeaderStyle CssClass="gridheaderlight" HorizontalAlign="Center" ForeColor="white"></HeaderStyle>
    </telerik:GridTemplateColumn>

    <telerik:GridDateTimeColumn AutoPostBackOnFilter="True" CurrentFilterFunction="EqualTo" FilterControlWidth="70px" DataField="Year End" DataFormatString="{0:M/d/yyyy}" DataType="System.DateTime" FilterControlAltText="Filter Year End column" Groupable="False" HeaderText="Year-End" ReadOnly="True" SortExpression="Year End" UniqueName="YearEnd">
    <ItemStyle HorizontalAlign="Center" Width="80px" />
    <HeaderStyle HorizontalAlign="Center" Width="90px" CssClass="gridheaderdark" ForeColor="white"/>
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    </telerik:GridDateTimeColumn>

    <telerik:GridDateTimeColumn AutoPostBackOnFilter="True" CurrentFilterFunction="EqualTo" FilterControlWidth="70px" DataField="Distribution Date" DataFormatString="{0:M/d/yyyy}" DataType="System.DateTime" FilterControlAltText="Filter Distribution Date column" Groupable="False" HeaderText="Dist. Date" ReadOnly="true" SortExpression="Distribution Date" UniqueName="DistributionDate">
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    <ItemStyle HorizontalAlign="Center" Width="80px" />
    <HeaderStyle HorizontalAlign="Center" Width="90px" CssClass="gridheaderlight" ForeColor="white"/>
    </telerik:GridDateTimeColumn>

    <telerik:GridDateTimeColumn AutoPostBackOnFilter="True" CurrentFilterFunction="EqualTo" FilterControlWidth="70px" DataField="Toolkit Due Date" DataFormatString="{0:M/d/yyyy}" DataType="System.DateTime" FilterControlAltText="Filter Toolkit Due Date column" Groupable="False" HeaderText="Toolkit Due" ReadOnly="False" SortExpression="Toolkit Due Date" UniqueName="ToolkitDueDate">
    <ItemStyle HorizontalAlign="Center" Width="80px" />
    <HeaderStyle HorizontalAlign="Center" Width="90px" CssClass="gridheaderdark" ForeColor="white"/>
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    </telerik:GridDateTimeColumn>


    <telerik:GridDateTimeColumn AutoPostBackOnFilter="True" CurrentFilterFunction="EqualTo" DataField="Board Meeting Date" FilterControlWidth="70px" DataFormatString="{0:M/d/yyyy}" DataType="System.DateTime" FilterControlAltText="Filter Board Meeting Date column" Groupable="False" HeaderText="Board Mtg." ReadOnly="False" SortExpression="Board Meeting Date" UniqueName="BoardMeetingDate">
    <ItemStyle HorizontalAlign="Center" Width="80px" />
    <HeaderStyle HorizontalAlign="Center" Width="90px" CssClass="gridheaderlight" ForeColor="white"/>
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    </telerik:GridDateTimeColumn>



    <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" DataField="Progress" DataType="System.Int16" Display="False" FilterControlAltText="Filter Progress column" Groupable="False" HeaderText="Progress" ReadOnly="True" Reorderable="False" Resizable="False" ShowSortIcon="False" UniqueName="Progress">
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" DataField="ProgressString" DataType="System.String" Display="False" FilterControlAltText="Filter Progress column" Groupable="False" HeaderText="ProgressString" ReadOnly="True" Reorderable="False" Resizable="False" ShowSortIcon="False" UniqueName="ProgressString">
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" DataField="Toolkit ID" Display="false" Groupable="False" HeaderText="Toolkit ID" ReadOnly="true" Reorderable="False" Resizable="False" ShowSortIcon="False" UniqueName="ToolkitID">
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn AllowFiltering="False" DataField="Assigned" Groupable="False" HeaderText="Assigned" HtmlEncode="True" SortExpression="Assigned" UniqueName="Assigned" ReadOnly="true" Display="false">
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn AllowFiltering="False" DataField="RestrictAccess" Groupable="False" HeaderText="RestrictAccess" HtmlEncode="True" SortExpression="RestrictAccess" UniqueName="RestrictAccess" ReadOnly="true" Display="False" >
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn AllowFiltering="False" DataField="IsDistributed" Groupable="False" HeaderText="IsDistributed" HtmlEncode="True" SortExpression="IsDistributed" UniqueName="IsDistributed" ReadOnly="true" Display="False" >
    <ColumnValidationSettings>
    <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    </telerik:GridBoundColumn>
    <telerik:GridEditCommandColumn ButtonType="ImageButton" ColumnGroupName="Actions" HeaderStyle-CssClass="header" UniqueName="EditCommandColumn" >
    <HeaderStyle CssClass="header" />
    <ItemStyle HorizontalAlign="Center" Width="15" CssClass="MergedBorder"/>
    </telerik:GridEditCommandColumn>

    <telerik:GridButtonColumn ButtonType="ImageButton" ColumnGroupName="Actions" HeaderStyle-CssClass="header" ImageUrl="~\Images\users-icon.png" UniqueName="ManageUserColumn" CommandName="Manageusers" >
    <HeaderStyle CssClass="header"/>
    <ItemStyle HorizontalAlign="Center" Width="5" CssClass="MergedBorder"/>
    </telerik:GridButtonColumn>


    <telerik:GridButtonColumn ButtonType="ImageButton" ColumnGroupName="Actions" HeaderStyle-CssClass="header" ImageUrl="~\Images\distribute.gif" UniqueName="DistributeColumn" CommandName="DistributeButtonColumn">
    <HeaderStyle CssClass="header" />
    <ItemStyle HorizontalAlign="Center" Width="5" CssClass="MergedBorder"/>
    </telerik:GridButtonColumn>

    <telerik:GridTemplateColumn UniqueName="DeleteColumn" ColumnGroupName="Actions" AllowFiltering="False">
    <ItemTemplate>
    <asp:ImageButton ID="DeleteImageButton" runat="server" AlternateText="Delete Toolkit" CommandName="Delete"
    OnClientClick="javascript:if(!confirm('This action will delete the selected Toolkit. Are you sure?')){return false;}"
    ImageUrl="~\Images\delete-icon.png" />
    </ItemTemplate>
    <HeaderStyle CssClass="header" />
    <ItemStyle HorizontalAlign="Center" Width="5" CssClass="MergedBorder"/>
    </telerik:GridTemplateColumn>

    </Columns>
    <ColumnGroups>
    <telerik:GridColumnGroup HeaderStyle-HorizontalAlign="Center" HeaderText="Actions" Name="Actions" >
    <HeaderStyle HorizontalAlign="Center" CssClass="gridheaderdark" ForeColor="white"/>

    </telerik:GridColumnGroup>
    </ColumnGroups>
    <EditFormSettings>
    <EditColumn UniqueName="EditCommandColumn" ButtonType="ImageButton" CancelImageUrl="~/RadControls/Grid/Skins/Default/Cancel.gif" UpdateImageUrl="~/RadControls/Grid/Skins/Default/Update.gif" >
    </EditColumn>

    <EditColumn FilterControlAltText="Filter EditCommandColumn1 column" UniqueName="EditCommandColumn1" >
    </EditColumn>
    </EditFormSettings>

    </MasterTableView>

    <FilterMenu OnClientShowing="MenuShowing" />
    </telerik:RadGrid>
    </telerik:RadAjaxPanel>


    <telerik:RadCodeBlock ID="CustomizingFiltersBlock" runat="server">
    <script type="text/javascript">
    var column = null;

    function MenuShowing(sender, args) {
    if (column == null) return;
    var menu = sender;
    var items = menu.get_items();
    if (column.get_dataType() == "System.String") {
    var i = 0;
    while (i < items.get_count()) {
    if (!(items.getItem(i).get_value() in { 'Contains': '', 'DoesNotContain': '', 'StartsWith': '', 'EndsWith': '', 'IsEmpty': '', 'NotIsEmpty': '', 'NoFilter': '' })) {
    var item = items.getItem(i);
    if (item != null)
    item.set_visible(false);
    }
    else {
    var item = items.getItem(i);
    if (item != null)
    item.set_visible(true);
    } i++;
    }
    }
    if (column.get_dataType() == "System.UInt32") {
    var j = 0;
    while (j < items.get_count()) {
    if (!(items.getItem(j).get_value() in { 'EqualTo': '', 'NotEqualTo': '', 'GreaterThan': '', 'GreaterThanOrEqualTo': '', 'LessThan': '', 'LessThanOrEqualTo': '', 'NoFilter': '' })) {
    var item = items.getItem(j);
    if (item != null)
    item.set_visible(false);
    } else {
    var item = items.getItem(j);
    if (item != null)
    item.set_visible(true);
    } j++;
    }
    }
    if (column.get_dataType() == "System.DateTime") {
    var j = 0;
    while (j < items.get_count()) {
    if (!(items.getItem(j).get_value() in { 'EqualTo': '', 'NotEqualTo': '', 'GreaterThan': '', 'GreaterThanOrEqualTo': '', 'LessThan': '', 'LessThanOrEqualTo': '', 'NoFilter': '' })) {
    var item = items.getItem(j);
    if (item != null)
    item.set_visible(false);
    } else {
    var item = items.getItem(j);
    if (item != null)
    item.set_visible(true);
    } j++;
    }
    }
    //if (column.get_uniqueName() == "EIN") {
    // var j = 0;
    // while (j < items.get_count()) {
    // if (!(items.getItem(j).get_value() in { 'NoFilter': ''})) {
    // var item = items.getItem(j);
    // if (item != null)
    // item.set_visible(false);
    // } else {
    // var item = items.getItem(j);
    // if (item != null)
    // item.set_visible(true);
    // } j++;
    // }
    //}
    column = null;
    menu.repaint();
    }

    function filterMenuShowing(sender, eventArgs) {
    column = eventArgs.get_column();
    }


    </script>
    </telerik:RadCodeBlock>

    and  Cs code:

    ​protected void ToolkitList_Init(object sender, EventArgs e)
    {

    #region Ordering Filter Options

    // Get the single server side filter list.
    GridFilterMenu menu = ToolkitList.FilterMenu;

    // Get the "No Filter" menu choice.
    var noFilter = menu.Items.FindItemByText("No Filter");

    // Moves "No Filter" To the bottom of the list.
    menu.Items.Remove(noFilter);
    menu.Items.Add(noFilter);

    // Get the "Less Than" menu choice and index.
    var lessThan = menu.Items.FindItemByText("Less Than");
    int lessThanIndex = lessThan.Index;

    // Get the "Greater Than Or Equal To" menu choice and index.
    var greaterThanOrEqualTo = menu.Items.FindItemByText("Greater Than Or Equal To");
    int greaterThanOrEqualToIndex = greaterThanOrEqualTo.Index;

    // Pull the old switch them around trick.
    menu.Items[lessThanIndex] = greaterThanOrEqualTo;
    menu.Items[greaterThanOrEqualToIndex] = lessThan;

    #endregion
    }
    ​ protected void ToolkitList_PreRender(object sender, EventArgs e)
    {
    #region Selecting Default Menu Option

    // Loop through all the columns
    int i = 0;
    while (i < ToolkitList.Columns.Count)
    {
    // Check to make sure that there is no filter text.
    if (string.IsNullOrEmpty(ToolkitList.MasterTableView.Columns[i].CurrentFilterValue))
    {
    // If it is a string column assign it the default of contains.
    if (ToolkitList.Columns[i].DataType.ToString() == "System.String")
    {
    ToolkitList.Columns[i].CurrentFilterFunction = GridKnownFunction.Contains;
    }

    // If it is an integer or date column assign it the default of equal to.
    if (ToolkitList.Columns[i].DataType.ToString() == "System.UInt32" ||
    ToolkitList.Columns[i].DataType.ToString() == "System.DateTime")
    {
    ToolkitList.Columns[i].CurrentFilterFunction = GridKnownFunction.EqualTo;
    }
    }

    i++;
    }

    this.ToolkitList.Rebind();

    #endregion
                 GridColumn gridCol = ToolkitList.MasterTableView.GetColumn("EditCommandColumn");
    gridCol.HeaderStyle.Width = Unit.Pixel(50);
              }

    but I get this error :
    0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index

    I need your help as soon as possible plz.
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1796 posts

    Posted 13 Aug 2014 Link to this post

    Hello,

    Since the error that you are receiving could be linked to a numerous things and it will be hard to pinpoint what exactly is causing it in your scenario, could you please temporarily disable the AJAX on your page, which will allow you to see the full stack trace of the exception.

    Please try the above and paste the full stack trace, so we could get a better idea of what is the root of the problem.

    I am looking forward to your reply.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top