📄 dhtmlxgridcell.js
字号:
}
eXcell_coro.prototype = new eXcell_co;
//color picker
function eXcell_cp(cell){
try{
this.cell = cell;
this.grid = this.cell.parentNode.grid;
}catch(er){}
this.edit = function(){
this.val = this.getValue()
this.obj = document.createElement("SPAN");
this.obj.style.border = "1px solid black";
this.obj.style.position = "absolute";
var arPos = this.grid.getPosition(this.cell);//,this.grid.objBox
this.colorPanel(4,this.obj)
document.body.appendChild(this.obj);//this.grid.objBox.appendChild(this.obj);
this.obj.style.left = arPos[0]+"px";
this.obj.style.top = arPos[1]+this.cell.offsetHeight+"px";
}
this.toolDNum = function(value){
if(value.length==1)
value = '0'+value;
return value;
}
this.colorPanel = function(index,parent){
var tbl = document.createElement("TABLE");
parent.appendChild(tbl)
tbl.cellSpacing = 0;
tbl.editor_obj = this;
tbl.style.cursor = "default";
tbl.style.cursor = "table-layout:fixed";
tbl.onclick = function(e){
var ev = e||window.event
var cell = ev.target||ev.srcElement;
var ed = cell.parentNode.parentNode.parentNode.editor_obj
ed.setValue(cell.style.backgroundColor)
ed.grid.editStop();
}
var cnt = 256/index;
for(var j=0;j<=(256/cnt);j++){
var r = tbl.insertRow(j);
for(var i=0;i<=(256/cnt);i++){
for(var n=0;n<=(256/cnt);n++){
R = new Number(cnt*j)-(j==0?0:1)
G = new Number(cnt*i)-(i==0?0:1)
B = new Number(cnt*n)-(n==0?0:1)
var rgb = this.toolDNum(R.toString(16))+""+this.toolDNum(G.toString(16))+""+this.toolDNum(B.toString(16));
var c = r.insertCell(i);
c.width = "10px";
c.innerHTML = " ";//R+":"+G+":"+B;//
c.title = rgb.toUpperCase()
c.style.backgroundColor = "#"+rgb
if(this.val!=null && "#"+rgb.toUpperCase()==this.val.toUpperCase()){
c.style.border = "2px solid white"
}
}
}
}
}
this.getValue = function(){
return this.cell.firstChild.style?this.cell.firstChild.style.backgroundColor:"";//this.getBgColor()
}
this.getRed = function(){
return Number(parseInt(this.getValue().substr(1,2),16))
}
this.getGreen = function(){
return Number(parseInt(this.getValue().substr(3,2),16))
}
this.getBlue = function(){
return Number(parseInt(this.getValue().substr(5,2),16))
}
this.detach = function(){
if(this.obj.offsetParent!=null)
document.body.removeChild(this.obj);
//this.obj.removeNode(true)
return this.val!=this.getValue();
}
}
eXcell_cp.prototype = new eXcell;
eXcell_cp.prototype.setValue = function(val){
this.setCValue("<div style='width:100%;height:"+(this.cell.offsetHeight-2)+";background-color:"+(val||"")+";border:0px;'> </div>",val);
}
//image
/*
The corresponding cell value in XML should be a "^" delimited list of following values:
1st - image src
2nd - image alt text (optional)
3rd - link (optional)
4rd - target (optional, default is _self)
*/
function eXcell_img(cell){
try{
this.cell = cell;
this.grid = this.cell.parentNode.grid;
}catch(er){}
this.getValue = function(){
if(this.cell.firstChild.tagName=="IMG")
return this.cell.firstChild.src+(this.cell.titFl!=null?"^"+this.cell.tit:"");
else if(this.cell.firstChild.tagName=="A"){
var out = this.cell.firstChild.firstChild.src+(this.cell.titFl!=null?"^"+this.cell.tit:"");
out+="^"+this.cell.lnk;
if(this.cell.trg)
out+="^"+this.cell.trg
return out;
}
}
this.getTitle = function(){
return this.cell.tit
}
}
eXcell_img.prototype = new eXcell;
eXcell_img.prototype.setValue = function(val){
var title = val;
if(val.indexOf("^")!=-1){
var ar = val.split("^");
val = ar[0]
title = ar[1];
//link
if(ar.length>2){
this.cell.lnk = ar[2]
if(ar[3])
this.cell.trg = ar[3]
}
this.cell.titFl = "1";
}
this.setCValue("<img src='"+(val||"")._dhx_trim()+"' border='0'>",val);
if(this.cell.lnk){
this.cell.innerHTML = "<a href='"+this.cell.lnk+"' target='"+this.cell.trg+"'>"+this.cell.innerHTML+"</a>"
}
this.cell.tit = title;
}
//extended simple editor (money oriented)
function eXcell_price(cell){
this.base = eXcell_ed;
this.base(cell)
this.getValue = function(){
if(this.cell.childNodes.length>1)
return this.cell.childNodes[1].innerHTML.toString()._dhx_trim()
else
return "0";
}
}
eXcell_price.prototype = new eXcell_ed;
eXcell_price.prototype.setValue = function(val){
if(isNaN(Number(val))){
if(!(val||"") || (val||"")._dhx_trim()!="")
val = 0;//alert("Value must be an integer")
val = this.val || 0;
}
if(val>0){
var color = "green";
this.setCValue("<span>$</span><span style='padding-right:2px;color:"+color+";'>"+val+"</span>",val);
}else{
this.setCValue("<div align='center' style='color:red;'> </div>",0);
}
}
//extended simple editor (dynamic of sales)
function eXcell_dyn(cell){
this.base = eXcell_ed;
this.base(cell)
this.getValue = function(){
return this.cell.firstChild.childNodes[1].innerHTML.toString()._dhx_trim()
}
}
eXcell_dyn.prototype = new eXcell_ed;
eXcell_dyn.prototype.setValue = function(val){
if(!val || isNaN(Number(val))){
val = 0;
}
if(val>0){
var color = "green";
var img = "dyn_up.gif";
}else if (val==0){
var color = "black";
var img = "dyn_.gif";
}else{
var color = "red";
var img = "dyn_down.gif";
}
this.setCValue("<div style='position:relative;padding-right:2px; width:100%;'><img src='"+this.grid.imgURL+""+img+"' height='15' style='position:absolute;top:0px;left:0px;'><span style='width:100%;color:"+color+";'>"+val+"</span></div>",val);
}
//readonly
function eXcell_ro(cell){
this.cell = cell;
this.grid = this.cell.parentNode.grid;
this.edit = function(){}
}
eXcell_ro.prototype = new eXcell;
/*
Copyright Scand LLC http://www.scbr.com
To use this component please contact info@scbr.com to obtain license
*/
/*
HTML Link eXcell v.1.0 for dhtmlxGrid
(c)Scand LLC 2005
The corresponding cell value in XML should be a "^" delimited list of following values:
1st - Link Text
2nd - URL (optional)
3rd - target (optional, default is _blank)
Samples:
<cell>Stephen King</cell>
<cell>Stephen King^http://www.stephenking.com/</cell>
<cell>Stephen King^http://www.stephenking.com/^_self</cell>
*/
function eXcell_link(cell){
this.cell = cell;
this.grid = this.cell.parentNode.grid;
this.edit = function(){}
this.getValue = function(){
if(this.cell.firstChild.getAttribute)
return this.cell.firstChild.innerHTML+"^"+this.cell.firstChild.getAttribute("href")
else
return "";
}
this.setValue = function(val){
var valsAr = val.split("^");
if(valsAr.length==1)
valsAr[1] = "";
else{
if(valsAr.length>1){
valsAr[1] = "href='"+valsAr[1]+"'";
if(valsAr.length==3)
valsAr[1]+= " target='"+valsAr[2]+"'";
else
valsAr[1]+= " target='_blank'";
}
}
this.setCValue("<a "+valsAr[1]+" onclick='(isIE()?event:arguments[0]).cancelBubble = true;'>"+valsAr[0]+"</a>",valsAr);
}
}
eXcell_link.prototype = new eXcell;
eXcell_link.prototype.getTitle=function(){
return this.cell.firstChild.getAttribute("href");
}
/**
* @desc: combobox object constructor (shouldn't be accessed directly - instead please use getCombo(...) method of the grid)
* @type: public
* @returns: combobox for dhtmlxGrid
*/
function dhtmlXGridComboObject(){
this.keys = new dhtmlxArray();
this.values = new dhtmlxArray();
/**
* @desc: puts new combination of key and value into combobox
* @type: public
* @param: key - object to use as a key (should be a string in the case of combobox)
* @param: value - object value of combobox line
*/
this.put = function(key,value){
for(var i=0;i<this.keys.length;i++){
if(this.keys[i]==key){
this.values[i]=value;
return true;
}
}
this.values[this.values.length] = value;
this.keys[this.keys.length] = key;
}
/**
* @desc: gets value corresponding to the given key
* @type: public
* @param: key - object to use as a key (should be a string in the case of combobox)
* @returns: value correspond. to given key or null if no such key
*/
this.get = function(key){
for(var i=0;i<this.keys.length;i++){
if(this.keys[i]==key){
return this.values[i];
}
}
return null;
}
/**
* @desc: clears combobox
* @type: public
*/
this.clear = function(){
/*for(var i=0;i<this.keys.length;i++){
this.keys._dhx_removeAt(i);
this.values._dhx_removeAt(i);
}*/
this.keys = new dhtmlxArray();
this.values = new dhtmlxArray();
}
/**
* @desc: remove pair of key-value from combobox with given key
* @type: public
* @param: key - object to use as a key
*/
this.remove = function(key){
for(var i=0;i<this.keys.length;i++){
if(this.keys[i]==key){
this.keys._dhx_removeAt(i);
this.values._dhx_removeAt(i);
return true;
}
}
}
/**
* @desc: gets the size of combobox
* @type: public
* @returns: current size of combobox
*/
this.size = function(){
var j=0;
for(var i=0;i<this.keys.length;i++){
if(this.keys[i]!=null)
j++;
}
return j;
}
/**
* @desc: gets array of all available keys present in combobox
* @type: public
* @returns: array of all available keys
*/
this.getKeys = function(){
var keyAr = new Array(0);
for(var i=0;i<this.keys.length;i++){
if(this.keys[i]!=null)
keyAr[keyAr.length] = this.keys[i];
}
return keyAr;
}
/**
* @desc: save curent state
* @type: public
*/
this.save = function(){
this._save=new Array();
for(var i=0;i<this.keys.length;i++)
this._save[i]=[this.keys[i],this.values[i]];
}
/**
* @desc: restore saved state
* @type: public
*/
this.restore = function(){
if (this._save){
this.keys[i]=new Array();
this.values[i]=new Array();
for(var i=0;i<this._save.length;i++){
this.keys[i]=this._save[i][0];
this.values[i]=this._save[i][1];
}
}
}
return this;
}
function Hashtable(){
this.keys = new dhtmlxArray();
this.values = new dhtmlxArray();
return this;
}
Hashtable.prototype = new dhtmlXGridComboObject;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -