在一个项目中用到了extremetable,但是有些的体现形式还不符合业务的需求,所以做了些改动。下面贴出来,供大家参考:
主要增加功能:加入 全选 反选 全不选 的按钮,外观布置改动,增加table的td监听事件。
首先在http://extremecomponents.org/下载eXtremeComponents 1.0.1 的源码
修改org.extremecomponents.table.view.DefaultToolbar如下:
<br />/*<br /> * Copyright 2004 original author or authors.<br /> *<br /> * Licensed under the Apache License, Version 2.0 (the "License");<br /> * you may not use this file except in compliance with the License.<br /> * You may obtain a copy of the License at<br /> *<br /> * http://www.apache.org/licenses/LICENSE-2.0<br /> *<br /> * Unless required by applicable law or agreed to in writing, software<br /> * distributed under the License is distributed on an "AS IS" BASIS,<br /> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br /> * See the License for the specific language governing permissions and<br /> * limitations under the License.<br /> */<br />package org.extremecomponents.table.view;<br /><br />import java.util.Iterator;<br /><br />import org.extremecomponents.table.bean.Export;<br />import org.extremecomponents.table.core.TableModel;<br />import org.extremecomponents.table.view.html.BuilderConstants;<br />import org.extremecomponents.table.view.html.BuilderUtils;<br />import org.extremecomponents.table.view.html.TwoColumnTableLayout;<br />import org.extremecomponents.util.HtmlBuilder;<br /><br />import com.ite.common.system.extremetable.CustomToolbarBuilder;<br /><br />/**<br /> * @author Jeff Johnston<br /> * alter by leo 2007 03 08<br /> */<br />public class DefaultToolbar extends TwoColumnTableLayout {<br /> public DefaultToolbar(HtmlBuilder html, TableModel model) {<br /> super(html, model);<br /> }<br /><br /> protected boolean showLayout(TableModel model) {<br /> boolean showPagination = BuilderUtils.showPagination(model);<br /> boolean showExports = BuilderUtils.showExports(model);<br /> boolean showTitle = BuilderUtils.showTitle(model);<br /> if (!showPagination && !showExports && !showTitle) {<br /> return false;<br /> }<br /><br /> return true;<br /> }<br /><br /> protected void columnLeft(HtmlBuilder html, TableModel model) {<br /> html.td(2).close();<br /> //new TableBuilder(html, model).title();<br /> html.append("选择:<a class=\"check\" href=\"#\" onclick=\"javascript:selectAll();\">全选</a>-");<br /> html.append("<a class=\"check\" href=\"#\" onclick=\"javascript:switchselect();\">反选</a>-");<br /> html.append("<a class=\"check\" href=\"#\" onclick=\"javascript:unselect();\">全不选</a> ");<br /> html.tdEnd();<br /> }<br /><br /> protected void columnRight(HtmlBuilder html, TableModel model) {<br /> boolean showPagination = BuilderUtils.showPagination(model);<br /> boolean showExports = BuilderUtils.showExports(model);<br /><br /> ToolbarBuilder toolbarBuilder = new ToolbarBuilder(html, model);<br /> //CustomToolbarBuilder toolbarBuilder = new CustomToolbarBuilder(html, model);<br /><br /> html.td(2).align("right").close();<br /><br /> html.table(2).border("0").cellPadding("0").cellSpacing("1").styleClass(BuilderConstants.TOOLBAR_CSS).close();<br /><br /> html.tr(3).close();<br /><br /> if (showPagination) {<br /><br /> html.td(4).close();<br /> toolbarBuilder.firstPageItemAsImage();<br /> html.tdEnd();<br /><br /> html.td(4).close();<br /> toolbarBuilder.prevPageItemAsImage();<br /> html.tdEnd();<br /><br /> html.td(4).close();<br /> toolbarBuilder.nextPageItemAsImage();<br /> html.tdEnd();<br /><br /> html.td(4).close();<br /> toolbarBuilder.lastPageItemAsImage();<br /> html.tdEnd();<br /><br /> html.td(4).close();<br /> toolbarBuilder.separator();<br /> html.tdEnd();<br /><br /> html.td(4).close();<br /> html.img();<br /> html.src(BuilderUtils.getImage(model, "pageDisplayed"));<br /> html.style("border:0");<br /> html.alt("当前页码");<br /> html.xclose();<br /> toolbarBuilder.pagesDisplayedDroplist();<br /> html.tdEnd();<br /><br /> html.td(4).close();<br /> toolbarBuilder.separator();<br /> html.tdEnd();<br /> <br /> html.td(4).close();<br /> html.img();<br /> html.src(BuilderUtils.getImage(model, BuilderConstants.TOOLBAR_ROWS_DISPLAYED_IMAGE));<br /> html.style("border:0");<br /> html.alt("每页显示");<br /> html.xclose();<br /> toolbarBuilder.rowsDisplayedDroplist();<br /> html.tdEnd();<br /><br /> if (showExports) {<br /> html.td(4).close();<br /> toolbarBuilder.separator();<br /> html.tdEnd();<br /> }<br /> }<br /><br /> if (showExports) {<br /> Iterator iterator = model.getExportHandler().getExports().iterator();<br /> for (Iterator iter = iterator; iter.hasNext();) {<br /> //html.td(4).close();<br /> <br /> html.td(4).close();<br /> html.img();<br /> html.src(BuilderUtils.getImage(model, "ExcelExport"));<br /> //html.style("border:0");<br /> html.alt("导出为Excel");<br /> html.xclose();<br /> <br /> Export export = (Export) iter.next();<br /> toolbarBuilder.exportItemAsImage(export);<br /> html.tdEnd();<br /> }<br /> }<br /><br /> html.trEnd(3);<br /><br /> html.tableEnd(2);<br /> html.newline();<br /> html.tabs(2);<br /><br /> html.tdEnd();<br /> }<br />}<br />
然后修改org.extremecomponents.table.view.HtmlView
<br />/*<br /> * Copyright 2004 original author or authors.<br /> *<br /> * Licensed under the Apache License, Version 2.0 (the "License");<br /> * you may not use this file except in compliance with the License.<br /> * You may obtain a copy of the License at<br /> *<br /> * http://www.apache.org/licenses/LICENSE-2.0<br /> *<br /> * Unless required by applicable law or agreed to in writing, software<br /> * distributed under the License is distributed on an "AS IS" BASIS,<br /> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br /> * See the License for the specific language governing permissions and<br /> * limitations under the License.<br /> */<br />package org.extremecomponents.table.view;<br /><br />import org.extremecomponents.table.core.TableModel;<br />import org.extremecomponents.util.HtmlBuilder;<br /><br />/**<br /> * @author Jeff Johnston alter by leo 2007 03 08<br /> */<br />public class HtmlView extends AbstractHtmlView {<br /> protected void beforeBodyInternal(TableModel model) {<br /> toolbar(getHtmlBuilder(), getTableModel());<br /> <br /> getTableBuilder().tableStart();<br /><br /> getTableBuilder().theadStart();<br /> <br /> //statusBar(getHtmlBuilder(), getTableModel());<br /> <br /> getTableBuilder().filterRow();<br /><br /> getTableBuilder().headerRow();<br /><br /> getTableBuilder().theadEnd();<br /><br /> getTableBuilder().tbodyStart();<br /> }<br /><br /> protected void afterBodyInternal(TableModel model) {<br /> getCalcBuilder().defaultCalcLayout();<br /><br /> getTableBuilder().tbodyEnd();<br /><br /> statusBar(getHtmlBuilder(), getTableModel());<br /><br /> getTableBuilder().tableEnd();<br /> <br /> }<br /> <br /> protected void toolbar(HtmlBuilder html, TableModel model) {<br /> new DefaultToolbar(html, model).layout();<br /> }<br /><br /> protected void statusBar(HtmlBuilder html, TableModel model) {<br /> new DefaultStatusBar(html, model).layout();<br /> }<br />}<br /><br />
下面是一个js的公共的函数,因为时间关系,没有融入到代码里面,以后会完善。现在只要include到jsp中就可以了。
<br /><br /><%@ page language="java" pageEncoding="gb2312"%><br /><%<br />response.setHeader("Pragma","No-cache"); <br />response.setHeader("Cache-Control","no-cache"); <br />response.setDateHeader("Expires", 0); <br />//create by leo 2007-03-08<br />%><br /><link rel="stylesheet" type="text/css" href="../css/extremecomponents.css"><br /><script type="text/javascript"><br /> ///select all<br /> function selectAll() {<br /> var i = document.getElementsByName("checkbox").length;<br /> if (i == 1) {<br /> document.forms.ec.checkbox.checked = true;<br /> } else {<br /> if (i > 1) {<br /> for (i = 0; i < document.forms.ec.checkbox.length; i++) {<br /> document.forms.ec.checkbox<i>.checked = true;<br /> }<br /> }<br /> }<br /> }<br /> <br /> //unselect all<br /> function unselect() {<br /> var i = document.getElementsByName("checkbox").length;<br /> if (i == 1) {<br /> document.forms.ec.checkbox.checked = false;<br /> } else {<br /> if (i > 1) {<br /> for (i = 0; i < document.forms.ec.checkbox.length; i++) {<br /> document.forms.ec.checkbox<i>.checked = false;<br /> }<br /> }<br /> }<br /> }<br /> <br /> ///switchselect<br /> function switchselect() {<br /> var i = document.getElementsByName("checkbox").length;<br /> if (i == 1) {<br /> document.forms.ec.checkbox.checked = !document.forms.ec.checkbox.checked;<br /> } else {<br /> if (i > 1) {<br /> for (i = 0; i < document.forms.ec.checkbox.length; i++) {<br /> document.forms.ec.checkbox<i>.checked = !document.forms.ec.checkbox<i>.checked;<br /> }<br /> }<br /> }<br /> }<br /><br /> //table event<br /> function runTableOnClick(TableHandle){<br /> var e = event.srcElement;<br /> //alert("e.tagName is "+e.tagName);<br /> //alert("e.rowIndex is "+e.rowIndex);<br /> //alert("e.parentElement is "+e.parentElement);<br /> <br /> if(typeof(e.tagName)=='undefined') return; <br /> if (e.tagName == 'TABLE' || e.tagName == 'TR' || e.tagName == 'TBODY') return;<br /> while (e.tagName != 'TR') e = e.parentElement;<br /> //alert("e.tagName is "+e.tagName);<br /> if (e.rowIndex == 0 || e.className == 'itemDisabled') return;<br /> var el = e;<br /> while (el.tagName != 'TABLE') el = el.parentElement;<br /> //alert("el.rows.length is "+el.rows.length);<br /> for (var i = 0; i < el.rows.length; i++){<br /> if (el.rows(i).className == 'itemOver'){<br /> el.rows(i).className = 'itemOut';<br /> break;<br /> }<br /> }<br /> e.className = 'itemOver';<br /> //if (TableHandle != null){<br /> // if (event.button == 2) menuShow(TableHandle); else menuHide(TableHandle);<br /> //}<br /> }<br /> <br /> //number only<br /> function JHshNumberText()<br /> {<br /> if ( !(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))&& (window.event.keyCode <= 90)))<br /> {<br /> window.event.keyCode = 0 ;<br /> alert("请输入0-9之间的字符!");<br /> }<br /> } <br /></script><br />
老头您好! 最近项目也打算用这控件,可是扩展起来感觉有些费事,由于刚参加工作不久,底子薄,能不能把你修改后的源码给小弟分享一下,不胜感激。
很多年前的东西了,现在几乎找不到了,上面就是源码,你看看吧。。现在这方面的开源控件很多,这个已经停止开发了,找找新的啊。
老头您好!我也是初学者,晚上用你的方法,都改好了,可用源码的test.jsp就是出不来你说的那效果,是不是我下的源码有问题?最好能有源码的架构说明。帮帮我,谢谢。
博爱老头:你好!我源代码修改后如何编译啊,我修改后的单个文件编译会出错,编译不成功。能告诉我怎么编译的吗?谢谢!!
如果是eclipse等工具的话,会自动编译,至于报错就要看报什么错误了。
你好,能不能也给我发一份,我也遇到了这个问题。谢谢了! 77860101@qq.com
这个貌似找不到了。 你直接看上面的代码把。
哦,这样啊,谢谢,楼主了,能把以前你研究的源代码共享一下吗?
chengtwocow@126.com
感激!
代码找不到了,下原包之后,按照上面的修改吧。