Add up and down arrow keys for easyui datagrid

Source: Internet
Author: User

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

Define the call method:

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

  

  

In the onLoadSuccess event where the datagrid is initialized

OnLoadSuccess: function () {// move the upstream and downstream keys moveRow (this );}

 

This is OK!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.