views:

332

answers:

1

Hi,

When using inline cell editor in my datatable I want to round value to 10 multiple

This is my code :

mydatatable.subscribe("cellDblclickEvent",datatable_DetailsCommande.onEventShowCellEditor);  

var onCellEdit = function(oArgs) { 

                    var oColumn=oArgs.editor.getColumn();
                    var column=oColumn.getKey();
                    var oRecord = oArgs.editor.getRecord();
                    var newValue=oRecord.getData(column);
                    var row = this.getRecord(oArgs.target);


                    // calculate the  modulo
                    n = newValue % 10;


                    if(n!=0)
                    {
                        newValue=parseInt(newValue);
                        oRecord.setData(column,eval(newValue+(10-n)));
                    } 


                }
mydatatable.subscribe("editorSaveEvent", onCellEdit); 

Function result :

After double clicking in cell I change value to 17 for example and I click save, I want then to have 20 in my datatable cell but I got 17. After second time double clicking in my datatable cell I obtain 20 in the inline cell editor.

How to put the rounded value in my datatable cell?

regards,

A: 

When you create your inline editor in your column definition you could specify a validator which will perform your rounding:

new YAHOO.widget.TextboxCellEditor({
    validator: function(data) {
        // Convert to a number
        var number = data * 1;

        if (!YAHOO.lang.isNumber(number)) {
            return undefined;
        }

        var n = number % 10;
        return n === 0 ? number : number + 10 - n;
    }
});
Simon Lieschke
Thank's for answer. Even using updateRecordValue I still have the same problem. I tried alert(oRecord.getData(column)) after both setData and updateRecordValue methods and I got the good value but not in my datatable cell.
Eli
Sorry, that's right, `updateRecordValue` won't work. I've had a look at the DataTable code and my updated answer should do the trick.
Simon Lieschke
Fianlly I used updateCell method http://developer.yahoo.com/yui/docs/YAHOO.widget.DataTable.html#method_updateCell. Anyway thank's for reactivity
Eli