Home  >  Article  >  Web Front-end  >  Extjs3.x gridPanel row data moving up and down example code

Extjs3.x gridPanel row data moving up and down example code

零下一度
零下一度Original
2018-05-11 14:07:411413browse

Ext3.x is also new to me and I am not familiar with it. I'll record it in my spare time for easy reference next time, and I hope it can help my colleagues. Just mess with the code!

rowUp : function() {//上移
var records =  this.gridPanel.getSelectionModel().getSelections();//得到选中所有行
for(var i in records)//遍历所选的所有行
{
var record = records[i];//每行的数据(记录此数据)
var index = this.gridPanel.getStore().indexOf(record);//数据所在位置
if(0>=index)
{
return;//不可移动
}
var data = record.data; 
var NewRecord = new Ext.data.Record({ //记录数据,remove&和insert方法是记录数组(我他妈不知道啥玩意)
itemName:data.itemName, //这里面的参数取gridPanel列表中record的定义
itemIndex:data.itemIndex,
maxScore:data.maxScore,
minScore:data.minScore,
itemType:data.itemType
            }); 
this.gridPanel.getStore().removeAt(index);//删除当前所选行数据
this.gridPanel.getStore().insert(index-1,NewRecord);//将记录数据插入到所删除数据位置的上一位置
this.gridPanel.getView().refresh();
this.gridPanel.getSelectionModel().selectRow(index-1,index-1);
}
},
 
rpwDown : function() {//下移
var records =  this.gridPanel.getSelectionModel().getSelections();//得到选中所有行
var num = this.gridPanel.getStore().getCount();
for(var i in records)//遍历所选的所有行
{
var record = records[i];//每行的数据(记录此数据)
var index = this.gridPanel.getStore().indexOf(record);//数据所在位置
if(this.gridPanel.getStore().getCount()-1<=index||0>index)
{
return;//不可移动
}
var data = record.data; 
var NewRecord = new Ext.data.Record({ 
itemName:data.itemName,
itemIndex:data.itemIndex,
maxScore:data.maxScore,
minScore:data.minScore,
itemType:data.itemType
            }); 
this.gridPanel.getStore().removeAt(index);//删除当前所选行数据
this.gridPanel.getStore().insert(index+1,NewRecord);//将记录数据插入到所删除数据位置的下一位置
this.gridPanel.getView().refresh();//刷新(不知道刷的啥)
this.gridPanel.getSelectionModel().selectRow(index+1,index+1);
 
}
//this.gridPanel.getStore().reload();
},

Just throw event calls into the two functions. It works fine, but there will be bugs (you will know it after using it, but I don’t know how to solve it now), and moving the multi-select data up or down is OK.

The above is the detailed content of Extjs3.x gridPanel row data moving up and down example code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn