extjs4 grid 多选、添加复选框、动态添加删除数据

grid多选属性:multiSelect: true

添加复选框:首先定义var selectModel = Ext.create(‘Ext.selection.CheckboxModel’); 然后设置grid的selModel属性。

动态添加删除数据:store.insert();和store.remove();

示例代码:

var arows = Ext.getCmp('dailytestuffASG').getSelectionModel().getSelection();
var orows = Ext.getCmp('dailytestuffOSG').getSelectionModel().getSelection();
if(orows.length==0){
	Ext.Msg.alert('错误','请选择要添加的记录!');
	return;
}
var flag = false;
for(var i=0;i<orows.length;i++){
	if(arows.length>0){
		for(var j=0;j<arows.length;j++){
		         if(orows[i].get('userId')==arows[j].get('userId')){
		               flag = true;
		                break;
		         }
		}
		if(flag==true){
		         flag==false;
		         continue;
		}
	}
	var data = [{'userId': orows[i].get('userId'),
		      'userName': orows[i].get('userName'),
		      'depart': orows[i].get('depart')}];
	dailytestuffASGStore.insert(0,data);
}
Ext.each(orows,function(orows){
	dailytestuffOSGStore.remove(orows);
});
dailyASGModel.selectAll();
This entry was posted in Computer, Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s