Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
215
Cannot change cell value using ValueChanged or ValueChanging
posted

Hi, I'm try to use the ValueChanged or ValueChanging events, with no luck.

I have a requirement that one of my grid columns must contain a number, however the customer is often going to be entering millions, billions, thousands and requires a shorthand. So if they enter 5K it should change to 5000.

I've got this in my ASPX...

 

                        <ig:TextEditorProvider ID="tepNetSyndPrem">

                            <EditorControl SelectionOnFocus="SelectAll" HorizontalAlign="Right">

                                <ClientEvents ValueChanging="KMBProcessor"></ClientEvents>

                            </EditorControl>

                        </ig:TextEditorProvider>

and this Javascript
            function KMBProcessor(sender, args) {
                var oldfieldvalue = args.get_value();
                if (oldfieldvalue != null) {
                    var cell_val = oldfieldvalue.replace(/[k]/i, '000');
                    cell_val = cell_val.replace(/[m]/i, '000000');
                    cell_val = cell_val.replace(/[b]/i, '000000000');
                    cell_val = cell_val.replace(/[^0-9]/g, '');
                    args.set_value(cell_val);
                    sender.set_value(cell_val);
                    return true;
                }
            }

As you can see, I'm trying to set the cell value using args and sender, I'm even returning true from the function in a vain attempt to get things working. The cell never changes! I enter 5k into it, move to the next cell and 5k remains. I've stuck debugging in and can see the function being called, and can even see that after the set_value calls, if you do a get_value the value has changed... but not on the grid.

I've tried ValueChanging, ValueChanged - I've even tried TextChanged, which worked, but is a pain as it runs with each keypress and if you hit a key such as R quick enough the javascript function doesn't catch it.

Please... what am I doing wrong? It has to be something simple. Or is there a better way of getting this KMB replacement functionality

Parents
  • 25665
    Offline posted

    Hello Chris,

    I recommend that you use the function set_newVaule from the eventArgs in the CellValueChanging event. I have attached a sample to demonstrate this behavior.

    Please let me know if you have any questions concerning this matter.

    Sincerely,
    Mike P.
    Developer Support Engineer
    Infragistics, Inc.
    www.infragistics.com

    WebDataGridChange.zip
Reply Children
No Data