JS操作梦行表格按TR属性值排序
1JS
		var last_v,last_id;
		$("td>span[class~='sorting']").click(function(){
			if(!$(this).attr('attr_key')){return false;}
			attr_key=$(this).attr('attr_key');
			$("#<?php echo $module['module_name'];?>_table tbody>tr ").removeAttr('each');
			last_num=0;
			last_v=-999999.99;
			last_id='';
			/**/
			if($(this).attr('class')!='sorting_desc'){
				$("#<?php echo $module['module_name'];?>_table thead td .sorting_desc").attr('class','sorting');
				$("#<?php echo $module['module_name'];?>_table thead td .sorting_asc").attr('class','sorting');
				
				$(this).attr('class','sorting_desc'); 
				$("#<?php echo $module['module_name'];?>_table tbody>tr ").each(function(index){
					if($(this).attr(attr_key)==undefined){return true;}
					if($(this).attr('each')){return true;}
					this_line=$("#"+$(this).attr('id'));
					this_id=$(this).attr('id');
					this_val=parseFloat($(this).attr(attr_key));
					if(this_val==0){
						$("#"+$(this).attr('id')).insertBefore($("#<?php echo $module['module_name'];?>_table tbody>tr:last-child "));	
						return true;
					}
					if(last_id!='' && this_val==last_v){
						$("#"+$(this).attr('id')).insertBefore($("#"+last_id));	
						return true;
					}
					last_v=this_val;
					last_id=$(this).attr('id');
					$("#<?php echo $module['module_name'];?>_table tbody>tr ").each(function(){
						if($(this).attr(attr_key)==undefined || $(this).attr('id')==this_id){return true;}
						//console.log(this_val+'>='+ parseFloat($(this).attr(attr_key)));
						if(this_val <= parseFloat($(this).attr(attr_key))){
							$("#"+$(this).attr('id')).insertBefore($("#"+this_id));	
								
						}	
						
					});
					
					$(this).attr('each',1);	
				});	
				
				$("#<?php echo $module['module_name'];?>_table tbody>tr ").removeAttr('each');
			}else{
				last_v=-999999.99;
				last_id='';
				$("#<?php echo $module['module_name'];?>_table thead td .sorting_desc").attr('class','sorting');
				$("#<?php echo $module['module_name'];?>_table thead td .sorting_asc").attr('class','sorting');
				$(this).attr('class','sorting_asc'); 
				$("#<?php echo $module['module_name'];?>_table tbody>tr ").each(function(index){
					if($(this).attr(attr_key)==undefined){return true;}
					if($(this).attr('each')){return true;}
					this_line=$("#"+$(this).attr('id'));
					this_id=$(this).attr('id');
					this_val=parseFloat($(this).attr(attr_key));
					if(this_val==0){return true;}
					if(last_id!='' && this_val==last_v){
						$("#"+$(this).attr('id')).insertBefore($("#"+last_id));
						//$("#"+$(this).attr('id')).insertBefore($("#"+this_id));	
						return true;
					}
					last_v=this_val;
					last_id=$(this).attr('id');
					
					
					$("#<?php echo $module['module_name'];?>_table tbody>tr ").each(function(){
						if($(this).attr(attr_key)==undefined || $(this).attr('id')==this_id){return true;}

						//console.log(this_val+'>='+ parseFloat($(this).attr(attr_key)));
						if(this_val >= parseFloat($(this).attr(attr_key))){
							$("#"+$(this).attr('id')).insertBefore($("#"+this_id));	
						
						}						
					});
					$(this).attr('each',1);	
				});	
				
				$("#<?php echo $module['module_name'];?>_table tbody>tr ").removeAttr('each');
			}
			return false;
		});	
		
本页由《梦行文档》生成

 

name完成
30