JSF表格的行列合并

JSF1.2对于表格的行列合并支持,并不太好。

花点时间,还是把这问题摆平吧,毕竟行列合并的用处比较多,借鉴网上的一段程序,修改了一下,也算一个解决方法。

思路:先将数据全部取出,在datatable中显示出来,然后在前端将内容相同的行进行合并,可以使用jQuery。列合并类之。

 

//函数说明:合并指定表格(表格id为table_id)指定列(列数为table_colnum)的相同文本的相邻单元格  
 //参数说明:table_id 为需要进行合并单元格的表格的id。如在HTMl中指定表格 id="data" ,此参数应为 #data   
//参数说明:table_colnum 为需要合并单元格的所在列。为数字,从最左边第一列为1开始算起。  
//参数说明:cols 表示该数组元素表示的列的合并的行数与 table_colnum一样。如table_colnum列第1行至第3行进行了合并,则cols中的所有列也在1行和3行之间进行合并操作。
//参数说明:tag表示是否要进行合并 
function table_rowspan(table_id,table_colnum, cols, tag){  
	 table_firsttd = "";  
	 table_currenttd = "";  
	 table_SpanNum = 0;  
	 table_Obj = jQuery(table_id + " tr td:nth-child(" + table_colnum + ")");
			     
	var table_othertds = new Array();
	if(cols.length > 0){
		for(var n=0; n<cols.length; n++){
			table_othertd = jQuery(table_id + " tr td:nth-child(" + cols[n] + ")");
			 table_othertds[n] = table_othertd;
		}
	
	var j = 0;
			     
	table_Obj.each(function(i){
		 j = i;
		if(i==0){  
			 table_firsttd = jQuery(this);  
			 table_SpanNum = 1;  
		}else{  
			 table_currenttd = jQuery(this);  
			 if(table_firsttd.text()==table_currenttd.text()){  
			           table_SpanNum++;
			           if(tag){
			                 	table_currenttd.hide(); //remove();
			                 	table_firsttd.attr("rowSpan",table_SpanNum);
			             }
			                 
			     }else{
			             	 for(var m=0; m<table_othertds.length; m++) {
			             	 	 otherrowspan(table_othertds[m], table_SpanNum, i-table_SpanNum);
			             	 }
			                 table_firsttd = jQuery(this);  
			                 table_SpanNum = 1;  
			             }  
			         } 
			     });
			     
	 if(j>0){
		for(var m=0; m<table_othertds.length; m++) {
	             	 	otherrowspan(table_othertds[m], table_SpanNum, j-table_SpanNum+1);
	             	}
	}
}
 
//函数说明:合并指定表格的列(表格id为table_id),从 beginIndex行开始,共合并spanNum行
//参数说明:table_othertd 为需要进行合并的列的jQuery对象。
//参数说明:beginIndex 表示从该行开始合并。
function otherrowspan(table_othertd, spanNum, beginIndex){
	table_firsttd = "";  
                table_currenttd = "";
	table_SpanNum = 0;
	table_othertd.each(function(i){
		if(i==beginIndex){
			table_firsttd = jQuery(this); 
			table_SpanNum = 1;
		}else if(i>beginIndex && i<spanNum+beginIndex){
			table_currenttd = jQuery(this);
			 if(table_firsttd.text()==table_currenttd.text()){  
			 table_SpanNum++;  
			 table_currenttd.hide(); //remove();  
			 table_firsttd.attr("rowSpan",table_SpanNum);
		      }else{  
			 table_firsttd = jQuery(this);
			  table_SpanNum = 1; 
		        }
		}
	});
} 
还有一种情况:表格中某列的合并边界与另一列保持一致,可以用下面的方法
 
 //函数说明:合并指定表格(表格id为table_id),将col2列的合并情况与col1一样 
//参数说明:table_id 为需要进行合并单元格的表格的id。
function spanRowLikeSomeone(table_id, col1,col2){
	var smallClass = jQuery(table_id + " tr td:nth-child(" + col1 + ")");
	var totalRate = jQuery(table_id + " tr td:nth-child(" + col2 + ")");
	smallClass.each(function(i){
		var spanNum = jQuery(this).attr("rowSpan");
		var isHidden = jQuery(this).is(":hidden");
		totalRate.each(function(j){
			if(j==i){
				jQuery(this).attr("rowSpan",spanNum);
				if(isHidden){
						jQuery(this).hide();
					}
				}
		});
	}	
}
   

 对于var isHidden = jQuery(this).is(":hidden");这行代码需要说明一下,col1合并的时候不是将内容相同的行删除,而是隐藏,否则这个方法是不会起作用的。

 

由于我对jQuery不熟,可能代码不够严谨。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于Spring Boot整合JSF,你可以按照以下步骤进操作: 1. 添加JSF依赖:在pom.xml文件中,添加JSF的依赖项,如下所示: ```xml <dependency> <groupId>javax.faces</groupId> <artifactId>javax.faces-api</artifactId> <version>2.3</version> </dependency> ``` 2. 配置JSF Servlet:在Spring Boot的配置类中,添加以下配置,以将JSF Servlet映射到`/javax.faces`路径下: ```java import javax.faces.webapp.FacesServlet; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class JsfConfig { @Bean public ServletRegistrationBean<FacesServlet> facesServletRegistration() { ServletRegistrationBean<FacesServlet> registration = new ServletRegistrationBean<>(new FacesServlet(), "*.jsf"); registration.setName("FacesServlet"); return registration; } } ``` 3. 配置JSF View Resolver:在Spring Boot的配置类中,添加以下配置,以将JSF视图解析为`.xhtml`文件: ```java import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration public class JsfConfig { @Bean public ViewResolver internalResourceViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setViewClass(JsfView.class); resolver.setPrefix("/WEB-INF/views/"); resolver.setSuffix(".xhtml"); return resolver; } } ``` 4. 创建JSF视图:在`/WEB-INF/views/`目录下创建JSF视图文件,例如`hello.xhtml`,并在其中定义JSF组件。 现在,你已经成功地将Spring Boot与JSF整合起来了。你可以在JSF视图中使用JSF的标签和组件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值