0
点赞
收藏
分享

微信扫一扫

extremetable改装


在一个项目中用到了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>


举报

相关推荐

0 条评论