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

Dynamic creation of columns and filter sizes

2 Answers 17 Views
Grid
This is a migrated thread and some comments may be shown as answers.
romulo~
Top achievements
Rank 1
romulo~ asked on 11 Nov 2014, 07:30 PM
Hello,

I'm using a RadGrid in an user control and for each different datasource I create columns. The columns I'm creating also use the filter feature.

The only problem is that the filters, in some cases, are small or bigger compared to the column it's on.

I mean, suppose a column have 200px, sometimes the filter have 50px or 300px. This behavior is pretty strange... Is there a way to make the filters have the same size as the columns?
 
Also, the columns allow resizing so another problem is that the filters have a fixed size. Can they be configured to have a dynamic size like the column it is in?

2 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 14 Nov 2014, 09:43 AM
Hello,

You can use the GridFilteringItem and find the controls for each column and set specific width to each of the controls.

However, if you handle the OnItemCreated event of the grid you could use the following example, which will traverse through each cell in the GridFilteringItem and will set a percentage width to each of the controls:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (!RadGrid1.AllowFilteringByColumn || !(e.Item is GridFilteringItem)) return;
 
    var filteringItem = e.Item as GridFilteringItem;
    foreach (GridColumn c in from GridColumn c in RadGrid1.Columns where c.Visible && c.SupportsFiltering() select c)
    {
        ((WebControl)filteringItem[c.UniqueName].Controls[0]).Width = Unit.Percentage(80);
    }
}

Please give this a try and see if the result meets your exact requirements. 


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
romulo~
Top achievements
Rank 1
answered on 19 Nov 2014, 05:22 PM
Thanks for the reply

I just tried that and worked nicely. 
Tags
Grid
Asked by
romulo~
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
romulo~
Top achievements
Rank 1
Share this question
or