1.EXTJS Row Editor Grid 点取消时插入的新行 的解决方法

1.EXTJS  Row Editor Grid  点取消时插入的新行 的解决方法 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    <link rel="stylesheet" type="text/css" href="/public/css/RowEditor.css" />

<script type="text/javascript" src="/public/js/Plugins/RowEditor.js"></script>

将新增 删除放到行后面。  

{header: '操作',

dataIndex: 'opt',

name:'opt',

align: 'center',

width: 100,

renderer:function(val, metadata, record, rowIndex, colIndex, store){ 

var grid_id=this.name; 

return  "<input type='button' style='background-Color:#FFF;border:0;font-size: 12px;'  value='新增' οnclick='add_row("+rowIndex+",\""+grid_id+"\");'/> " +"<input type='button'  style='background-Color:#FFF;border:0;font-size: 12px;' value='删除'  οnclick='del_row(\""+grid_id+"\");'/>";

 }

外部函数

function add_row(Index,grid_id) {

    var grid = Ext.getCmp(grid_id);

    grid.addRow(Index);

}

function del_row(grid_id) {

    var grid = Ext.getCmp(grid_id);

    grid.isEdit = false;

    grid.delRow(true);

}

初始化时的函数 控制内的函数。

addRow : function(Index){

        var Employee = Ext.data.Record.create([{

                name: 'id'

            }]);

var u = new Employee({

id: ""  

});

this.editor.stopEditing();

this.store.insert(Index+1,u);  //在当前行的下一行插入

this.getView().refresh();

this.getSelectionModel().selectRow(Index+1);

this.editor.startEditing(Index+1);

},

delRow:function(){

this.editor.stopEditing();

        if(!this.isEdit) {

            if(this.store.getCount() != 1)

            {

                var rec = this.getSelectionModel().getSelected();

                this.store.remove(rec);

                this.getView().refresh();

            }else{

                alert('至少要有一个属性。')

            }

        }

}

New一个编辑的面板

 var editor = new Ext.ux.grid.RowEditor({

clicksToEdit : 2,  //去掉单击编辑情况

saveText: '确定' ,

            cancelText: '取消',

            onRowDblClick: function(g, rowIndex, e){

                this.startEditing(rowIndex, false);

                this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);

                _this.isEdit = true;  //双击的时候设置为true 利用这个来控制取消的时候不删除。

            },

            listeners : {

                canceledit : function(re,isPress){

                    if(isPress){

                        _this.delRow();  点击取消时调用删除方法。防止插入的行留空问题

                    }

                } 

            }

});

转载于:https://www.cnblogs.com/holyes/archive/2012/06/01/97fa7b99d59c9931fea2bcc1c02467a7.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值