aa th
aa th

Reputation: 171

yui datatable inline cell editor problem

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,

Upvotes: 1

Views: 2040

Answers (1)

Simon Lieschke
Simon Lieschke

Reputation: 13333

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;
    }
});

Upvotes: 1

Related Questions