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

你可能感兴趣的:(extjs4)