新闻资讯

js表格字段排序

发布时间:2010-08-03

点击量:

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)


服务热线

服务热线

15383239821

微信咨询
微信二维码
返回顶部
×微信二维码

截屏,微信识别二维码

微信号:

(点击微信号复制,添加好友)

打开微信

微信号已复制,请打开微信添加咨询详情!