This is a migrated thread and some comments may be shown as answers.

Filter with Custom pagging

4 Answers 247 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paresh
Top achievements
Rank 1
Paresh asked on 29 Mar 2014, 09:30 AM
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" ?

4 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 02 Apr 2014, 02:01 PM
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.

 
0
Mick
Top achievements
Rank 1
answered on 14 Aug 2015, 01:33 AM

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

0
Mick
Top achievements
Rank 1
answered on 14 Aug 2015, 01:55 AM

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".

0
Mick
Top achievements
Rank 1
answered on 14 Aug 2015, 02:00 AM
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".
Tags
Grid
Asked by
Paresh
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Mick
Top achievements
Rank 1
Share this question
or