首页 优化推广 js表格字段排序

js表格字段排序

来源: | 时间:2010/8/3 16:56:51 |

1.比较函数生成器:

view plaincopy to clipboardprint?
 
function  generateCompareTRs(iCol, sDataType) {  
     return   function  compareTRs(oTR1, oTR2) {  
        vValue1 = convert(oTR1.cells[iCol].firstChild.nodeValue, sDataType);  
        vValue2 = convert(oTR2.cells[iCol].firstChild.nodeValue, sDataType);  
         if  (vValue1 < vValue2) {  
             return  -1;  
        else   if  (vValue1 > vValue2) {  
             return  1;  
        else  
             return  0;  
        
    };  


function  generateCompareTRs(iCol, sDataType) {
     return   function  compareTRs(oTR1, oTR2) {
        vValue1 = convert(oTR1.cells[iCol].firstChild.nodeValue, sDataType);
        vValue2 = convert(oTR2.cells[iCol].firstChild.nodeValue, sDataType);
         if  (vValue1 < vValue2) {
             return  -1;
        else   if  (vValue1 > vValue2) {
             return  1;
        else  {
             return  0;
        }
    };
}
2.处理比较字符类型:

view plaincopy to clipboardprint?
 
function  convert(sValue, sDataType) {  
     switch  (sDataType) {  
     case   "int" :  
         return  parseInt(sValue);  
     case   "float" :  
         return  parseFloat(sValue);  
     case   "date" :  
         return   new  Date(Date.parse(sValue));  
     default :  
         return  sValue.toString();  
    


function  convert(sValue, sDataType) {
     switch  (sDataType) {
     case   "int" :
         return  parseInt(sValue);
     case   "float" :
         return  parseFloat(sValue);
     case   "date" :
         return   new  Date(Date.parse(sValue)

服务热线

153 8323 9821

功能和特性

价格和优惠

网站和维护

推广和优化

微信服务号