|
进来的项目中遇到了一个问题,一个datagrid列表的内容来源于几个表的联合查询内容,那么在修改某个cell当中的内容的时候将涉及到更新几个表的内容,如果解决这样的问题,我的思路是采用弹出窗口(当然用div也可以的,只是表现方式不同而已),dhtmlxgrid中是没有弹出窗口的,所以我就扩展了一下。
首先是在dhtmlXGridCell.js中添加如下代码
function eXcell_oWin(cell) { var cellVal=""; try { this.cell = cell; this.grid = this.cell.parentNode.grid; }catch(er){}
this.edit = function(){ this.val = this.cell.val; eval(this.val.split("^")[1]); this.cell._cediton=true; } this.getValue = function(){ }
this.setValue = function(val){ var valsAr = val.split("^"); if(valsAr.length==1) valsAr[0] = ""; this.cell.innerHTML=valsAr[0]; this.cell.val=val;
}
}
eXcell_oWin.prototype = new eXcell;
这段代码的功能是扩展一个xcell的类型oWin
在grid.xml中的内容如下 <?xml version="1.0" encoding="UTF-8"?> <rows> <row id="1"> <cell>1</cell> <cell>John Grisham^modUserName('John Grisham')</cell> </row> <row id="2"> <cell>2</cell> <cell>Stephen King^modUserName('Stephen King')</cell> </row> </rows>
大家注意第二个cell的内容是由两部分组成,前面是cell显示的内容,后面是双击调用的函数modUserName,他们之间用^分开
然后在oWin.html中添加如下代码: function modUserName(val1) {//这个函数就是我们在xml中需要调用的,这段代码中我是定义了弹出窗口程序,当然你也可以写成div的。
window.open("win.html", "smallwin","width=400,height=350");
}
同时也要注意mygrid的定义代码更改成mygrid.setColTypes("ro,oWin");
此时浏览oWin.html,双击第二列cell,弹出窗口,在弹出窗口的文本框中输入文字,点击提交,datagrid中相应的cell的值更新了,具体请看附件的例子。
dhtmlxgrid已经应用了一段时间了,感觉很不错,扩展很方便,足可以看出原作者的高深功力,希望对dhtmlxgrid感兴趣的朋友来信一起讨论和改进dhtmlxgrid。我的email:rautinee@yahoo.com.cn 附件:dhtmlxgrid-openwin.rar(149K)
|