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

radgrid GridDateTimeColumn using EnableRangeFiltering

8 Answers 280 Views
Grid
This is a migrated thread and some comments may be shown as answers.
regina
Top achievements
Rank 1
regina asked on 10 Aug 2012, 12:32 PM
Is there a way to narrow this column? right now the range filter is quite wide is there a way to stack the datepickers instead of having them appear side by side, this takes up an enourmous amount of grid real estate.  I have tried filtercontrolwidth and it had no effect at all.  Please assist, thank you.

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Aug 2012, 12:48 PM
Hi,

Try accessing the column in ItemCreated event and set its width as shown below.
C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridFilteringItem)
 {
   GridFilteringItem item = (GridFilteringItem)e.Item;
   RadDatePicker pkr = (RadDatePicker)item["UniqueName"].Controls[0];
   pkr.Width = Unit.Pixel(30);
 }
}

Thanks,
Princy.
0
regina
Top achievements
Rank 1
answered on 10 Aug 2012, 01:05 PM
Princy I really appreciate the prompt answer thank you.
I am getting the following error with the code suggested, Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'Telerik.Web.UI.RadDatePicker'.  There are other filters on the grid, however in this instance the datepicker filter is on the first column, this will not be the case in all instances so I need to identify it properly.  In the unique name I used the unique name of the of the

GridDateTimeColumn   ,
if this is not correct how do I discern or set, the unique name of the datepicker
thank you.

0
regina
Top achievements
Rank 1
answered on 10 Aug 2012, 01:11 PM
further investigation indicates the item["UniqueName"].Controls[0];
is the literal containing the text "From:"

And I am using the ajax build or rather close to it, there may be one newer now, but I am using the built in feature, so I am not nameing the datepicker.

I also tried this to see if I just needed to keep going till I got to a filter item that was datepicker, I put a breakpoint on the pkr.width line but it never hits for a datepicker
try{
              GridFilteringItem item = (GridFilteringItem)e.Item;
              RadDatePicker pkr = (RadDatePicker)item["EntryDate"].Controls[0];
              pkr.Width = Unit.Pixel(30);
              }
                  catch(Exception donothing){}
0
Princy
Top achievements
Rank 2
answered on 13 Aug 2012, 07:22 AM
Hi,

Unfortunately I cannot replicate the error on my end. Here is the full code that I tried which worked as expected.
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" AutoGenerateColumns="False" AllowFilteringByColumn="true" OnItemCreated="RadGrid1_ItemCreated">
 <MasterTableView>
   <Columns>
    <telerik:GridDateTimeColumn EnableRangeFiltering="true" FilterControlWidth="20px" UniqueName="EntryDate" DataField="BirthDate"></telerik:GridDateTimeColumn>
   </Columns>
 </MasterTableView>
</telerik:RadGrid>
C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridFilteringItem)
 {
   GridFilteringItem item = (GridFilteringItem)e.Item;
   RadDatePicker pkr = (RadDatePicker)item["EntryDate"].Controls[0];
   pkr.Width = Unit.Pixel(30);
 }
}

Thanks,
Princy.
0
regina
Top achievements
Rank 1
answered on 13 Aug 2012, 12:08 PM
Princy,
what build number are you using?  As this is new functionality perhaps I need to update my ajax build?  This is not something I want to do unless I have to so please let me know.
0
Princy
Top achievements
Rank 2
answered on 14 Aug 2012, 05:45 AM
Hi,

I tried your scenario in the version 2012.2.607.40. By setting the FilterControlWidth property from aspx, I was able to 
reduce the width of GridDateTimeColumn when filtering was enabled. Another approach to reduce the width is by accessing
it as RadDatePicker in ItemCreated and as explained in the code. Please elaborate your scenario if it doesn't helps.

Thanks,
Princy. 
0
regina
Top achievements
Rank 1
answered on 14 Aug 2012, 12:25 PM
ok so doing this does change the actual size of the filter date boxes itself and that does help though only marginally.  What I am trying to force the filter to do is wrap so the filter to/from will be stacked.  This is a specific request from my customer I am doing development for and this is what I am not able to do and the true root of my scenario.  how do I get the filter to stack instead of presenting side by side.  I have tried altering the itemstyle and the headerstyle on both width and wrap set to true and this has no effect.
0
Pavlina
Telerik team
answered on 17 Aug 2012, 01:13 PM
Hi Regina,

Browsers wrap text by default in the data cells. If you need to wrap the filter textboxes, then use the code snippet below:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 
    GridFilteringItem filteringItem = e.Item as GridFilteringItem;
    if (filteringItem != null)
    {
        LiteralControl literalTo = filteringItem["ShippedDate"].Controls[3] as LiteralControl;
        literalTo.Text = "<br />To";
    }
}

Kind regards,
Pavlina
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
regina
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
regina
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or