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

Show filtering on only certain columns

5 Answers 922 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 23 Aug 2012, 03:54 PM
Hello,  I'm a bit of a scrub when it comes to the radgrid controls, but slowly I am learning.  

Currently I have a radgrid that loads it's data everytime on runtime (essentially I have nothing in my aspx file except for the creation and it calling NeedDataSource) and everything that get's formats, and loads the data in NeedDataSource.  Thus it's run everytime a refresh is done or a different page is called.  I think there's a much more efficient way of doing it than my way so suggestions on this are more than welcome, however my main current issue is below.

I have about 18 columns currently,  I want people to be able to filter on 6 of them and to not be able to filter (to have the filter menu just not appear) on 12 columns.  Ideally how would I do this?

(I'm thinking I need to somehow grab the column name/id in the cs, check it against the 12 column names/ids and set the property to hide but am having problems with it.)

Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Aug 2012, 04:25 AM
Hi John,

Try setting ShowFilterIcon as false for the columns that doesn't need filtering.
aspx:
<telerik:GridBoundColumn ShowFilterIcon="false" DataField="LastName" HeaderText="LastName" UniqueName="LastName" />

Thanks,
Shinu.
Johnny
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 27 Apr 2023, 07:22 AM

This only disables the filter icon next to the textbox. To hide the whole textbox: AllowFiltering="false"
0
John
Top achievements
Rank 1
answered on 24 Aug 2012, 11:37 AM
Can't do this in the aspx because the columns are automatically generated by the dataset.

If I define the columns in the aspx master table will it be smart enough to match the data from the dataset and fill in the rows?  As maybe that would work.

Currently I do your equivalent in the aspx.cs file

protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    if (e.Column.UniqueName == "Jan")
    {
        e.Column.ShowFilterIcon = false;
        e.Column.AutoPostBackOnFilter = true;
    }
}

However this just results in the attached, and I'd like that cell to be completely empty (not able to put in text).
2
John
Top achievements
Rank 1
answered on 24 Aug 2012, 06:10 PM
UPDATE:  Figured it out,  I had to turn off AutoGenerateColumns, create the columns myself and then have AllowFiltering="false" for each of those columns. 
0
Venkata Reddy
Top achievements
Rank 1
answered on 19 Sep 2012, 06:39 PM
i have a similar situation where i want to hide filter icons for some columns for my AutoGenerated Telerik Control.

in my  .cs file i am using these statement to hide the filter icons and also hide the text box.

protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    if (e.Column.UniqueName == "XYZ")
                {
                    e.Column.ShowFilterIcon = false;
                    e.Column.FilterControlWidth = 0;
                }
}

i am able to hide the icons but not the text box fully. 
here is the how it is displaying (as shown in the pic).


-1
Antonio Stoilkov
Telerik team
answered on 24 Sep 2012, 10:16 AM
Hello,

You could achieve your scenario by setting the column AllowFiltering property to false as it is shown below. Note that you should cast the column to GridBoundColumn to access the AllowFiltering property.
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    if (e.Column.UniqueName == "XYZ")
    {
        GridBoundColumn boundColumn = e.Column as GridBoundColumn;
        if (boundColumn != null)
        {
            boundColumn.AllowFiltering = false;
        }
    }
}

All the best,
Antonio Stoilkov
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.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
John
Top achievements
Rank 1
Venkata Reddy
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or