开发者

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,


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜