巨难题:改写GRID的效率,急,解决了另开贴送300分.
这是我在asp网页中调用的一个GRID的代码,目前的代码是可用的,不过我觉得效率太差,GRID中的数据录入超过200笔就会要反应30秒以上.我希望能把他改成在10秒以内.请各位高手帮帮忙.
<public:component>
<PUBLIC:ATTACH EVENT="onmousemove" ONEVENT="onMousemoveProc()" FOR="element" />
<PUBLIC:ATTACH EVENT="onmouseup" ONEVENT="onMouseupProc()" FOR="document" />
<PUBLIC:PROPERTY NAME = "ColsTitle" put="getTitle" />
<PUBLIC:PROPERTY NAME = "ColsWidth" put="getWidth" />
<PUBLIC:PROPERTY NAME = "ColsAlignment" put="getAlignment" />
<PUBLIC:PROPERTY NAME = "ColsTitle" put="getTitle" />
<PUBLIC:PROPERTY NAME = "Cols" put="getCols" />
<PUBLIC:PROPERTY NAME = "Font" put="getFont" />
<PUBLIC:METHOD NAME="AddItem" />
<PUBLIC:METHOD NAME="CurRowBuf" />
<PUBLIC:METHOD NAME="EditItem" />
<PUBLIC:METHOD NAME="DelItem" />
<PUBLIC:METHOD NAME="SetGridArray" />
<PUBLIC:METHOD NAME="GetGridArray" />
<PUBLIC:METHOD NAME="Init" />
<script language="vbscript">
dim blnIsArry
dim aryWidth
dim aryTitle
blnIsArry=false
dim aryData
dim aryColsAlignment
//取得陣列值
function getTitle(arytmp)
aryTitle = arytmp
dim strAry
strAry=""
dim i
for i=LBound(arytmp) to UBound(arytmp)
if i <> UBound(arytmp) then
strAry = strAry & arytmp(i) & ","
else
strAry = strAry & arytmp(i)
end if
next
transintoColsTitle(strAry)
end function
//取得陣列值
function getWidth(arytmp)
aryWidth=arytmp
dim strAry
strAry=""
dim i
for i=LBound(arytmp) to UBound(arytmp)
if i <> UBound(arytmp) then
strAry = strAry & arytmp(i) & ","
else
strAry = strAry & arytmp(i)
end if
next
transintoColsWidth(strAry)
end function
//取得陣列值
function getAlignment(arytmp)
dim strAry
strAry=""
dim i
aryColsAlignment=arytmp
for i=LBound(arytmp) to UBound(arytmp)
if i <> UBound(arytmp) then
strAry = strAry & arytmp(i) & ","
else
strAry = strAry & arytmp(i)
end if
next
transintoColsAlignment(strAry)
end function
//AddItem function,傳入參數array
function AddItem(arytmp)
dim strAry
strAry=""
dim i
for i=LBound(arytmp) to UBound(arytmp)
if i <> UBound(arytmp) then
strAry = strAry & arytmp(i) & ","
else
strAry = strAry & arytmp(i)
end if
next
transintoRowData(strAry)
end function
function CurRowBuf()
dim strAry
strAry = getAryCurRow()
if strAry = "" then
CurRowBuf=""
else
CurRowBuf = Split( strAry,",")
end if
end function
function EditItem()
dim strAry
strAry = getAryCurRow()
if strAry = "" then
EditItem=""
else
deleteItem()
EditItem = Split( strAry,",")
end if
end function
function DelItem()
deleteItem()
end function
function GetGridArray()
dim aryRows
ReDim aryRows(element.document.all(strTableID).rows.length-2,element.document.all(strTableID).rows(0).cells.length-1)
dim i,j
if element.document.all(strTableID).rows.length >1 then
//共幾列
for i=1 to element.document.all(strTableID).rows.length-1
//共幾欄
for j=0 to element.document.all(strTableID).rows(0).cells.length-1
aryRows(i-1,j) = Replace(element.document.all(strTableID).rows(i).childNodes(j).childNodes(0).innerHTML," ","")
next
next
GetGridArray =aryRows
else
GetGridArray = ""
end if
end function
function SetGridArray(arytmp)
if isarray(arytmp) then
aryData=arytmp
blnIsArry=true
else
blnIsArry=false
end if
end function
function Init()
//判斷是否資料收集齊全,若資料不全則不繪製Grid
If ( strCols = "" ) Or ( Not IsArray(aryTitle) ) Or ( Not IsArray(aryWidth) ) Then
Exit Function
End If
//清空資料
if element.document.all(strTableID).rows.length >1 then
for i=element.document.all(strTableID).rows.length-1 to 1 step -1
element.document.all(strTableID).deleteRow(i)
'element.document.all(strTableID).rows(i).removeNode(true)
next
end if
//把data塞進grid
if blnIsArry=true then
//共幾列
dim strgridID
for i=LBound(aryData,1) to UBound(aryData,1)
'strgridID = "gridrow_" & element.document.all(strTableID).rows.length
set objRow = element.document.all(strTableID).insertRow()
'objRow.id=strgridID
objRow.style.cssText="font-size:13px;color:666666;"
call objRow.attachEvent("onclick",clickfun)
//call objRow.attachEvent("onblur",losefocus)
'共幾欄
for j=LBound(aryData,2) to UBound(aryData,2)
set objCell = objRow.insertCell()
objCell.innerHTML="<div UNSELECTABLE='on' style='font-size:13px;cursor:default ;width:" & cdbl(aryWidth(j))/15 & "px;height:15px;overflow:hidden; text-overflow:ellipsis' >" & aryData(i,j) & " </div>"
objCell.align=aryColsAlignment(j)
next
for j=LBound(aryData,2) to UBound(aryData,2)
if cdbl(aryWidth(j)) = 0 then
element.document.all(strTableID).rows(element.document.all(strTableID).rows.length-1).childNodes(j).style.display="none"
end if
next
next
end if
end function
</script>