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

RadGrid GridNumericColumn negative amounts switch to positive when editing

2 Answers 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bryan
Top achievements
Rank 1
bryan asked on 21 Aug 2017, 08:33 PM

There is a serious bug in the AJAX radgrid, when using a bound GridNumericColumn, where NumericType = "currency" to set the display format.  

 

When the  datasource has negative amounts, this will be displayed in the format "($1.22)", which is what is expected with a currency format.  But, as soon as you try to edit this column, it opens the editor, and misinterprets this negative, and transforms the amount to positive.   The currency format should be shown in non edit mode, but it should interpret this properly and display a number with a negative sign in edit mode.  When edit has closed, the display should revert back to currency format.

 

This is a very serious issue with financial applications, such as those that deal with hundreds of million sof dollars in a corporate Profit And Loss, or Forecasting system.

 

 

bryan
Top achievements
Rank 1
commented on 22 Aug 2017, 08:30 PM

forgot to mention....

This issue is for BatchEdit mode.

Eyup
Telerik team
commented on 28 Aug 2017, 06:20 AM

Hello Bryan,

I believe this is the same case from your formal support thread. I am glad the provided sample has proven helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
bryan
Top achievements
Rank 1
commented on 28 Aug 2017, 02:19 PM

yes, same issue.  Maybe I put this in the wrong forum, I wanted to report this as a (non trivial) bug that needs to be fixed.  The other post in the support forum was to get an urgent workaround.
Dave Wolf
Top achievements
Rank 1
Iron
commented on 25 Jan 2020, 02:22 AM

What was the fix for this?  I'm having a similar issue.
bryan
Top achievements
Rank 1
commented on 25 Jan 2020, 08:16 AM

Hi Dave, they never did fix that grid issue, but there is a workaround.   But the workaround is for batch edit mode...is that the mode you are using?
bryan
Top achievements
Rank 1
commented on 04 Feb 2020, 10:29 PM

Dave, as I mentioned...if its batch mode you are using there is a workaround solution, without the need to do inline editing.  It willwork for batch mode.  let me know.
Jerry
Top achievements
Rank 2
Iron
Iron
commented on 03 Aug 2022, 12:40 PM

Could you post a link to the workaround?  I am having this same issue with negative numbers.  Thanks,
bryan
Top achievements
Rank 1
commented on 03 Aug 2022, 09:56 PM

Jerry the workaround is in the thread linked below.  Start at the bottom of the thread and work backwards.   As I discovered more, I modified my original code.  There are quite a few hoops to jump through using client side grid events.  Hope this helps you. 

https://www.telerik.com/account/support-center/view-ticket/1125232

 

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 29 Jan 2020, 10:36 AM

Hi,

 

Yes, this behavior is present only with Batch editing mode which does not support automatic handling of formats. You can use InPlace editing instead which would be more suitable in this case:
https://www.telerik.com/support/kb/aspnet-ajax/grid/details/radgrid-batch-editing-templates-and-specifics

 

Regards,
Eyup
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Valentin Dragnev
Telerik team
answered on 08 Aug 2022, 12:48 PM | edited on 08 Aug 2022, 01:00 PM

Hello Jerry and Bryan,

Allow me to jump in and share that the ticketing system is a private one and only the forums are public resources.

On behalf of Bryan Scott, the author of the final solution in ticket 1125232, I isolated the sample files in the attached NegParenFinalFix.zip arhive and shared them here with the community.

Some quick notes are:

  • the Batch-editing is client-side based functionality and because of that, it has its own limitations, like in the concrete case. You can find this article very useful for the workaround solution: Working with Templates.
  • If you need server-side and more complex control you can use: EditForms, PopUp or InPlace you can find information about them here: Accessing Values and Controls.
  • From here you can see the pros and cons of the Batch-editing tool: RadGrid Batch Editing Templates and Specifics.

@Bryan, feel free to share more information for your solution.

 

bryan
Top achievements
Rank 1
commented on 08 Aug 2022, 09:41 PM

thank you Valentin. Looks like you made a few improvements that simplified the client side code..   To anyone following, its actually quite simple its just 2 grid client events, and using a template column in the page markup, with a  label and RadTextBox formatted to currency. 
bryan
Top achievements
Rank 1
commented on 06 Oct 2022, 09:25 PM

I thought I would do another update on this thread regarding Valentin's code with the zip file which I discovered.   That works nicely but unfortunately it won't work for editing of new rows, only existing rows.   It looks like this might be due to element(0) is a span for existing rows, but a div for new rows, so the named label can't be found.

I would recommend using my original code, which doesn't require named labels or textboxes.  I simply retrieve element(0), and this seems to work for both scenarios.  In addition, I use different client events than Valentin.  as shown below, and I feel this makes sense,  You want to get the cell value (which is formatted) and then modify the args before they are passed to the editor.   Similarly, the editor passes the correct value which must then be formatted when you set the cell contents.   So its Get/Set CellValue events,

                        <ClientEvents 
                            OnBatchEditGetCellValue="gridBatchEditGetCellValue"
                            OnBatchEditSetCellValue="gridBatchEditSetCellValue"
                            />
                        <ClientEvents />


javascript to use.


function gridBatchEditGetCellValue(sender, args)
{
    var columnName = args.get_columnUniqueName();
    var convertFormattedCurrencyToAmount = false;

    switch (columnName)
    {
        case "Amount":
            convertFormattedCurrencyToAmount = true;
            break;
    }

    if (convertFormattedCurrencyToAmount)
    {
        var value = $(args.get_cell()).text().trim();

        if (value.startsWith("(") && value.endsWith(")"))
        {
            args.set_cancel(true);
            args.set_value("-" + value.slice(1, -1));
        }
    }
}

function gridBatchEditSetCellValue(sender, args) 
{
    // need to format the value as currency in the cell. 
    // can't reference a named label in the element, because a span is only found in existing rows. New rows are DIVs so no span
    // must reference the cells first child element 

    var columnName = args.get_columnUniqueName();
    var container = args.get_container();
    var value = args.get_value();
    var formatAsNegativeCurrency = false

    switch (columnName) 
    {
        case "Amount":
            if (parseFloat(value) < 0) //negative number
            {
                formatAsNegativeCurrency = true;
            }
            break;
    }

    if (formatAsNegativeCurrency)
    {
        args.set_cancel(true);

        var formattedValue = "($" + value.toString().slice(1) + ")";
        args.get_cell().children[0].textContent = formattedValue;
    }
}

 

 

Tags
Grid
Asked by
bryan
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Valentin Dragnev
Telerik team
Share this question
or