This is a migrated thread and some comments may be shown as answers.
Filteration in GridView
10 Answers 278 Views
This is a migrated thread and some comments may be shown as answers.
Kamlesh
Top achievements
Rank 1
Kamlesh asked on 28 Nov 2008, 04:19 PM
How can i add filteration on my Gridview and how to do paging

I need a filter textbox on each column.  

What you have already done in GridView for Ajax. I want same functionality.

Kamlesh

10 Answers, 1 is accepted

Sort by
0
Hristo Deshev
Telerik team
answered on 28 Nov 2008, 04:42 PM
Hi Kamlesh,

Right now we do not offer special paging support, and you have to do a custom pager that would let you fetch the data for the new page, and rebind the grid. This blog post outlines the heart of the technique for WPF, and the same approach is applicable in Silverlight.

As far as the filtering UI is concerned, RadGridView for Silverlight offers filtering support via its data object model -- check the FilterDescription property. The downside is that, for the current CTP release, you have to do your own filtering UI that will create a FilterDescription object and feed it to the RadGridView control. The official RadGridView release in Q1 2009 will have Excel-like filtering UI support, and we will be implementing the one-textbox-per-column filtering UI (RadGrid for ASP.NET AJAX style) afterwards.

Kind regards,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kamlesh
Top achievements
Rank 1
answered on 29 Nov 2008, 07:25 AM
Can we add text box to the column header.
0
Jimmy
Telerik team
answered on 01 Dec 2008, 02:35 PM
Hello Kamlesh,

Yes it is possible to add TextBox to the header of the column. To do this you will need to make a custom template for the GridViewHeaderCell visual control.

Below is an example in XAML of how this could be done. I presume that you will need the header text visible as well as an extra textbox that you need added in, so I will put both in a StackPanel.

<Style TargetType="{x:Type telerik:GridViewHeaderCell}"
        <Setter Property="Template" > 
         <Setter.Value> 
           <ControlTemplate  TargetType="{x:Type grid:GridViewHeaderCell}"
           <StackPanel Orientation="Horizontal"
                <ContentPresenter /> 
                <TextBox /> 
          </StackPanel> 
           </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
</Style>  

Cheers,
Jimmy
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kamlesh
Top achievements
Rank 1
answered on 01 Dec 2008, 03:43 PM
Thanks

I have made custom template for the GridViewHeaderCell as mentioned.

I am creating the GridView dynamically 

GridViewDataColumn

 

col = new GridViewDataColumn();

 

 

col.UniqueName = source[i].FieldName;

col.HeaderCellStyle = LayoutRoot.Resources[

"ColumnHeaderStyle"] as Style;  

 

 

col.HeaderText = source[i].Caption; 

Is this correct?

But this code is not working. Are talking about GridView for Silverlight not WPF.

Thanks
Kamlesh

 

 

0
Nedyalko Nikolov
Telerik team
answered on 03 Dec 2008, 03:02 PM
Hello Kamlesh,

Setting CellStyle and HeaderCellStyle properties for the RadGridView for Silverlight will be available with our first beta release which is scheduled for the mid-December. Then you should be able to set these properties safely.

The issue with setting these styles is a Silverlight platform restriction "Style can be set only once!!!"
For reference you can see this article.

The style we have sent to you earlier still apply perfectly with WPF version.
For Silverlight style's xaml should look like this:

<Style TargetType="telerik:GridViewHeaderCell">  
        <Setter Property="Template" >  
         <Setter.Value>  
           <ControlTemplate  TargetType="grid:GridViewHeaderCell">  
           <StackPanel Orientation="Horizontal">  
                <ContentPresenter />  
                <TextBox />  
          </StackPanel>  
           </ControlTemplate>  
         </Setter.Value>  
        </Setter>  
</Style>  


Greetings,
Nedyalko Nikolov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Corey Gaudin
Top achievements
Rank 1
answered on 19 Dec 2008, 06:12 PM
Do you have a code example of this I can follow. I have been trying for the life of me to get this grid to do Filtering with a simple Textbox under each Header column. The example above allows me to set each of the HeaderCellStyle for each GridViewDataColumn specified to have this, but how do you grab the Data Column from the Textbox? I cant bind it to the TemplateBinding UniqueName in the style. How would you do this?

Please give me an example of the entire process on one column filtering. I understand the FilterDescription Custom Class and setting this to the Grid, but the problem is I cant get how to pass the column you are filtering on to an event to add this Filter Description to the Grid itself.

IF not this way, can you customize the Header Row using a ControlTemplate on that individual Header Column? I dont want to use the Style (if I can do this, I can set the Tag Manually and that would give me the Column this filter belongs to).
0
Corey Gaudin
Top achievements
Rank 1
answered on 19 Dec 2008, 06:12 PM
Duplicate - because the site kept erroring out.
0
Corey Gaudin
Top achievements
Rank 1
answered on 19 Dec 2008, 06:13 PM
duplicate
0
Corey Gaudin
Top achievements
Rank 1
answered on 19 Dec 2008, 06:14 PM
Duplicate
0
Rosi
Telerik team
answered on 20 Dec 2008, 02:28 PM
Hi Corey,

Please find the attached sample project illustarting how to achieve the desired behavior.

Steps to implement it are:

1.Define a control  template for the HeaderCell:
  <telerikGridView:GridViewDataColumn HeaderText="CompanyName"   UniqueName="CompanyName" > 
                    <telerik:GridViewColumn.HeaderCellStyle> 
                        <Style TargetType="telerikGridView:GridViewHeaderCell">  
                            <Setter Property="Template">  
                                <Setter.Value> 
                                    <ControlTemplate TargetType="telerikGridView:GridViewHeaderCell">  
                                        <TextBox   Width="200" TextChanged="TextBoxSearch_TextChanged"  ></TextBox>  
                                    </ControlTemplate> 
                                </Setter.Value> 
                                </Setter> 
                        </Style> 
                    </telerik:GridViewColumn.HeaderCellStyle> 
                </telerikGridView:GridViewDataColumn> 

2.In the code behind the CustomFilterDescription class inherits the FilterDescription and overrides the SatisfiesFilter method to implement row filtering for the column with filter value given by the TextBox.

3.Subscribe to the TextChange event of the TextBox and set the FilterDescription property of the RadGridView in its event handler:
private void TextBoxSearch_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)  
        {  
            TextBox txtBox = (TextBox)sender;  
            if (txtBox.Text == String.Empty)  
            {  
                this.radGridViewFirstLook.FilterDescription = null;  
            }  
            else 
            {  
                this.radGridViewFirstLook.FilterDescription = new CustomFilterDescription(txtBox.Text);  
            }  
        } 

Hope this helps.

Regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Kamlesh
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
Kamlesh
Top achievements
Rank 1
Jimmy
Telerik team
Nedyalko Nikolov
Telerik team
Corey Gaudin
Top achievements
Rank 1
Rosi
Telerik team
Share this question
or