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
225
Update data source after column formatter allied.
posted

On on individual columns in a grid I am using the formatter to set some default values. The default values are for drop downs in the grid rows. One of these is for a default currency. The default currency is set in the grid if no currency is specified during an excel sheet import. What I have noticed is that when I go to edit the row it will default the currency combo box to the first item in the currency list.  

I know this is because the data-source is not updated with the value in the grid.  My question is, can I updated the datasource after the formatter is applied to each row or is there away to update the data-source before any editing is done.   

Parents
No Data
Reply
  • 29097
    Verified Answer
    Offline posted

    Hello John, 

    Thank you for posting in our forum. 

    The formatter function affects only the display text for the related cell in the grid. It does not affect the actual value stored in the data source, so when the combo tries to match the cell value with an existing value in its items it will fail and will default to the first item. 

    The formatter function has a second parameter that holds reference to the data record, so you can directly modify the record value for the related column with your default value.

    For example:

    function formatFunc, rec) {

    if(val === null || val === undefined){

                    //set your default value and modify the data record

                    val = <DefaultValue>;

                    rec.<FieldName>  = <DefaultValue>;

    }

       return val;

    }

     I’ve attached a sample for your reference where the first record from the data source has no value for the field CategoryID. The column for that field is edited via the combo editor and a formatter function is used to display the text of the selected item from the combo. For null or undefined values a default value is set for the record’s CategoryID in the formatter function.  

    Please refer to the attached sample and let me know if you have any questions or concerns. 

     

    Best Regards,

    Maya Kirova

    Infragistics, Inc.

    http://www.infragistics.com/support

     

     

     

     

    comboInGrid.zip
Children
No Data