Filter with Custom pagging

5 posts, 0 answers
  1. Paresh
    Paresh avatar
    11 posts
    Member since:
    Jan 2009

    Posted 29 Mar 2014 Link to this post

    Hi,
    I was checking Telerik UI for ASP.NET AJAX Q1 2014 trial version.
    I need custom paging with sorting and filtering using Stored Procedure.

    i found that RadGrid filters already filtered data on its own. if custom paging is used, obviously sorting and filtering done in Stored Procedure.

    is there any way to stop Radgrid to filter data on its own somthing like FilterMode="Custom" ?
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 02 Apr 2014 Link to this post

    Hello Paresh,

    For canceling the default filter functionality of the grid you should handle the server-side OnItemCommand event and if the command name equals RadGrid.FilterCommandName to cancel the command.

    Following is a simple example of the above approach:
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="true"
        DataSourceID="SqlDataSource1" OnItemCommand="RadGrid1_ItemCommand">
    </telerik:RadGrid>

    And the code-behind:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.FilterCommandName)
        {
            e.Canceled = true;
            Pair filterPair = (Pair)e.CommandArgument;
            string filterFunction = filterPair.First.ToString();
            string column = filterPair.Second.ToString();
            string inputElementValue = ((e.Item as GridFilteringItem)[column].Controls[0] as TextBox).Text;
        }
    }

    As you could notice, in the ItemCommand event handler I have shown how to retrieve the data that you will need for your custom filtering.

    Hope that helps.


    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
  4. Mick
    Mick avatar
    16 posts
    Member since:
    May 2012

    Posted 13 Aug 2015 in reply to Konstantin Dikov Link to this post

    Yes, no it isn't that helpful as this results in the column.CurrentFilterValue and column.CurrentFilterFunction being blank.

    When doing virtual paging, it's quite obvious that you are going to need to do filtering and sorting in the database.  It's also quite obvious that if you are doing virtual paging you will not need the grid to perform filtering operations and that such operations might even be undesirable.  

     In my instance they are indeed undesirable and are causing an issue.  I'm trying to filter a date column which contains times down to millisecs, I handle the rounding issue in the database, but the grid doesn't resulting in results that should be in the page being omitted and not displayed, because they are filtered by the radgrid.

     I don't understand why Telerik goes to the trouble of providing the ability to do virtual paging, but makes it so hard to get it to work properly. 

     Regards

    Mick

  5. Mick
    Mick avatar
    16 posts
    Member since:
    May 2012

    Posted 13 Aug 2015 in reply to Mick Link to this post

    OK.  Helpful it was helpful

    I ended up with...

    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.FilterCommandName)
        {
            e.Canceled = true;
            Pair filterPair = (Pair)e.CommandArgument;
            string filterFunction = filterPair.First.ToString();
            string column = filterPair.Second.ToString();
            string inputElementValue = ((e.Item as GridFilteringItem)[column].Controls[0] as TextBox).Text;
            var gridColumn = gvAuditTrail.MasterTableView.Columns.FindByUniqueName(column);
        GridKnownFunction function; if (Enum.TryParse(filterFunction, out function))    }

    }

     This all seems overly coimplicated  a simple option or just ​don't filter items in the grid when AllowCustomPaging="true".

  6. Mick
    Mick avatar
    16 posts
    Member since:
    May 2012

    Posted 13 Aug 2015 in reply to Mick Link to this post

    Sorry that last post was accidentally posted prematurely and there's no way to edit or delete comments... so...

    OK.  Helpful it was helpful

    I ended up with...

    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.FilterCommandName)
        {
            Pair filterPair = (Pair)e.CommandArgument;
            string filterFunction = filterPair.First.ToString();
            string column = filterPair.Second.ToString();
            string inputElementValue = ((e.Item as GridFilteringItem)[column].Controls[0] as TextBox).Text;
            var gridColumn = gvAuditTrail.MasterTableView.Columns.FindByUniqueName(column);
            gridColumn = inputElementValue;
            GridKnownFunction function; 
            if (Enum.TryParse(filterFunction, out function))
                gridColumn.CurrentFilterFunction = function;
            e.Canceled = true;
            RadGrid1.DataSource = null;
            RadGrid1.Rebind();
       }
    }

    That seems like 23 lines of code more than should be needed to me a simple option or just don't filter items in the grid when AllowCustomPaging="true".
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017