extremetable改装

news/2024/7/7 7:54:12
http://www.icnote.com/Extreme-Table/
在一个项目中用到了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("选择:<a class=\"check\" href=\"#\" οnclick=\"javascript:selectAll();\">全选</a>-");
        html.append("<a class=\"check\" href=\"#\" οnclick=\"javascript:switchselect();\">反选</a>-");
        html.append("<a class=\"check\" href=\"#\" οnclick=\"javascript:unselect();\">全不选</a> ");
        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   
%>   
<link rel="stylesheet" type="text/css" href="../css/extremecomponents.css">   
<script type="text/javascript">   
    ///select all   
    function selectAll() {   
      var i = document.getElementsByName("checkbox").length;   
      if (i == 1) {   
        document.forms.ec.checkbox.checked = true;   
      } else {   
        if (i > 1) {   
          for (i = 0; i < document.forms.ec.checkbox.length; i++) {   
            document.forms.ec.checkbox[i].checked = true;   
          }   
        }   
      }   
    }   
         
    //unselect all   
    function unselect() {   
      var i = document.getElementsByName("checkbox").length;   
      if (i == 1) {   
        document.forms.ec.checkbox.checked = false;   
      } else {   
        if (i > 1) {   
          for (i = 0; i < document.forms.ec.checkbox.length; i++) {   
            document.forms.ec.checkbox[i].checked = false;   
          }   
        }   
      }   
    }   
         
    ///switchselect   
    function switchselect() {   
      var i = document.getElementsByName("checkbox").length;   
      if (i == 1) {   
        document.forms.ec.checkbox.checked = !document.forms.ec.checkbox.checked;   
      } else {   
        if (i > 1) {   
          for (i = 0; i < document.forms.ec.checkbox.length; i++) {   
            document.forms.ec.checkbox[i].checked = !document.forms.ec.checkbox[i].checked;   
          }   
        }   
      }   
    }   
  
  //table event   
  function runTableOnClick(TableHandle){   
    var e = event.srcElement;   
    //alert("e.tagName is "+e.tagName);   
    //alert("e.rowIndex is "+e.rowIndex);   
    //alert("e.parentElement is "+e.parentElement);   
       
    if(typeof(e.tagName)=='undefined') return;     
    if (e.tagName == 'TABLE' || e.tagName == 'TR' || e.tagName == 'TBODY') return;   
    while (e.tagName != 'TR') e = e.parentElement;   
    //alert("e.tagName is "+e.tagName);   
    if (e.rowIndex == 0 || e.className == 'itemDisabled') return;   
    var el = e;   
    while (el.tagName != 'TABLE') el = el.parentElement;   
    //alert("el.rows.length is "+el.rows.length);   
    for (var i = 0; i < el.rows.length; i++){   
      if (el.rows(i).className == 'itemOver'){   
        el.rows(i).className = 'itemOut';   
        break;   
      }   
    }   
    e.className = 'itemOver';   
    //if (TableHandle != null){   
    //  if (event.button == 2) menuShow(TableHandle); else menuHide(TableHandle);   
    //}   
    }   
       
    //number only   
    function JHshNumberText()   
            {   
              if ( !(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))&& (window.event.keyCode <= 90)))   
                {   
                  window.event.keyCode = 0 ;   
                  alert("请输入0-9之间的字符!");   
                }   
            }     
</script>   


http://www.niftyadmin.cn/n/1733049.html

相关文章

web端 css hack(一)

逢10月小长假&#xff0c;几天不敲键盘&#xff0c;浑身难受。也是有时间分享一下自己遇到的css问题。先说一下什么css hack 简单介绍一下css hack&#xff1a; 定义&#xff1a; 一般都是利用各浏览器的支持CSS的能力和BUG来进行的&#xff0c;可以分为能力选择和怪癖选择(BU…

将本地已有项目添加到gitee仓库中

陈拓 2021/09/16-2021/09/17 1. 创建gitee仓库hk-Console 新建 点击 仓库地址 https://gitee.com/linkdle/hk-console 2. 克隆hk-Console 我的系统克隆hk-Console到本地 git clone https://gitee.com/linkdle/hk-console.git 查看hk-console 进入目录hk-console cd hk-cons…

修改git commit的注释

2021/09/17-2020/09/17 在《将本地已有项目添加到gitee仓库中》 https://zhuanlan.zhihu.com/p/411306340 https://blog.csdn.net/chentuo2000/article/details/120345622 一文中我们已经发布(push)了几个项目到gitee仓库&#xff0c; 下面我们将远程的注释“海康NVR工具集…

01html基础

01_html 1 Mac中的快捷键 基础快捷键&#xff1a; command c 复制command v 粘贴command m 最小化当前窗口Shift command c 桌面环境打开Findercommand space 输入法切换fn F3 快速显示桌面command tab 切换应用程序command shift N 在打开Finder后快速建立文件夹command sh…

Oracle 用户数据字典 以及 查询表字段

http://www.blogjava.net/xiaohewoai/archive/2010/02/01/311532.html查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * from user_role_privs; 查看当前用户的系统权限和表级权限 SQL>select * f…

git上传修改过的代码和创建标签

2021/09/18-2021/12/27 在《将本地已有项目添加到gitee仓库中》 https://zhuanlan.zhihu.com/p/411306340 https://blog.csdn.net/chentuo2000/article/details/120345622 一文中我们已经发布(push)了几个项目到gitee仓库。 在《修改git commit的注释》 https://zhuanlan.…

extremetable+hibernate实现分页 关于结合hibernate后台数据分页和eXtremeTable分页功能的使用 ...

http://blog.csdn.net/tigerflower/archive/2006/08/22/1105036.aspxeXtremeComponents是一系列提供高级显 示的开源JSP定制标签。当前的包含 的组件为eXtremeTable&#xff0c;用于以表的形式显示数据。eXtremeTable提 供了一个很好的分页特性&#xff0c;但是如何结合hiberna…

text-align: justify;不能均匀分布问题

本文地址&#xff1a;http://www.cnblogs.com/veinyin/p/7617610.html 对于text-align来说&#xff0c;一般我们都是使用居中这个属性值&#xff0c;突然今天需要达到这样一个效果&#xff1a; 对&#xff0c;就是“上海活动”这四个字在所在的区域均匀分布 1 <li class&qu…