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

Numeric Column Percent is not divided by 100

37 Answers 1299 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 27 May 2009, 12:51 AM
Hi,

I am using a RadGrid (Q1 2009) to edit a column of "percentages" and I am not getting the behaviour I would expect - though my expectation may be wrong.

The values stored in the database are "factors" i.e. 0.015 (for a number which the user should "see" as 1.5%), and, if I set the DataFormatString to be {0:p4} my values are displayed as expected (they are multiplied by 100 and displayed to 4 decimal places).

I would like the user to edit the values in the same way i.e. they edit/enter 12.5600% and what gets written to the database is 0.125600 and what is then re-displayed is 12.5600 %. But leaving the NumericType as "Number" ignores the DataFormatString (the value is displayed as 0.1256), and setting the NumericType to "percent" just results in a % sign being appended to the unmultiplied number (so they have to edit it as 0.125600%) which is frankly wrong.

It seems a little odd to me - is this intentional (by design), is there anything I can do to easily fix it?

37 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 28 May 2009, 10:05 AM
Hello Andrew,

This issue has already been reported to us. We will think about a way to improve this behavior in the future.

In the meantime, you can use the following workaround:

1. When displaying the edit form, you can modify the value, which is retrieved from the database (e.g. multiply it by 100) in the RadGrid ItemDataBound event.

2. When the edit form is submitted, there are two scenarios:

2a) If you are using RadGrid automatic operations, you have to subscribe to the Updating event of the datasource control and modify the submitted percentage value (divide it by 100).

2b) Otherwise, you have to use the RadGrid OnUpdateCommand and OnInsertCommand events to modify the submitted percentage values before updating the database.


All the best,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Andrew
Top achievements
Rank 1
answered on 29 May 2009, 10:00 AM
Hi Dimo,

Thanks for the reply, and yes your solution would work, but again this means that I have to fiddle about in code behind for all such cases.

In the end it is easier (in this one) to leave the edit as a number (factor), and just display as a percentage on the grid, I am sure the users can get used to this. Then I can wait for a fix.

If it helps, the ideal fix would be that the editor picks up the Format that has been selected "{0:p4}" and behaves accordingly - i.e. it multiplies by 100, appends a % sign, limits the number fo decimal places to 2 (i.e. 4 when dispalyed divided by 100) and so on. There will need to be a way of overriding this behaviour when the developer wants to allow the user to do something different (e.g. possibly the user is allowed to enter more than 2 (4) decimal places), but in general the format used for display shoudl be the default for editing.

0
Dimo
Telerik team
answered on 29 May 2009, 01:39 PM
Hello Andrew,

Thank you for sharing your opinion. You are right that the Grid should be able to display a percentage number (0 < number < 1) in the same fashion in view and edit mode, so we will develop this behavior for a future version.

Best wishes,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Kenneth Mazur
Top achievements
Rank 1
answered on 17 Sep 2009, 05:59 AM
Any update on this?  When I show the RadNumericTextBox on an edit form, it displays the percentage correctly, ie, 6%.  Once it is shown in the RadGrid, it shows up as 600%.  My short term solution is to set the DataFormatString property as follows:

Dim tBC As New GridBoundColumn
tBC.DataFormatString = "{0:N2} %"
0
Dimo
Telerik team
answered on 17 Sep 2009, 12:20 PM
Hi Kenneth,

I am afraid this feature has not been implemented yet. It is in our to-do list, but currently we are working on taks with higher priority.

Greetings,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Robert
Top achievements
Rank 1
answered on 11 Feb 2010, 06:49 PM
Has there been an update for this?
0
Dimo
Telerik team
answered on 16 Feb 2010, 04:02 PM
Hello Robert,

The feature has not been implemented yet. I have logged it in our public issue tracking system, so that you will be able to track any progress. The PITS item ID is 1038.

http://www.telerik.com/support/pits.aspx

Greetings,
Dimo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ray
Top achievements
Rank 1
answered on 23 May 2010, 10:19 PM
Mmm,

I reported this over a year and ahalf ago..

the last reponse
"Posted on on May 27, 2009 CC:
Hello Ray,

Thanks for the feedback, you have raised an interesting point. We will think about it.

I have updated your Telerik points.

Greetings,
Dimo
the Telerik team "

The above, simply demonstrates that basic bugs ( this is realy not a feature request, but complience with the dotnet framework) simply does not get done, they seem to want to develop more "new products" rather than fix existing ones..

Hence, dont hold your breath for a solution.. PITS is simply a nother way of saying we dont want to do anything, so stop asking us to fix bugs..

Ray

0
Miguel
Top achievements
Rank 1
answered on 31 Oct 2011, 05:27 PM
Hello Telerik Team

Any updates on this issue?

Thanks

Miguel
0
Vasil
Telerik team
answered on 02 Nov 2011, 04:10 PM
Hello Miguel,

We did further research on the issue and I am afraid that we could not change this behaviour.
You could the workaround discussed before in the second post.

The limitation comes from the fact that DataFormatString could be something that is not suitable for showing in the edit form and not reversible. For example like:
DataFormatString="{0:imaginary unit 000 myDecimalSeparator 00 }"
In this case, you would get properly all values when they are displayed in the grid. However it is expected in the edit form to be able to enter the value exact way as it will be saved in the database. The grid could not know the reverse format (if such exist) that has to be applied for value like:
imaginary unit 334 myDecimalSeparator 12
In order to convert it to 334.12 or to 0.33412 or even to 12*2^334 (which would be possible for our imaginary unit.) And because it could not know, the best that the Grid could do is to pass it without change. So it is up to you to change the value manually.

You probably expect this to work for percents, as they are something common and used daily. However we can't add an exception for the percents, because this will breaks all currently working applications that expects this behaviour.

All the best,
Vasil
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
Ray
Top achievements
Rank 1
answered on 02 Nov 2011, 08:52 PM
Vasil,
" I am afraid that we could not change this behaviour"
This is a joke right?

Simply implement the work around, or do what 100% of  other dot net controls do..
I.e implement the dotnet framework, all percentages MUST be 0 ->1 this is how the dotnet framework works, dont make up something which breaks the framework.

The stuff below is simply waffle..



0
Vasil
Telerik team
answered on 03 Nov 2011, 01:38 PM
Hello Ray,

In the framework itself 0.4 does not mean 40 percents when parsing. The developer who manages the data should know if it works in percents or not. For example the constructor of Unit (which is part of the framework) will not multiply the value, and it will use it as it is in original state:
Unit u1 = Unit.Percentage(75);
string u1AsString = u1.ToString(); //u1AsString will be "75%"
double u1AsDouble = u1.Value; // the value will be "75.0"
 
Unit u2 = Unit.Percentage(0.4);
string u2AsString = u2.ToString();//u1AsString  will be "0.4%"
double u2AasDouble = u2.Value; // the value will be 0.4
So I believe the Kenneth's solution is best for use in this case. Just store the values in your Database in range from 0 to 100. And using "{0:N2} %" for DataFormatString. This will allow you to edit them in the edit form like percents.

Best wishes,
Vasil
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
Ray
Top achievements
Rank 1
answered on 13 Nov 2011, 10:59 PM
"In the framework itself 0.4 does not mean 40 percents when parsing"

I see the problem..
In the framewerk ( see andrews orignal request)..  percentages are ALWAYS AND ONLY 0->1..
If you cannot see this than itelerick will never get a solution that works within dotnet..
Unit has absolutely nothing to do with the issue at hand..

Just fix the problem, same as 100% of any dotnet controls.. telerik si the only control provider which seems unable to make a simple percentage work in their own grid..

0
Veli
Telerik team
answered on 14 Nov 2011, 01:40 PM
Hi guys,

Let me clarify what options you have for representing your percentages in RadGrid:

1. Specifying DataFormatString in your GridNumericColumn settings:

DataFormatString="{0:p2}"

This property is only used when formatting the visible values in read-only cells. A database value of 0.52 will be displayed as 52.00% in the non-editable cells of the numeric column. The property does not affect the RadNumericTextBox instance rendered in the edited items.

2. Specifying NumericType in your GridNumericColumn settings:

NumericType="Percent"

This property affects only the numeric textbox in the edit form when you specify Percent. Using this setting, RadNumericTextBox will show a percent sign in the numeric field without modifying the original value. A database value of 0.52 will display as 0.52 % if you have specified NumericType="Percent", and will stay as 0.52 if you use the default value (NumericType="Number").

3. Implement a custom column that will take care of the percent conversion and will allow your users to enter a value between 0 and 100. When extracting the value from the column, the former will be returned as a floating point value between 0 and 1. This is easier than you might think. We need to subclass GridNumericColumn to set a few required settings, and then subclass GridNumericColumnEditor to setup the numeric textbox correctly. The complete source code of this custom percent column is attached. Including it in your grid is very easy. First register your namespace:

<%@ Register Namespace="GridCustomColumns" TagPrefix="grid" %>

And then use your percent column just like any other column:

<telerik:RadGrid>
    <MasterTableView>
        <Columns>
            <grid:GridPercentColumn>
            </grid:GridPercentColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

The result is a percent column that displays values from 0 to 1 as integers from 0 to 100 and also allows users to enter values from 0 to 100 keeping the conversion transparent.


Veli
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
Ray
Top achievements
Rank 1
answered on 14 Nov 2011, 11:09 PM

"RadNumericTextBox will show a percent sign in the numeric field without modifying the original value. A database value of 0.52 will display as 0.52 % if you have specified NumericType="Percent",

Good description of the issue and defect..
In order to amke any grid work, one need to sue the framework 0->1 stanadrd..
If one uses your percentage control within Your grid, one gets the wrong displayed value as you demonstate above.
FULL STOP..

Been over a year and no progress on this basic defect..




0
Veli
Telerik team
answered on 15 Nov 2011, 08:39 AM
Have you tried the custom column I have provided in my previous post? I believe it solves the issue you are describing and you can use that in your project.

Veli
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
Ray
Top achievements
Rank 1
answered on 15 Nov 2011, 09:53 PM
Thanks but you mis understand..

I just want the controls to work out fo the box, i.e percentage control with your grid..
Very basic stuff..

I have been hacking up fixes.. for this defect for many years ARG!!
You suggestion is just another of the many..
JUST FIX IT... once and for all; to save us ALL a lot of work fixing your broken control on each and evry page we use it..




0
Callum
Top achievements
Rank 1
answered on 15 Nov 2011, 11:25 PM
Hi,

This issue is also causing me a major headache.  I have tried your example custom column class and it breaks when I try to do a postback.  I have an example application that I would like to attach, however this thread won't let me do that, so here is the stack trace for the exception I get:

[GridException: Cannot create column with the specified type name: GridPercentColumn] Telerik.Web.UI.GridColumnCollection.CreateColumnFromTypeName(String columnTypeName) +1520 Telerik.Web.UI.GridColumnCollection.System.Web.UI.IStateManager.LoadViewState(Object savedState) +434 Telerik.Web.UI.GridTableView.LoadStructureState(Object SavedStructure) +366 Telerik.Web.UI.RadGrid.LoadTableViewStructure(IEnumerator stateEnumerator, GridTableView tableView) +101 Telerik.Web.UI.RadGrid.LoadViewState(Object savedStateObject) +281 System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +187 System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +148 System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +225 System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +148 System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +225 System.Web.UI.Page.LoadAllState() +312 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +747 



I have to say after reading the history of this issue I'm appalled with Telerik's handling of it.  I agree with Ray, the behavior of this control should be consistent with the globally accepted standard - not only for that reason, but more importantly because we can't use percentage-based columns consistently between edit mode and read-only mode.  Let me explain our situation:

We are in the process of trialling an upgrade of our application from the Classic RadControls to the latest Prometheus controls (on .NET 4).  Previously with the Classic controls, all we had to do was set the DataFormatString property on the GridBoundColumn object and the formatting would be consistent between edit mode and read-only mode.  Now in the new controls that behavior has been stripped and the DataFormatString is no longer applied when in edit mode.  This has been brought up in a previous post (see here) and answered such that we should apply the data format string manually to every grid in the application through the grid's ItemDataBound event - a stupid idea given that we probably have 50+ grids in our application which would need this change.

The suggested alternative to this is that we use GridNumericColumn.  This would be an acceptable solution, however when using Percent as the numeric type there is now an inconsistency between how the datasource needs to present values between edit mode and read-only mode.  Obviously our datasource can't be aware of what mode the grid cell is in so we would have to intercept this in the grid itself (again a stupid solution given the amount of grids we have in the application, and just shouldn't be necessary!!).

So finally Telerik provide a solution in the form of a custom column (which at the moment doesn't work) that in most developers minds would be considered a hack.  Say this solution does eventually work, this extra code now becomes code that is now managed by us.  What happens when Telerik make a change to the product which breaks this code?  I can be sure that Telerik's response will be that this code - although provided by them - is not part of the product so is not supported.  I mean what is the point in having a 3rd party product if we have to write custom code to fix deficiencies in the product??!!!

These comments are intentionally emotive, but have been seriously toned down from how I actually feel. For myself and the rest of the development community, that up until now have had nothing but praise for Telerik, a workable and sensible solution must be provided for this issue to restore our faith and continued use of this solution. Telerik team....over to you.
0
Callum
Top achievements
Rank 1
answered on 15 Nov 2011, 11:26 PM
Ignore this post, your server throws errors even when a post does work so this turned out to be a duplicate of my other one.  Oh and can I suggest that on your error page you don't say "Cheer up and get a free trial" when it's your free trial that's hacking me off in the first place.
0
Veli
Telerik team
answered on 16 Nov 2011, 10:11 AM
Hi Callum,

We cannot reproduce the error you have reported. We would surely like to look into this issue, if you manage to reproduce it again. If you can share some more info on your particular grid setup and column usage, we may be able to identify what's wrong.

As for "fixing" the numeric column, note that this would be a major breaking change affecting users that are already using the current column behavior. Instead, a property (turned off by default) can be introduced to alter the column behavior and use values from 0 to 1 for representing percentage.

In any case, you guys definitely have a say in what we build. I have notified the development team of this conversation and I believe they will consider your opinion. Additionally, I have created a PITS item for this feature where you guys can vote. Note that voting for this feature is important for us and is an effective way of influencing the decision to implement.

Veli
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
Callum
Top achievements
Rank 1
answered on 16 Nov 2011, 10:46 PM
Hi Veli,

Thanks for your reply.  I've created a separate thread so that I am able to upload my example application which reproduces the issue I'm experiencing with your sample GridPercentColumn, see the following link:

http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=483791

I understand that Telerik can't simply change the code and break existing uses, so the suggested solution of adding a PercentType property to the GridNumericColumn class is perfectly acceptable.  Thank you for moving this issue into the PITS area so it can be voted, but until either this development is done or the GridPercentColumn example works, we have no acceptable solution to this problem and as a result will not be upgrading from Classic to Prometheus (which also prevents us from upgrading from .NET 2 to 4!).

I notice that this issue has previously been moved there as item 1038 (mentioned here).  I'm unable to find this item in PITS and am wondering what votes it previously had.  Will the votes added to this previous item also count towards the new PITS item?

Regards
Callum
0
Veli
Telerik team
answered on 17 Nov 2011, 09:31 AM
Hi Callum,

The previous issue seems to have been removed from PITS due to getting insufficient interest. It got one vote which we can add to the votes of this newly created PITS item.

As for your issue with the custom column, you are creating your columns programmatically in the Page_Load method of the page. When creating custom column programmatically, you need to use RadGrid's ColumnCreating event to create new instances of custom columns on postback:

protected void EmployeeGrid_ColumnCreating(object sender, GridColumnCreatingEventArgs e)
{
    if (e.ColumnType == "GridPercentColumn")
    {
        e.Column = new GridPercentColumn();
    }
}

Using that event, RadGrid can now properly initialize your custom column. This should fix the problem.

Veli
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
Callum
Top achievements
Rank 1
answered on 17 Nov 2011, 09:25 PM

Hi Veli,

I see, that may be the case but again that puts us in the position of having to write code into every grid in the application to resolve this problem - a situation that is unacceptable to us (as I have already said).  It seems to be a common theme in many of the posts I've seen in this forum, that the suggested solution for fixing problems with the grid is for the developer to patch it up by implementing some code in a grid event.  Is it not recognized by Telerik that whenever this is required, that the developer may have to go through every grid in their application and do this?  Do you realize how much pain that causes your community of developers?  In my mind this is not acceptable practice and I question whoever is architecting this stuff as to whether they understand this.  PLEASE provide a solution where I don't have to write code into every grid in my application.  Until this happens we are not prepared to upgrade from the Classic controls and will have to look for a product that understands this simple concept.

Regards

Callum

0
Veli
Telerik team
answered on 18 Nov 2011, 09:14 AM
PLEASE provide a solution where I don't have to write code into every grid in my application.

Currently, any solution we may provide involves writing some amount of code in every grid. If the dev team decides to implement the proposed approach, there will be a single property you will have to set in each percentage formatted GridNumericColumn.

Veli
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
Callum
Top achievements
Rank 1
answered on 20 Nov 2011, 11:26 PM
I understand your point but actually with the way we have written our application that won't be necessary for us if your dev team implements this feature.  In our application, the users are able to configure exactly what fields will appear on any grid they can see.  Because of this, when our code builds a grid on a screen, it uses central logic that reads this configuration and determines what value to apply to the various properties (DataType, DataFormatString, HeaderText, ReadOnly etc) for each column.  Currently that code looks something like this:
public void SetGridColumns(RadGrid grid, GridConfig gridConfig)
{
    foreach (GridAttribute gridAttribute in gridConfig.GridAttributes)
    {
        this.AddGridBoundColumn(grid, gridAttribute);
    }
}
 
protected void AddGridBoundColumn(RadGrid grid, GridAttribute gridAttribute)
{
    GridBoundColumn gridColumn = new GridBoundColumn();
    grid.MasterTableView.Columns.Add(gridColumn);
 
    gridColumn.UniqueName = gridAttribute.ID;
    gridColumn.HeaderText = gridAttribute.SoftName;
    gridColumn.DataType = gridAttribute.GetType();
    gridColumn.DataField = gridAttribute.ID;
    gridColumn.DataFormatString = gridAttribute.DataFormatString;
}

So what we do for each grid we put on a form is turn off the AutoGenerateColumns property and instead call the above SetGridColumns method (which resides in a class called GridBinder that is accessible to all web forms) from the non-postback section of the Page_Load event.

With the proposed change (and after upgrading from Classic to the new version of RadControls) the code would look more like this:
public void SetGridColumns(RadGrid grid, GridConfig gridConfig)
{
    foreach (GridAttribute gridAttribute in gridConfig.GridAttributes)
    {
        this.AddGridBoundColumn(grid, gridAttribute);
    }
}
 
protected void AddGridBoundColumn(RadGrid grid, GridAttribute gridAttribute)
{
    GridBoundColumn gridColumn = null;
    if (gridAttribute.GetType() == typeof(decimal))
    {
        gridColumn = new GridNumericColumn();
    }
    else
    {
        gridColumn = new GridBoundColumn();
    }
    grid.MasterTableView.Columns.Add(gridColumn);
 
    gridColumn.UniqueName = gridAttribute.ID;
    gridColumn.HeaderText = gridAttribute.SoftName;
    gridColumn.DataType = gridAttribute.GetType();
    gridColumn.DataField = gridAttribute.ID;
    gridColumn.DataFormatString = gridAttribute.DataFormatString;
 
    if (gridColumn is GridNumericColumn)
    {
        GridNumericColumn numericColumn = gridColumn as GridNumericColumn;
        switch (gridAttribute.DataType)
        {
            case DataTypeEnum.Percentage:
                numericColumn.NumericType = NumericType.Percent;
                numericColumn.GridPercentType = GridPercentType.FloatingPoint;
                break;
            case DataTypeEnum.Money:
                numericColumn.NumericType = NumericType.Currency;
                break;
            case DataTypeEnum.Decimal:
                numericColumn.NumericType = NumericType.Number;
                break;
        }
    }
}

Hopefully you can now see that with this type of solution we wouldn't need to write code into every grid of the application to resolve this problem.
0
Veli
Telerik team
answered on 21 Nov 2011, 02:01 PM
Understood. Dev team is getting the feedback. It all depends on the PITS voting now.

Veli
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
matt
Top achievements
Rank 1
answered on 09 Sep 2013, 08:52 PM
Telerik,

I came across this post while researching the same exact problem -- this is a bug. Percentages are often stored in 0-1 format in .NET and our underlying SQL db. It makes zero sense to have the RadNumericColumn have a NumericType="Percent" mode that simply shows a "%" sign. I'm forced to use the 0:p2 dataformatstring property...but this doesnt help on edit/filter textboxes, which for filtering improperly require one to type in this:

.95 %

...when trying to filter on 95 %, as the grid shows when using 0:p2 format.

It's a bug. It should have been fixed years ago. I'm disappointed that it hasn't.
0
Vasil
Telerik team
answered on 10 Sep 2013, 07:18 AM
Hello matt,

Few releases ago we had introduced the DbValueFactor property of both RadNumericTextBox and GridNumericColumn. It should do the trick in your case.
Set DbValueFactor=100 for your column. And when you bind to database value like 0.15 it will be seen in the numeric text box as 15.
By default the factor is 1.

Regards,
Vasil
Telerik
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 the blog feed now.
0
Mike
Top achievements
Rank 1
answered on 01 Aug 2014, 04:32 PM
DbValueFactor does not get applied to edit/filter textbox values, so its still necessary to filter on 0.95 to find values displayed in the grid as 95 % when filtering. Annoying and a bug as has been pointed out in this thread many times.
0
Vasil
Telerik team
answered on 06 Aug 2014, 01:21 PM
Hello Mike,

Indeed the property apply only for the NumericTextBox in the edit item. The inputs in the filter item will not be affected. We will research it further and if it is possible will improve it.

Regards,
Vasil
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
matt
Top achievements
Rank 1
answered on 13 Aug 2014, 09:49 PM
thanks. definitely needed.
0
Alessandro
Top achievements
Rank 1
answered on 31 Jul 2018, 10:09 AM

Here is what I came up with. Just add a GridNumericColumn with its NumericType=Percent, or adapt the code to better fit your needs. Since the item is correctly evalueted I expected the filtering item to work out of the box tho.

 

```
public partial class MyClass
{
    private bool filtered = false;

    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (filtered)
        {
            var arr = new GridColumn[RadGrid1.MasterTableView.Columns.Count];
            RadGrid1.MasterTableView.Columns.CopyTo(arr, 0);

            var filterItem = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem).First() as GridFilteringItem;

            foreach (var c in arr)
            {
                bool isPercentColumn = c.ColumnType == "GridNumericColumn" && (c as GridNumericColumn).NumericType == NumericType.Percent;

                if (isPercentColumn)
                {
                    var textbox = filterItem[c.UniqueName].Controls.OfType<RadNumericTextBox>().First();

                    textbox.Value = textbox.Value * 100;
                    textbox.DbValue = textbox.Value;

                    RadGrid1.MasterTableView.GetColumn(c.UniqueName).CurrentFilterValue = textbox.Value.ToString();
                }
            }
            filtered = false;
        }
    }
            
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case RadGrid.FilterCommandName:
                var filterItem = e.Item as GridFilteringItem;

                var arr = new GridColumn[RadGrid1.MasterTableView.Columns.Count];
                RadGrid1.MasterTableView.Columns.CopyTo(arr, 0);

                foreach (var c in arr)
                {
                    var col = RadGrid1.MasterTableView.GetColumn(c.UniqueName);
                    bool isPercentColumn = col.ColumnType == "GridNumericColumn" && (col as GridNumericColumn).NumericType == NumericType.Percent;

                    if (isPercentColumn)
                    {
                        var textbox = filterItem[c.UniqueName].Controls.OfType<RadNumericTextBox>().First();

                        textbox.Value = textbox.Value / 100;
                        textbox.DbValue = textbox.Value;

                        RadGrid1.MasterTableView.GetColumn(c.UniqueName).CurrentFilterValue = textbox.Value.ToString();
                    }
                }

                filtered = true;
                break;
            default:
                break;
        }
    }
}
```

0
matt
Top achievements
Rank 1
answered on 31 Jul 2018, 02:40 PM
LOL, are you telling me all these years later and they still never fixed this bug? Nice.
0
Alessandro
Top achievements
Rank 1
answered on 31 Jul 2018, 03:21 PM

Pretty much. I am using the 2018 release

@Vasil please delete my first post

0
Vessy
Telerik team
answered on 03 Aug 2018, 08:18 AM
Hi Alessandro,

Thank you for sharing your solution with the community. Your initial post has bed deleted as per your request.

Regards,
Vessy
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alan
Top achievements
Rank 1
Iron
answered on 02 Jul 2021, 01:44 PM

Hi Vessy,

I use the following to display a decimal value as a Percentage, however, when I go to edit the row the decimal value is shown. For example, the grid row cell will show 100%, but when Editing the Cell value shown is 1 - this becomes quiet confusing to external Users. If a User sees a value of 100 they expect to edit the value of 100.

Is there a fix for this?

Thanks

<telerik:GridNumericColumn FilterControlWidth="50px" DataFormatString="{0:0.0%}" DataType="System.Double" DataField="C_C" FilterControlAltText="Filter C_C column" HeaderText="% Complete" SortExpression="C_C" UniqueName="C_C">
                    </telerik:GridNumericColumn>

0
Doncho
Telerik team
answered on 07 Jul 2021, 01:33 PM

Hi Alan,

You can try to set the DbValueFactor of the GridNumericColumn to 100. This should resolve the editing issue. See sample declaration below:

<telerik:GridNumericColumn DataField="Freight" FilterControlWidth="150px" DataFormatString="{0:0.0%}" DataType="System.Double" DbValueFactor="100"
    FilterControlAltText="Filter Freight column" HeaderText="Freight"
    SortExpression="Freight" UniqueName="Freight">
</telerik:GridNumericColumn>

To be able to filter by using the percentage values in this case you can try to manipulate the NumericTextBox in the FilteringItem in the following way:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    var filteringItem = e.Item as GridFilteringItem;
    if (filteringItem != null)
    {
        var filterTextBox = filteringItem["Freight"].Controls[0] as RadNumericTextBox;
        filterTextBox.DbValueFactor = 0.01;
    }
}

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    GridFilteringItem filteringItem = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
    var textBox = filteringItem["Freight"].Controls[0] as RadNumericTextBox;
    var val = textBox.Value;
    textBox.Value = val * 10000;
}

I have attached a test page for you to test the suggested above. You can add it to an existing Telerik Web site or just copy-paste the code in a new WebForm.

Please give it a try and let me know how this would work for you.

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Alan
Top achievements
Rank 1
Iron
commented on 07 Jul 2021, 03:18 PM

works perfectly now Doncho. Appreciate your support. Thanks
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Andrew
Top achievements
Rank 1
Kenneth Mazur
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Ray
Top achievements
Rank 1
Miguel
Top achievements
Rank 1
Vasil
Telerik team
Veli
Telerik team
Callum
Top achievements
Rank 1
matt
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Alessandro
Top achievements
Rank 1
Vessy
Telerik team
Alan
Top achievements
Rank 1
Iron
Doncho
Telerik team
Share this question
or