extremetable改装
2023-04-12
在一个项目中用到了extremetable,但是有些的体现形式还不符合业务的需求,所以做了些改动。下面贴出来,供大家参考:
主要增加功能:加入 全选 反选 全不选 的按钮,外观布置改动,增加table的td监听事件。
首先在http://extremecomponents.org/下载eXtremeComponents 1.0.1 的源码
修改org.extremecomponents.table.view.DefaultToolbar如下:
/*
* Copyright 2004 original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.extremecomponents.table.view;
import java.util.Iterator;
import org.extremecomponents.table.bean.Export;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.view.html.BuilderConstants;
import org.extremecomponents.table.view.html.BuilderUtils;
import org.extremecomponents.table.view.html.TwoColumnTableLayout;
import org.extremecomponents.util.HtmlBuilder;
import com.ite.common.system.extremetable.CustomToolbarBuilder;
/**
* @author Jeff Johnston
* alter by leo 2007 03 08
*/
public class DefaultToolbar extends TwoColumnTableLayout {
public DefaultToolbar(HtmlBuilder html, TableModel model) {
super(html, model);
}
protected boolean showLayout(TableModel model) {
boolean showPagination = BuilderUtils.showPagination(model);
boolean showExports = BuilderUtils.showExports(model);
boolean showTitle = BuilderUtils.showTitle(model);
if (!showPagination && !showExports && !showTitle) {
return false;
}
return true;
}
protected void columnLeft(HtmlBuilder html, TableModel model) {
html.td(2).close();
//new TableBuilder(html, model).title();
html.append("选择:全选-");
html.append("反选-");
html.append("全不选 ");
html.tdEnd();
}
protected void columnRight(HtmlBuilder html, TableModel model) {
boolean showPagination = BuilderUtils.showPagination(model);
boolean showExports = BuilderUtils.showExports(model);
ToolbarBuilder toolbarBuilder = new ToolbarBuilder(html, model);
//CustomToolbarBuilder toolbarBuilder = new CustomToolbarBuilder(html, model);
html.td(2).align("right").close();
html.table(2).border("0").cellPadding("0").cellSpacing("1").styleClass(BuilderConstants.TOOLBAR_CSS).close();
html.tr(3).close();
if (showPagination) {
html.td(4).close();
toolbarBuilder.firstPageItemAsImage();
html.tdEnd();
html.td(4).close();
toolbarBuilder.prevPageItemAsImage();
html.tdEnd();
html.td(4).close();
toolbarBuilder.nextPageItemAsImage();
html.tdEnd();
html.td(4).close();
toolbarBuilder.lastPageItemAsImage();
html.tdEnd();
html.td(4).close();
toolbarBuilder.separator();
html.tdEnd();
html.td(4).close();
html.img();
html.src(BuilderUtils.getImage(model, "pageDisplayed"));
html.style("border:0");
html.alt("当前页码");
html.xclose();
toolbarBuilder.pagesDisplayedDroplist();
html.tdEnd();
html.td(4).close();
toolbarBuilder.separator();
html.tdEnd();
html.td(4).close();
html.img();
html.src(BuilderUtils.getImage(model, BuilderConstants.TOOLBAR_ROWS_DISPLAYED_IMAGE));
html.style("border:0");
html.alt("每页显示");
html.xclose();
toolbarBuilder.rowsDisplayedDroplist();
html.tdEnd();
if (showExports) {
html.td(4).close();
toolbarBuilder.separator();
html.tdEnd();
}
}
if (showExports) {
Iterator iterator = model.getExportHandler().getExports().iterator();
for (Iterator iter = iterator; iter.hasNext();) {
//html.td(4).close();
html.td(4).close();
html.img();
html.src(BuilderUtils.getImage(model, "ExcelExport"));
//html.style("border:0");
html.alt("导出为Excel");
html.xclose();
Export export = (Export) iter.next();
toolbarBuilder.exportItemAsImage(export);
html.tdEnd();
}
}
html.trEnd(3);
html.tableEnd(2);
html.newline();
html.tabs(2);
html.tdEnd();
}
}
然后修改org.extremecomponents.table.view.HtmlView
/*
* Copyright 2004 original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.extremecomponents.table.view;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.util.HtmlBuilder;
/**
* @author Jeff Johnston alter by leo 2007 03 08
*/
public class HtmlView extends AbstractHtmlView {
protected void beforeBodyInternal(TableModel model) {
toolbar(getHtmlBuilder(), getTableModel());
getTableBuilder().tableStart();
getTableBuilder().theadStart();
//statusBar(getHtmlBuilder(), getTableModel());
getTableBuilder().filterRow();
getTableBuilder().headerRow();
getTableBuilder().theadEnd();
getTableBuilder().tbodyStart();
}
protected void afterBodyInternal(TableModel model) {
getCalcBuilder().defaultCalcLayout();
getTableBuilder().tbodyEnd();
statusBar(getHtmlBuilder(), getTableModel());
getTableBuilder().tableEnd();
}
protected void toolbar(HtmlBuilder html, TableModel model) {
new DefaultToolbar(html, model).layout();
}
protected void statusBar(HtmlBuilder html, TableModel model) {
new DefaultStatusBar(html, model).layout();
}
}
下面是一个js的公共的函数,因为时间关系,没有融入到代码里面,以后会完善。现在只要include到jsp中就可以了
<%@ page language="java" pageEncoding="gb2312"%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
//create by leo 2007-03-08
%>
本文仅代表作者观点,版权归原创者所有,如需转载请在文中注明来源及作者名字。
免责声明:本文系转载编辑文章,仅作分享之用。如分享内容、图片侵犯到您的版权或非授权发布,请及时与我们联系进行审核处理或删除,您可以发送材料至邮箱:service@tojoy.com




