Extjs GridPanel 监听事件 行选中背景详解编程语言

 Extjs设置GridPanel选中行背景色和选中单元格背景色 

var view = grid.getView();

view.getRow(index).style.backgroundColor = “red”;  //选中行背景色

view.getCell(rowIndex,colIndex).style.backgroundColor = “red”;  //选中单元格背景色

我在开发时是在CheckboxSelectionModel中的beforerowselect中进行设置的:

var smQd = new Ext.grid.CheckboxSelectionModel({ 
  'beforerowselect':function(sm,rowIndex,keepExisting,record){ 
                           var l = storeXtcpyy.getCount(); 
                           for(var i=0;i<l;i++){ 
                               if(i%2 == 0){ 
                                   var view = gridXtcpyy.getView(); 
                                view.getRow(i).style.backgroundColor =                                         "white"; 
                               }else{ 
                                   var view = gridXtcpyy.getView(); 
                                   view.getRow(i).style.backgroundColor =                                         "#FAFAFA"; 
                               } 
                           } 
                      } 
                 } 
      });
gridXtcpyy.addListener('cellclick', function (grid, rowIndex, columnIndex, event) { 
    var view = gridXtcpyy.getView(); 
    view.getRow(rowIndex).style.backgroundColor = "#DFE8F6";  
  }, gridXtcpyy);

 

var smQd = new Ext.grid.CheckboxSelectionModel({ 
renderer:function(value, metaData, record, rowIndex, colIndex, store){ 
if((org_id == record.data['dsfjg'])||(top_org_id == org_id)){ 
if((record.data['ywdm']=="901")||(record.data['xgdjzt'].split("-")[0] == 2)||(record.data['khlxzt'].split("-")[0] != 0)||(record.data['khtzzt'].split("-")[0] != 0)){ 
return ""; 
}else{ 
return '<div class="x-grid3-row-checker"> </div>'; 
} 
}else{ 
return ""; 
} 
}, 
//不允许使用点击表格形式修改选择 
//handleMouseDown:Ext.emptyFn, 
        listeners:{ 
/*'rowselect':function(sm,rowIndex,record){ 
var view = gridXtcpyy.getView(); 
view.getRow(rowIndex).style.backgroundColor = "#DFE8F6";  
}, 
'rowdeselect':function(sm,rowIndex,record){ 
var l = storeXtcpyy.getCount(); 
for(var i=0;i<l;i++){ 
if(i%2 == 0){ 
var view = gridXtcpyy.getView(); 
view.getRow(i).style.backgroundColor = "white"; 
}else{ 
var view = gridXtcpyy.getView(); 
view.getRow(i).style.backgroundColor = "#FAFAFA"; 
} 
} 
},*/ 
'selectionchange':function(sm){ 
if(sm.getSelections().length>0){ 
var select_zyed = 0; 
var yxt_rs = 0; 
for(var i=0;i<sm.getSelections().length;i++){ 
if((sm.getSelections()[i].data['xgdjzt'].split("-")[0] != 2)&&(sm.getSelections()[i].data['khlxzt'].split("-")[0] == 0)){ 
var jyje_arr = sm.getSelections()[i].data['jyje'].split(","); 
var jyje_sel = ""; 
for(var j = 0; j< jyje_arr.length; j++){ 
jyje_sel += jyje_arr[j]; 
} 
select_zyed = select_zyed + parseFloat(jyje_sel) ; 
//console.log("-------1:"+select_zyed); 
//select_zyed = accAdd(select_zyed,parseFloat(jyje_sel)); 
if(parseFloat(jyje_sel)>=gmqdje && parseFloat(jyje_sel) < xzje){ 
yxt_rs ++; 
} 
} 
} 
used_ed.setValue(rendererZhMoney(select_zyed)); 
//var total_ed_arr = total_ed.getValue().split(","); 
var total_ed_arr = Ext.getCmp("total_ed").getValue().split(","); 
var _total_ed = ""; 
for(var j = 0; j< total_ed_arr.length; j++){ 
_total_ed += total_ed_arr[j]; 
} 
_total_ed = parseFloat(_total_ed); 
var sure_used_ed_arr = Ext.getCmp("sure_used_ed").getValue().split(","); 
var _sure_used_ed = ""; 
for(var j = 0; j< sure_used_ed_arr.length; j++){ 
_sure_used_ed += sure_used_ed_arr[j]; 
} 
_sure_used_ed = parseFloat(_sure_used_ed); 
var yfdx_wqr_ed_arr = Ext.getCmp("yfdx_wqr_ed").getValue().split(","); 
var _yfdx_wqr_ed = ""; 
for(var j = 0; j< yfdx_wqr_ed_arr.length; j++){ 
_yfdx_wqr_ed += yfdx_wqr_ed_arr[j]; 
} 
_yfdx_wqr_ed = parseFloat(_yfdx_wqr_ed); 
//console.log("---------:"+Subtr(_total_ed,accAdd(accAdd(_sure_used_ed,_yfdx_wqr_ed),select_zyed))); 
//leave_ed.setValue(rendererZhMoney(_total_ed-_sure_used_ed-_yfdx_wqr_ed-select_zyed)); 
                            leave_ed.setValue(rendererZhMoney(Subtr(_total_ed,accAdd(accAdd(_sure_used_ed,_yfdx_wqr_ed),select_zyed)))); 
//leave_ed.setValue(rendererZhMoney(Subtr(total_ed,select_zyed))); 
                             
total_rs = total_xje_rs.getValue(); 
ytz_rs = ytz_xje_rs.getValue(); 
yxz_xje_rs.setValue(yxt_rs); 
sy_xje_rs.setValue(Subtr(total_rs,accAdd(ytz_rs,yxt_rs))); 
}else{ 
used_ed.setValue(rendererZhMoney(0)); 
//leave_ed.setValue(total_ed.getValue()); 
var total_ed_arr = Ext.getCmp("total_ed").getValue().split(","); 
var _total_ed = ""; 
for(var j = 0; j< total_ed_arr.length; j++){ 
_total_ed += total_ed_arr[j]; 
} 
_total_ed = parseFloat(_total_ed); 
var sure_used_ed_arr = Ext.getCmp("sure_used_ed").getValue().split(","); 
var _sure_used_ed = ""; 
for(var j = 0; j< sure_used_ed_arr.length; j++){ 
_sure_used_ed += sure_used_ed_arr[j]; 
} 
_sure_used_ed = parseFloat(_sure_used_ed); 
var yfdx_wqr_ed_arr = Ext.getCmp("yfdx_wqr_ed").getValue().split(","); 
var _yfdx_wqr_ed = ""; 
for(var j = 0; j< yfdx_wqr_ed_arr.length; j++){ 
_yfdx_wqr_ed += yfdx_wqr_ed_arr[j]; 
} 
_yfdx_wqr_ed = parseFloat(_yfdx_wqr_ed); 
//leave_ed.setValue(rendererZhMoney(_total_ed-_sure_used_ed-_yfdx_wqr_ed)); 
                            leave_ed.setValue(rendererZhMoney(Subtr(_total_ed,accAdd(_sure_used_ed,_yfdx_wqr_ed)))); 
total_rs = total_xje_rs.getValue(); 
ytz_rs = ytz_xje_rs.getValue(); 
yxz_xje_rs.setValue(0); 
sy_xje_rs.setValue(Subtr(total_rs,ytz_rs)); 
} 
}, 
'beforerowselect':function(sm,rowIndex,keepExisting,record){ 
var l = storeXtcpyy.getCount(); 
for(var i=0;i<l;i++){ 
if(i%2 == 0){ 
var view = gridXtcpyy.getView(); 
view.getRow(i).style.backgroundColor = "white"; 
}else{ 
var view = gridXtcpyy.getView(); 
view.getRow(i).style.backgroundColor = "#FAFAFA"; 
} 
} 
if((org_id == record.data['dsfjg'])||(top_org_id == org_id)){ 
if((record.data['ywdm']=="901")||(record.data['xgdjzt'].split("-")[0] == 2)||(record.data['khlxzt'].split("-")[0] != 0)||(record.data['khtzzt'].split("-")[0] != 0)){ 
return false; 
}else{ 
return true; 
}     
}else{ 
return false; 
}     
} 
} 
});

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/13211.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论