`
snoopy7713
  • 浏览: 1124462 次
  • 性别: Icon_minigender_2
  • 来自: 火星郊区
博客专栏
Group-logo
OSGi
浏览量:0
社区版块
存档分类
最新评论

Velocity分页模板

阅读更多

#*
宏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

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics