在可编辑表格EditorGrid中,我选择一行已输入的数据,点击删除按钮,该行数据将被删除,然后当我点击表单提交按钮时,已经被删除的那一行数据仍然被插入数据库中

 

问题描述:在可编辑表格中,我选择一行已输入的数据,点击删除按钮,该行数据将被删除,然后当我点击表单提交按钮时,已经被删除的那一行数据仍然被插入数据库中。

 

1:我的可编辑表格:

  

2:选中一行后,点击删除一行按钮:

  

3:删除成功后:

  

就是当我点击“提交”按钮时,仍然会插入数据库中两条记录(包括我删除的那一行数据)。

我的删除一行的代码:

 /*
 *  1:grid是当前的可编辑表格 我的是:var grid  =   newExt.grid.EditorGridPanel({});
 * 2: store是可编辑表格中定义的数据源,我的是:var store = newExt.data.JsonStore({});
 */
       var sm = grid.getSelectionModel();
       var cell =sm.getSelectedCell();
      
       var record =store.getAt(cell[0]);
       store.remove(record);

 

解决方法:在你的store中添加属性配置选项:

  pruneModifiedRecords: true

  API中解释:此值为true将在 store被加载或者一条记录被删除时,清除所有记录的修改信息(默认为false。也就是说当我点击删除一行操作时,其实被删除的那一行数据还是存在的,只是不显示罢了,如果配置该选项为true,当我们执行删除一行操作时,就会把要删除的那一行数据给清除掉。


如下:

var store = new Ext.data.JsonStore({
       data : data,
       pruneModifiedRecords : true,
       fields : ['detailCosts','detailType','detailPaid','detailDescription',{name : 'detailTime',type : 'date', dateFormat : 'Y-m-d'}]
    });

添加后就执行删除行操作后,再点击提交按钮就不会把原来已经删除的那些数据提交到后台了!

 补充:

  新增一行:

Var countnum=10;//你的可编辑表格的初始最大行数
 var p = new Record({
           detailCosts : '',
           detailType  : '',
           detailPaid  : '2',
           detailTime  : '',
           detailDescription : ''
       });
       grid.stopEditing();
       store.insert(countnum,p);
       countnum++;

 上移:

       var sm =grid.getSelectionModel();
       var cell = sm.getSelectedCell();
       var record = store.getAt(cell[0]);
       var index = cell[0];
       if(index > 0){
           store.remove(record);
           store.insert(index-1,record)
           grid.getView().refresh();
       }

 下移:

       var sm =grid.getSelectionModel();
       var cell = sm.getSelectedCell();
       var record = store.getAt(cell[0]);
       var index = cell[0];
      
       if(index < store.getCount()-1){
           store.remove(record);
           store.insert(index+1,record)
           grid.getView().refresh();
       }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值