注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

我的博客

等闲识得东风面,万紫千红总是春!

 
 
 

日志

 
 

Velocity分页模板  

2010-11-25 00:21:21|  分类: java(B/S) |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

#*
宏pageGrid:自定义表格宏
${gridInfo}: 表格中的信息,含数据和分页信息,样式等
20行<!--表格样式需在引用css-->
26行<!--表格标题头行-->
47行<!--表格内容奇数行与偶数行在鼠标移动到上面时变色-->
55行<!--表格首列是否显示checkbox-->
54行<!-- 定义表格某列为链接列-->
63行<!--定义表格某列为链接列,引用页面需定义js函数griddetail('$id')-->
78行<!--在表格后加图片列用来操作-->
81行<!--在表格后加图片列用来操作引用页面需定义js函数$img.imageEvent('$id')-->
131行<!--引用循环页码-->
102行<!--checkbox批处理-->
*#

#macro (pageGrid $gridInfo)
<table width="100%">
   <!--表格内容开始-->
   <tr>
   <td>     
         <table id="listTable" class="grid">
       #set ($rowCount = 0)
             #foreach ($map in $gridInfo.list)
              #set ($row = $map.get("value"))
        #set ($colCount = 0)
        #set ($id = "")
                 #if ($rowCount == 0)
                  <tr class="blue_bold">
                     #foreach ($col in $row)
          #if ($colCount == 0)
        #if($gridInfo.gridStyle.checked)
        <th></th>
        #end
       #else
        <th>
                             $col
                             </th>       
          #end
          #set ($colCount = $colCount + 1)
         #end
         #foreach ($ecol in $gridInfo.gridStyle.columns)
          <th>
                         $ecol
                         </th>
         #end    
         </tr>
                 #else    <!--表格内容行-->
                  #set ($imp = $map.get("IMP"))
         #set ($isOddRow = $rowCount % 2 != 0)
         #if($imp == "1")
                      <tr class="text_bc03">
                  #else
                   #if ($isOddRow)
                       <tr   onMouseOver='high(this);' onMouseOut='low(this);' class='odd'>
                      #else
                       <tr   onMouseOver='high(this);' onMouseOut='low(this);' class='even'>
                      #end
                  #end
    <script>             
        function colvalue(cv)
    {
      if(cv.length>20)
      {
       var pattern=RegExp("(<IMG\\s*[\\S]*\\s*/\\s*>)([\\S]*)");
       if (pattern.exec(cv))
       {
          var str1=RegExp.$1;
          var str2=RegExp.$2;
          return str1+str2.substring(0,20)+"...";
       }
       else
       {
          return cv.substring(0,20)+"...";
       }
      }
      else
      {
       return cv;
      }
     }
   
   </script>
                     #foreach ($col in $row)
          #if ($colCount == 0)
           #set ($id = $col)
        #if($gridInfo.gridStyle.checked)
         <td><input type="checkbox" name="model.grid_check"   value="$id"/></td>
        #end
          #else
              #if ($colCount == $gridInfo.gridStyle.linkNum)
                              <td align="center" title='$col'>
                             #else
                              <td title='$col'>
           #end
              
                             #if ($col == "")
                              &nbsp;
                             #else
                                 
             #if($colCount == $gridInfo.gridStyle.linkNum)      
         <a href="javascript:griddetail('$id');" >
         <script>document.write(colvalue('$col')); </script>
         </a>
          #else
            <script>document.write(colvalue('$col')); </script>
          #end
                             #end
                             </td>
          #end
          #set ($colCount = $colCount + 1)
         #end
     
      #foreach ($imgs in $gridInfo.gridStyle.images)
             <td>
              #foreach ($img in $imgs)
                  #set ($imageEvent = $img.imageEvent)
                              <img src="$img.imagePath" alt="$img.imageTitle" onclick="javascript:img$imageEvent('$id');" style="cursor:hand"/> &nbsp; &nbsp;              
                          #end
                         </td>
         
         #end
                  </tr>
                 #end
        #set ($rowCount = $rowCount + 1)
       #end
         </table>
   </td>
   </tr>
   <!--表格内容结束-->
   <!--分页开始-->
   <tr>
    <td>
    <table   width="100%">
     <tr>
     <td align="left">
      #if($gridInfo.gridStyle.checked)
       <td>&nbsp;<input type="checkbox" name="grid_check_all" onclick="javascript:selectall();"/>全部选中</td>
      #end
     </td>
     <td align="right">
    
     #if ($gridInfo.list)
    
      #if ($gridInfo.gridStyle.pagable)
      
       #set($prepage = $gridInfo.currentpage - 1)
       #set($nextpage = $gridInfo.currentpage + 1)
      
       #if ($gridInfo.gridStyle.displaySum)
        共<font color="red">$gridInfo.sumrecords</font>条记录
        <input type="hidden" name="model.pageGridInfo.sumrecords" value="$!{model.pageGridInfo.sumrecords}">
       #end
       每页<input type="text"id="pPR" name="model.pageGridInfo.perPageRows" class="page_input"value="$gridInfo.perPageRows" onchange="document.getElementById('cpage').value='1';" />条
       共$gridInfo.sumpages页
      
       #if ($gridInfo.firstPage)
        <img src="/images/arrow_pre02.gif" onclick="page(1)">
       #else
        <img src="/images/arrow_pre02.gif">
       #end
      
       #if ($gridInfo.previousPage)
        <img src="/images/arrow_pre.gif" onclick="page($prepage)">
       #else
        <img src="/images/arrow_pre.gif">
       #end
      
       #set($indexPage =$gridInfo.currentpage/$gridInfo.prePageNum*$gridInfo.prePageNum)
          #set($lastPageNum = $indexPage+$gridInfo.prePageNum)
       #pagePrint($indexPage $gridInfo.prePageNum   $gridInfo.sumpages $lastPageNum)
      
       #if ($gridInfo.nextPage)
        <img src="/images/arrow_next.gif" onclick="page($nextpage)">
       #else
        <img src="/images/arrow_next.gif">
       #end     
            
      
       #if ($gridInfo.endPage)
        <img src="/images/arrow_next02.gif" onclick="page($gridInfo.sumpages)">
       #else
        <img src="/images/arrow_next02.gif">
       #end
      
       第<input type="text"id="cpage" name="model.pageGridInfo.currentpage" class="page_input" value="$gridInfo.currentpage" />页      
     
       <script language="javascript" type="text/javascript">
      
       function pagego()
       {
        p=parseInt(document.getElementById('pPR').value);
        s=parseInt(document.getElementById('cpage').value);
        if(/[\D]/g.test(p))
        {
                            alert('每页显示记录数必须全部是数字');
                            document.getElementById('pPR').value=$gridInfo.perPageRows;
                          }
                           if(p==0)
        {
                            alert('每页显示记录数不能为零');
                            document.getElementById('pPR').value=$gridInfo.perPageRows;
                          }
        if(s<=0)
        {
          alert('页码必须大于0');
                            return s=$gridInfo.currentpage;
        }
        if(s>$gridInfo.sumpages)
        {
          alert('页码必须小于总页数');
                            return s=$gridInfo.currentpage;
        }
        if(/[\D]/g.test(s))
        {
                            alert('页码必须全部是数字');
                            return s=$gridInfo.currentpage;
                          }
                          else
                          {
          return s;
        }
       }
                      </script>
                      <input type="button" name="pageGo"   value="GO" onclick="page(pagego());" />
      #end
     #end
     </td>
     </tr>
    </table>
    </td>
   </tr>
<!--分页结束-->
</table>
#end
<!--定义循环页码-->
#macro (pagePrint $indexPage $prePageNum   $sumpages $lastPageNum)

#if ($indexPage<$lastPageNum&&$indexPage<$sumpages)

#set($indexPage =$indexPage+1)
<a href="javascript:page($indexPage)" >$indexPage</a>
#pagePrint($indexPage $prePageNum   $sumpages $lastPageNum)
  
#end
#end

  评论这张
 
阅读(2073)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017