📄 treegrid.js
字号:
//for row0
if(profile.getKey(src.parentNode.id)==profile.keys['HCELL0A']){
profile.box._asy0(profile,true);
return;
}
//for other rows
var p = profile.properties,
sid = profile.getSubId(src.id),
header = profile.colMap[sid],
cells=header._cells,
cls=profile.getClass('CELLA','-inline'),
n,ns=[],ws=[],w;
_.each(cells,function(o){
n=profile.getSubNode('CELLA',o);
ns.push(n.get(0));
ws.push(n.addClass(cls).width());
});
ws.push(p._minColW);
w=parseInt(Math.max.apply(null,ws));
if(w>p._maxColW)w=p._maxColW;
linb(ns).parent().width(w);
linb(src.parentNode.parentNode).width(header.width=w);
linb(ns).removeClass(cls);
profile.box._ajdustBody(profile);
return false;
}
},
//row resizer
ROWHANDLER:{
onMousedown:function(profile, e, src){
var p=profile.properties,
row = profile.rowMap[profile.getSubId(src.id)],
o=linb(src),
minH =o.parent(3).height()-p._minRowH,
scroll = profile.getSubNode('SCROLL'),
maxH = scroll.offset().top + scroll.height() - linb.Event.getPos(e).top - 4;
if(p.disabled || (row&&row.disabled))return false;
o.startDrag(e, {
verticalOnly:true,
dragType:'blank',
dragDefer:2,
maxTopOffset:minH,
maxBottomOffset:maxH ,
targetReposition:false
});
linb([src.parentNode.parentNode]).onMouseout(true,{$force:true}).onMouseup(true);
},
onDragbegin:function(profile, e, src){
linb.DragDrop.getProfile().proxyNode
.css({
width:profile.root.width()+'px',
height:'4px',
backgroundColor:'#ddd',
cursor:'n-resize'
});
},
onDrag:function(profile, e, src){
var d=linb.DragDrop,p=d.getProfile(),b=0;
if(p.y<=p.restrictedTop || p.y>=p.restrictedBottom)b=true;
if(b){
if(!profile._limited){
p.proxyNode.css('backgroundColor','#ff6600');
profile._limited=true;
}
}else{
if(profile._limited){
p.proxyNode.css('backgroundColor','#ddd');
profile._limited=0;
}
}
},
onDragstop:function(profile, e, src){
var o=linb(src).parent(3),
h=o.height()+linb.DragDrop.getProfile().offset.y,
row = profile.rowMap[profile.getSubId(src.id)]
//for ie's weird bug
if(linb.browser.ie && h%2==1)h+=1;
o.height(h);
if(_.str.startWith(src.parentNode.id,profile.keys.HCELL0A)){
profile.properties.headerHeight=h;
linb.UI.$tryResize(profile,null,profile.root.height());
}else
row.height=h;
profile._limited=0;
},
onDblclick:function(profile, e, src){
var p = profile.properties,
sid = profile.getSubId(src.id),
row,cells;
if(sid){
row=profile.rowMap[sid];
cells=profile.getSubNode('CELLS', sid);
cells.height(row.height=cells.height('auto').height());
}else{
cells=profile.getSubNode('HCELLS');
cells.height(profile.properties.headerHeight=cells.height('auto').height());
linb.UI.$tryResize(profile,null,profile.root.height());
}
return false;
},
onClick:function(){return false}
},
//mark click for tree build
TOGGLE:{
onClick:function(profile, e, src){
var
p = profile.properties,
row = profile.rowMap[profile.getSubId(src.id)]
;
if(p.disabled || row.disabled)return false;
if(!row.sub)return false;
profile.box._setSub(profile, row, !row._checked);
return false;
}
},
//HCELL handler dragdrop
HCELL:{
onClick:function(profile, e, src){
var p=profile.properties,
id = profile.getSubId(src.id),
col = profile.colMap[id];
linb(src).first().focus();
if(p.disabled || col.disabled)return false;
if(!(('colSortable' in col)?col.colMovable:p.colSortable))return;
var order = col._order || false,
type = col.type || 'input',
index = _.arr.indexOf(p.header,col),
me=arguments.callee,
fun = me.fun||(me.fun = function(profile, root, index, type, order){
var rows,parent,self=arguments.callee;
if(root){
rows = root.sub;
parent = profile.getSubNode('SUB', root._serialId).get(0);
}else{
root={_created:true};
rows = profile.properties.rows;
parent = profile.getSubNode('BODY').get(0);
}
//sor sub first
var a1=[], a2=[], a3=[], t,ff;
_.arr.each(rows,function(row){
if(row.sub && row.sub.length>1)
self(profile, row, index, type, order);
//for short input
a1[a1.length]=(t=row.cells)?(t=t[index])?t.value:'':row[index];
a2[a2.length]=a2.length;
});
switch(type){
case 'number':
ff=function(n){return parseFloat(n)||0};
break;
case 'date':
ff=function(n){return new Date(n).getTime()||0};
break;
default:
ff=function(n){return n||''};
}
a2.sort(function(x,y){
x=ff(a1[x]); y=ff(a1[y]);
return (x>y?1:x==y?0:-1)*(order?1:-1);
});
//sort memory array
//sort domnode
var b = root._created, bak=_.copy(rows), c;
if(b)
a1=parent.childNodes;
_.arr.each(a2,function(o,i){
rows[i]=bak[o];
if(b)a3[i]=a1[o];
});
if(b){
var fragment=document.createDocumentFragment();
for(var i=0;t=a3[i];i++)
fragment.appendChild(t);
parent.appendChild(fragment);
}
});
fun(profile, '', index, type, order);
//show sort mark
profile.getSubNode('SORT', true).css('display','none');
var node = profile.getSubNode('SORT', col._serialId).css('display','');
node.tagClass('-checked', !(col._order = !col._order));
profile.box._asy(profile,false);
//clear rows cache
delete profile.$allrowscache;
return false;
},
onMousedown:function(profile, e, src){
var p=profile.properties;
if(p.disabled || !p.colMovable)return;
var col=profile.colMap[profile.getSubId(src.id)];
if(!(('colMovable' in col)?col.colMovable:1))return;
//fire before event
if(false === profile.boxing().beforeColDrag(profile, col.id))return;
var pos=linb.Event.getPos(e),
o = linb(src),
itemId = profile.getSubId(src.id);
o.startDrag(e,{
dragType:'icon',
shadowFrom:src,
dragCursor:'pointer',
targetLeft:pos.left+12,
targetTop:pos.top+12,
targetReposition:false,
dragDefer: 2,
dragKey:profile.$id + ":col",
dragData:o.id()
});
},
onDragbegin:function(profile, e, src){
linb(src).onMouseout(true,{$force:true}).onMouseup(true);
},
beforeMouseover:function(profile, e, src){
if(false===profile.box._colDragCheck(profile,src))return;
linb.DragDrop.setDropElement(src).setDropFace(src,'move');
},
beforeMouseout:function(profile, e, src){
linb.DragDrop.setDropElement(null).setDropFace(null,'none');
if(false===profile.box._colDragCheck(profile,src))return;
},
onDrop:function(profile, e, src){
if(false===profile.box._colDragCheck(profile,src))return;
//check dragData
var p=profile.properties,
data=linb.DragDrop.getProfile().dragData,
fromId = data && profile.getSubId(data),
toId = profile.getSubId(src.id);
//get properties
var
map=profile.colMap,
fromTh=map[fromId],
toTh=map[toId]
;
//fire before event
if(false === profile.boxing().beforeColMoved(profile,fromTh.id, toTh.id))return;
//remove dragover appearance
linb.DragDrop.setDropFace(src,'none');
//get index in HCELL array
var fromIndex = _.arr.subIndexOf(p.header,'_serialId',fromId),
toIndex = _.arr.subIndexOf(p.header,'_serialId',toId)
;
//if same or same position, return
if(fromIndex===toIndex|| fromIndex===toIndex-1)return;
//reposition header dom node
profile.getSubNode('HCELL', toId).addPrev(linb.DragDrop.getProfile().dragData);
//reposition cell dom nodes
_.each(toTh._cells, function(o,i){
profile.getSubNode('CELL',o).addPrev(profile.getSubNode('CELL',fromTh._cells[i]));
});
//update memory
//HCELL position
//keep refrence, and remove
var temp=p.header[fromIndex];
_.arr.removeFrom(p.header,fromIndex);
//insert to right pos
_.arr.insertAny(p.header,temp,toIndex);
//cell position rowMap
var allitems = profile.queryItems(p.rows, true, true);
_.arr.each(allitems,function(o){
//for those non-prepared data
o=o.cells?o.cells:o;
if(!o || o.constructor!=Array)return;
temp=o[fromIndex];
_.arr.removeFrom(o,fromIndex);
_.arr.insertAny(o,temp,toIndex);
});
//fire after event
profile.boxing().afterColMoved(profile, fromTh.id, toTh.id);
//clear rows cache
delete profile.$allrowscache;
},
onMouseover:function(profile,e,src){
if(profile.properties.disabled || !profile.properties.colHidable)return;
var col=profile.colMap[profile.getSubId(src.id)];
if(!(('colHidable' in col)?col.colHidable:1))return;
_.resetRun(profile.$id+':collist',null);
var region={},
o=linb([src]),
pos=o.offset(null,profile.getSubNode('BOX')),
size=o.cssSize();
if(size.width<16)return;
region.height=size.height;var col=profile.colMap[profile.getSubId(src.id)];
region.width=14;
region.left=pos.left;
region.top=pos.top;
profile.getSubNode('COLLIST').cssRegion(region).css('visibility','visible');
},
onMouseout:function(profile,e,src){
if(profile.properties.disabled || !profile.properties.colHidable)return;
var col=profile.colMap[profile.getSubId(src.id)];
if(!(('colHidable' in col)?col.colHidable:1))return;
_.resetRun(profile.$id+':collist',function(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -