easyui 데이터grid에 위아래 방향 키 이동 추가

var DatagridMoveRow = (function($){
 
    function DatagridMoveRow(gridTarget){
        this.el = gridTarget;
        this.$el = $(this.el);
        this.rowIndex = -1;
        this.rowsCount = this.$el.datagrid('getData').rows.length;
        return this;
    }
 
    DatagridMoveRow.prototype = {
        getRowindex: function(){
            var selectRowIndex = this.$el.datagrid('getSelectedIndex');
            if(selectRowIndex == -1){
                this.rowIndex = 0 ;
            }else{
                this.rowIndex = selectRowIndex;
            }
        },
        moveUp: function(){
 
            this.getRowindex();
 
            if(this.rowIndex ==0){
                return false;
            }
 
            var i = --this.rowIndex;
            if(i>-1){
                this.$el.datagrid('selectRow',i);
            }else{
                this.rowIndex = 0;
            }
 
            return false;
        },
        moveDown: function (){
            this.getRowindex();
 
            if(this.rowIndex == this.rowsCount -1 ){
                return false;
            }
            var i = ++this.rowIndex;
            this.$el.datagrid('selectRow',i);
        }
    }
 
    return DatagridMoveRow;
 
})(jQuery);

// ;
var moveRow = function(target){
        var options = $(target).datagrid('options');
 
        if(options.moveRow){
            var dmr = new DatagridMoveRow(target);
            $(document).on('keydown.datagridrow',function(e){
                if(e.keyCode == 38){ //up
                    dmr.moveUp();
                }else if(e.keyCode == 40) {// down
                    dmr.moveDown();
                }
            });
        }
    }
// datagrid   onLoadSuccess  
//onLoadSuccess:function(){
   //  
//   moveRow(this);       
//}

좋은 웹페이지 즐겨찾기