📄 dhtml.js
字号:
}
,
setServersideSortNumberOfRows:function(serversideSortNumberOfRows)
{
this.serversideSortNumberOfRows = serversideSortNumberOfRows;
}
,
setServersideSortFileName:function(serversideSortFileName)
{
this.serversideSortFileName = serversideSortFileName;
}
,
setNoCssLayout:function()
{
this.noCssLayout = true;
}
,
sortTableByColumn:function(columnIndex,howToSort)
{
if(!howToSort)howToSort = 'ascending';
var tableObj = document.getElementById(this.idOfTable);
var firstRow = tableObj.rows[0];
var tds = firstRow.cells;
if(tds[columnIndex] && this.columnSortArray[columnIndex]){
this.__sortTable(tds[columnIndex],howToSort);
}
}
,
setTableId:function(idOfTable)
{
this.idOfTable = idOfTable;
try{
this.tableObj = document.getElementById(idOfTable);
}catch(e){
}
}
,
setTableWidth:function(width)
{
this.widthOfTable = width;
}
,
setTableHeight:function(height)
{
this.heightOfTable = height;
}
,
setColumnSort:function(columnSortArray)
{
this.columnSortArray = columnSortArray;
}
,
addNewRow:function(cellContent)
{
var tableObj = document.getElementById(this.idOfTable);
var tbody = tableObj.getElementsByTagName('TBODY')[0];
var row = tbody.insertRow(-1);
for(var no=0;no<cellContent.length;no++){
var cell = row.insertCell(-1);
cell.innerHTML = cellContent[no];
}
this.__parseDataRows(tableObj);
}
,
addNewColumn:function(columnContent,headerText,sortMethod)
{
this.columnSortArray[this.columnSortArray.length] = sortMethod;
var tableObj = document.getElementById(this.idOfTable); // Reference to the <table>
var tbody = tableObj.getElementsByTagName('TBODY')[0]; // Reference to the <tbody>
var thead = tableObj.getElementsByTagName('THEAD')[0]; // Reference to the <tbody>
var bodyRows = tbody.rows; // Reference to all the <tr> inside the <tbody> tag
var headerRows = thead.rows; // Reference to all <tr> inside <thead>
cellIndexSubtract = 1; // Firefox have a small cell at the right of each row which means that the new column should not be the last one, but second to last.
if(DHTMLSuite.clientInfoObj.isMSIE) cellIndexSubtract = 0; // Browser does not have this cell at the right
var headerCell = headerRows[0].insertCell(headerRows[0].cells.length-cellIndexSubtract);
if(!this.noCssLayout)headerCell.className = 'DHTMLSuite_tableWidget_headerCell';
headerCell.onselectstart = DHTMLSuite.commonObj.cancelEvent;
DHTMLSuite.commonObj.__addEventElement(headerCell);
headerCell.innerHTML = headerText;
if(sortMethod){
this.__parseHeaderCell(headerCell);
}else{
headerCell.style.cursor = 'default';
}
headerRows[0].cells[headerRows[0].cells.length-1].style.borderRightWidth = '0px';
headerRows[0].cells[headerRows[0].cells.length-2].style.borderRightWidth = '1px';
for(var no=0;no<columnContent.length;no++){
var dataCell = bodyRows[no].insertCell(bodyRows[no].cells.length-cellIndexSubtract);
dataCell.innerHTML = columnContent[no];
}
this.__parseDataRows(tableObj);
}
,
setPageHandler:function(ref)
{
this.pageHandler = ref;
}
,
__handleCallBackFromEvent:function(e,whichCallBackAction)
{
if(document.all)e = event;
var src = DHTMLSuite.commonObj.getSrcElement(e);
if((whichCallBackAction=='rowClick' || whichCallBackAction=='rowDblClick') && src.tagName.toLowerCase()!='tr'){
while(src.tagName.toLowerCase()!='tr')src = src.parentNode;
}
this.__createCallBackJavascriptString(whichCallBackAction,src);
}
,
__createCallBackJavascriptString:function(whichCallBackAction,el)
{
var callbackString = "";
switch(whichCallBackAction){
case "rowClick":
if(!this.rowClickCallBackFunction)return;
callbackString = this.rowClickCallBackFunction + '(el)';
break;
case "rowDblClick":
if(!this.setRowDblClickCallBackFunction)return;
callbackString = this.setRowDblClickCallBackFunction + '(el)';
break;
}
this.__executeCallBack(callbackString,el);
}
,
__executeCallBack:function(callbackString,el)
{
if(!callbackString)return;
try{
eval(callbackString);
}catch(e){
}
}
,
__parseHeaderCell:function(inputCell)
{
if(!this.noCssLayout){
inputCell.onmouseover = this.__highlightTableHeader;
inputCell.onmouseout = this.__removeHighlightEffectFromTableHeader;
inputCell.onmousedown = this.__mousedownOnTableHeader;
inputCell.onmouseup = this.__highlightTableHeader;
}else{
inputCell.style.cursor = 'pointer'; // No CSS layout -> just set cursor to pointer/hand.
}
var refToThis = this; // It doesn't work with "this" on the line below, so we create a variable refering to "this".
inputCell.onclick = function(){ refToThis.__sortTable(this); };
DHTMLSuite.commonObj.__addEventElement(inputCell);
var img = document.createElement('IMG');
img.src = DHTMLSuite.configObj.imagePath + 'arrow_up.gif';
inputCell.appendChild(img);
img.style.visibility = 'hidden';
}
,
__parseDataRows:function(parentObj)
{
var ind = this.objectIndex;
for(var no=1;no<parentObj.rows.length;no++){
if(!this.noCssLayout){
parentObj.rows[no].onmouseover = this.__highlightTableRow;
parentObj.rows[no].onmouseout = this.__removeHighlightEffectFromTableRow;
}
parentObj.rows[no].onclick = function(e){ DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[ind].__handleCallBackFromEvent(e,'rowClick'); };
parentObj.rows[no].ondblclick = function(e){ DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[ind].__handleCallBackFromEvent(e,'rowDblClick'); };
DHTMLSuite.commonObj.__addEventElement(parentObj.rows[no]);
for(var no2=0;no2<this.columnSortArray.length;no2++){ /* Right align numeric cells */
try{
if(this.columnSortArray[no2] && this.columnSortArray[no2]=='N')parentObj.rows[no].cells[no2].style.textAlign='right';
}catch(e){
alert('Error in __parseDataRows method - row: ' + no + ', column:' + no2);
}
}
}
for(var no2=0;no2<this.columnSortArray.length;no2++){ /* Right align numeric cells */
if(this.columnSortArray[no2] && this.columnSortArray[no2]=='N')parentObj.rows[0].cells[no2].style.textAlign='right';
}
}
,
__initTableWidget:function()
{
if(!this.columnSortArray)this.columnSortArray = new Array();
this.widthOfTable = this.widthOfTable + '';
this.heightOfTable = this.heightOfTable + '';
var obj = document.getElementById(this.idOfTable);
obj.parentNode.className = 'DHTMLSuite_widget_tableDiv';
if(navigator.userAgent.toLowerCase().indexOf('safari')==-1 && !this.noCssLayout){
if(!DHTMLSuite.clientInfoObj.isMSIE)
obj.parentNode.style.overflow='hidden';
else {
obj.parentNode.style.overflowX = 'hidden';
obj.parentNode.style.overflowY = 'scroll';
}
}
if(!this.noCssLayout){
if(this.widthOfTable.indexOf('%')>=0){
obj.style.width = '100%';
obj.parentNode.style.width = this.widthOfTable;
}else{
obj.style.width = this.widthOfTable + 'px';
obj.parentNode.style.width = this.widthOfTable + 'px';
}
if(this.heightOfTable.indexOf('%')>=0){
obj.parentNode.style.height = this.heightOfTable;
}else{
obj.parentNode.style.height = this.heightOfTable + 'px';
}
}
if(!DHTMLSuite.clientInfoObj.isMSIE){
this.__addEndCol(obj);
}else{
obj.style.cssText = 'width:expression(this.parentNode.clientWidth)';
}
obj.cellSpacing = 0;
obj.cellPadding = 0;
if(!this.noCssLayout)obj.className='DHTMLSuite_tableWidget';
var tHead = obj.getElementsByTagName('THEAD')[0];
var cells = tHead.getElementsByTagName('TD');
var tBody = obj.getElementsByTagName('TBODY')[0];
tBody.className = 'DHTMLSuite_scrollingContent';
if(DHTMLSuite.clientInfoObj.isMSIE && 1==2){ /* DEPRECATED */
lastCell = tHead.rows[0].insertCell(-1);
lastCell.innerHTML = ' ';
lastCell.className='DHTMLSuite_tableWidget_MSIESPACER';
}
for(var no=0;no<cells.length;no++){
if(!this.noCssLayout)cells[no].className = 'DHTMLSuite_tableWidget_headerCell';
cells[no].onselectstart = DHTMLSuite.commonObj.cancelEvent;
DHTMLSuite.commonObj.__addEventElement(cells[no]);
if(no==cells.length-1 && !this.noCssLayout){
cells[no].style.borderRightWidth = '0px';
}
if(this.columnSortArray[no]){
this.__parseHeaderCell(cells[no]);
}else{
cells[no].style.cursor = 'default';
}
}
if(!this.noCssLayout){
var tBody = obj.getElementsByTagName('TBODY')[0];
if(document.all && navigator.userAgent.indexOf('Opera')<0){
tBody.className='DHTMLSuite_scrollingContent';
tBody.style.display='block';
}else{
if(!this.noCssLayout)tBody.className='DHTMLSuite_scrollingContent';
tBody.style.height = (obj.parentNode.clientHeight-tHead.offsetHeight) + 'px';
if(navigator.userAgent.indexOf('Opera')>=0){
obj.parentNode.style.overflow = 'auto';
}
}
}
this.__parseDataRows(obj);
var ind = this.objectIndex;
}
,
__addEndCol:function(obj)
{
var rows = obj.getElementsByTagName('TR');
for(var no=0;no<rows.length;no++){
var cell = rows[no].insertCell(rows[no].cells.length);
cell.innerHTML = '<img src="' + DHTMLSuite.configObj.imagePath + 'transparent.gif" width="10" style="visibility:hidden">';
cell.style.width = '13px';
cell.width = '13';
cell.style.overflow='hidden';
}
}
,
__highlightTableHeader:function()
{
this.className='DHTMLSuite_tableWigdet_headerCellOver';
if(document.all){ // I.E fix for "jumping" headings
var divObj = this.parentNode.parentNode.parentNode.parentNode;
this.parentNode.style.top = divObj.scrollTop + 'px';
}
}
,
__removeHighlightEffectFromTableHeader:function()
{
this.className='DHTMLSuite_tableWidget_headerCell';
}
,
__mousedownOnTableHeader:function()
{
this.className='DHTMLSuite_tableWigdet_headerCellDown';
if(document.all){ // I.E fix for "jumping" headings
var divObj = this.parentNode.parentNode.parentNode.parentNode;
this.parentNode.style.top = divObj.scrollTop + 'px';
}
}
,
__sortNumeric:function(a,b){
a = a.replace(/,/,'.');
b = b.replace(/,/,'.');
a = a.replace(/[^\d\.\/]/g,'');
b = b.replace(/[^\d\.\/]/g,'');
if(a.indexOf('/')>=0)a = eval(a);
if(b.indexOf('/')>=0)b = eval(b);
return a/1 - b/1;
}
,
__sortString:function(a, b) {
if ( a.toUpperCase() < b.toUpperCase() ) return -1;
if ( a.toUpperCase() > b.toUpperCase() ) return 1;
return 0;
}
,
__parseDataContentFromServer:function(ajaxIndex)
{
var content = DHTMLSuite.variableStorage.ajaxObjects[ajaxIndex].response;
if(content.indexOf('|||')==-1 && content.indexOf('###')==-1){
alert('Error in data from server\n'+content);
return;
}
this.__clearDataRows(); // Clear existing data
var rows = content.split('|||'); // Create an array of each row
for(var no=0;no<rows.length;no++){
var items = rows[no].split('###');
if(items.length>1)this.__fillDataRow(items);
}
this.__parseDataRows(this.tableObj);
}
,
__clearDataRows:function()
{
if(!this.tableObj)this.tableObj = document.getElementById(this.idOfTable);
while(this.tableObj.rows.length>1){
this.tableObj.rows[this.tableObj.rows.length-1].parentNode.removeChild(this.tableObj.rows[this.tableObj.rows.length-1]);
}
}
,
__fillDataRow:function(data)
{
if(!this.tableObj)this.tableObj = document.getElementById(this.idOfTable);
var tbody = this.tableObj.getElementsByTagName('TBODY')[0];
var row = tbody.insertRow(-1);
for(var no=0;no<data.length;no++){
var cell = row.insertCell(no);
cell.innerHTML = data[no];
}
}
,
updateTableHeader:function(columnIndex,direction)
{
var tableObj = document.getElementById(this.idOfTable);
var firstRow = tableObj.rows[0];
var tds = firstRow.cells;
var tdObj = tds[columnIndex];
tdObj.setAttribute('direction',direction);
tdObj.direction = direction;
var sortBy = tdObj.getAttribute('sortBy');
if(!sortBy)sortBy = tdObj.sortBy;
this.tableCurrentlySortedBy = sortBy;
this.__updateSortArrow(tdObj,direction);
}
,
reloadDataFromServer:function()
{
this.__getItemsFromServer();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -