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

[Solved] Suppress built-in filtering

11 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jan
Top achievements
Rank 1
Jan asked on 19 Apr 2013, 02:38 PM
Hi all.

Is there any possibility to suppress built-in filtering in RadGrid?

I need to handle with filtering on my own so I'd like to use FilteringItem in MasterTableView which is generated automatically and do some filtering action in OnItemCommand event. For this I need to prevent from application of built-in filtering functionality.

Datasource - DataTable.
NeedDataSource not used.
For all actions (sorting/filtering) I want to have my own handlers. (I have my own sorting.)

Target scenario - I will create dynamic SQL command with filtering condition and I will bind its result to Grid. No stored procedures, no LINQ, no Entity. I have dynamic commands and I need them.

Thanks a lot for any advance.

11 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 19 Apr 2013, 05:03 PM
doesn't the grid have a property AllowFiltering?  and each column can also turn on/off filtering

I wrote a page with a Telerik RadGrid that turned off all filtering on the header and used dropdowns (RadComboBoxes) to filter
- **** turn off LINQ on the grid or it won't work ********
0
Jan
Top achievements
Rank 1
answered on 19 Apr 2013, 06:02 PM
Thank you for fast reply.

It has, of course. I wanted to overload filtering. Not to disable it.
I tried to find some solution to disable whole filtering functionality and render some filter textboxes to first row of grid. But I was not successful.
0
Elliott
Top achievements
Rank 2
answered on 19 Apr 2013, 06:22 PM
let me see if I can help you then
if you want to turn off filtering on the entire grid then set AllowFilteringByColumns=False (default is true)
if you want to turn off filtering on selected columns but not on the entire grid then set AllowFiltering="False" on that column

if you want to change or add filtering from another source, then set EnableLinqExpressions="false" on the grid
now to add / update the filter use something like the following
private string AppendFilterExpression(string filterExpression)
{
    StringBuilder sb;
    sb = new StringBuilder(rgEditOrder.MasterTableView.FilterExpression);
    if (filterExpression == string.Empty)
        return sb.ToString();
    if (sb.ToString() != string.Empty)
    {
        sb.Append(" AND ");
    }
    sb.Append(filterExpression);
    return sb.ToString();
}
 
private string RemoveFilter(string columnName)
{
    string filterExpression;
    string[] filterArray;
    string charac = "&";
    char[] amper = charac.ToCharArray();
    StringBuilder sb;
    int i;
 
    sb = new StringBuilder("");
    filterExpression = rgEditOrder.MasterTableView.FilterExpression;
    filterExpression = filterExpression.Replace(" AND ", charac);
    filterArray = filterExpression.Split(amper, 3);
 
    for (i = 0; i < filterArray.Length; i++)
    {
        if (filterArray[i].IndexOf(columnName) == -1)
        {
            if (sb.Length > 0)
            {
                sb.Append(charac);
            }
            sb.Append(filterArray[i]);
        }
    }
    filterExpression = sb.ToString();
    filterExpression = filterExpression.Replace(charac, " AND ");
    return filterExpression;
}

to update, remove the old filter expression(remove any filter for the column) - and add the new
the filter expression is found in grid name.MasterTableView.FilterExpression property
it is a string in the following format ([UniqueName of column] = 'value') AND filter criteria #2 and so forth
- this applies to Equal To - for the other operators it wouldn't be =


0
Jan
Top achievements
Rank 1
answered on 19 Apr 2013, 06:53 PM
Unfortunately I think you don't understand me. I have no problem to build filter friteria and use it in my SQL command. My prob is that when I build this command from values in filteringitem.controls and apply it on the db, grid once more applies filter. And that's what I don' t want to. I need to interupt built-in filtering engine after I click on control that fires filtering command.
0
Elliott
Top achievements
Rank 2
answered on 19 Apr 2013, 07:28 PM
I had to suppress the filtering, too
first, intercept the FilterCommand
Protected Sub rgStores_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgStores.ItemCommand
    Dim gdItem As GridDataItem = Nothing
    Dim gfItem As GridFilteringItem = Nothing
    Dim OneofaKind As Pair
    ' Dim TableName As String = String.Empty
 
    ' TableName = e.Item.OwnerTableView.Name
    ' updates done in code-behind of user control
    Select Case e.CommandName
        Case "PerformInsert"
 
        Case "Edit"
 
        Case "Filter"
            gfItem = DirectCast(e.Item, GridFilteringItem)
            OneofaKind = DirectCast(e.CommandArgument, Pair)
            LookAtFilter(gfItem, OneofaKind)
        Case "Update"
 
        Case "Delete"
 
    End Select
End Sub

the CommandArgument is a "Pair" object
Private Sub LookAtFilter(gfItem As GridFilteringItem, APair As Pair)
    Dim ColumnFiltered As Object
    Dim txtTypeID As TextBox
    Dim sb As StringBuilder
 
    ColumnFiltered = APair.Second
    If ColumnFiltered = "TypeID" Then
    Else
        Exit Sub
    End If
    txtTypeID = DirectCast((gfItem)(ColumnFiltered.ToString()).Controls(0), TextBox)
    If IsNumeric(txtTypeID.Text) Then
        If CInt(txtTypeID.Text) >= -1 And CInt(txtTypeID.Text) <= 4 Then
        Else
            txtTypeID.Text = ""
        End If
        Exit Sub
    End If
    txtTypeID.Text = SetPowerBuyType(txtTypeID.Text.ToString)
End Sub

what is going on here is that I replaced the numeric value in the column of the grid with a value from an XML file
the filter is looking for the value so on a filter I basically need to reverse the process
the Pair.First is the type of filter - EqualTo,IsEmpty,etc

0
Jan
Top achievements
Rank 1
answered on 22 Apr 2013, 07:59 AM
Sorry for late reply but weekend .o)

I've tried this proposed solution but after I did some of my actions then grid applied its own built-in filtering. And that's what I don't want to.
0
Elliott
Top achievements
Rank 2
answered on 22 Apr 2013, 01:34 PM
I have successfully overridden the filtering twice - if you want to completely override the filtering then can't you turn off the filtering on the grid itself and manipulate the FilterExpression of the grid?  If you want to change the functionality of the grid's filtering (like replacing one value in the filter textbox with another) then handle the Filter command, identify the column and make your necessary code changes.  I looked for a binding statement anywhere - and I didn't have to.
0
Jan
Top achievements
Rank 1
answered on 22 Apr 2013, 02:08 PM
Thank You Marianne.

I'd like to completely override filtering. But I hope that it is possible to use filtering row in grid for it.
Unfortunately I don't know any way to do it and I will have to do it via another functionality like a RadFilter.
0
Kostadin
Telerik team
answered on 24 Apr 2013, 08:26 AM
Hello Jaroslav,

I would suggest you to review the following help articles which could prove helpful in your scenario.
Operating with the FilterExpression of Telerik RadGrid Manually
Custom Option for Filtering (FilterListOptions -> VaryByDataTypeAllowCustom)
Custom Filter Options with Handling

Greetings,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jan
Top achievements
Rank 1
answered on 24 Apr 2013, 08:28 AM
I'd like to thank you all with your suggestions. Because we have to work with millions of records I had to write own filtering functionality and we do not use built-in filtering now.
0
Daryl
Top achievements
Rank 1
answered on 15 May 2013, 03:10 PM
I had a similar issue where I didn't want to use the RadGrid's built in filtering but still wanted the filter controls to show.  I did the following just before setting the datasource in the NeedDataSource event and it worked for me.  It also got rid of the case sensitivity issue.

RadGrid1.MasterTableView.FilterExpression = "";
Tags
Grid
Asked by
Jan
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Jan
Top achievements
Rank 1
Kostadin
Telerik team
Daryl
Top achievements
Rank 1
Share this question
or