关闭

希希table1.0

标签: tableurlclassfunctionborderinput
952人阅读 评论(0) 收藏 举报

已更新到1.1,有兴趣至

http://showlin.hinesoft.com/xxtable/demo.asp

下载

---------demo.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
'---------------------------希希Table1.0说明-----------------------------------------------
'属性   说明        默认值      
'DataSource 数据源采用的recordset对象    无
'Head  表格头,决定表格的显示方式    <table width="100%"  border="1" cellspacing="0" cellpadding="0"> 
'CanEdit 是否显示编辑栏       false
'EditUrl 处理编辑动作的地址      无
'EditField 传递参数到编辑页面的字段    id
'CanDel  是否显示删除栏       false
'DelUrl  处理删除动作的地址      无
'DelField 传递参数到删除页面的字段    id
'WriteTitle 是否显示标题行       true
'Title  显示标题的栏目名称(用","分割)   Recordset的所有Fields
'FieldsList 显示recordset对象的字段列表(用","分割) 所有Fields
'ValueOutPut 输出值支持外挂函数转换     *
'    例如"*,*,*,changeto,*,*"
'   表示第四列的值用自定义函数changeto转换
'   注意要和title和Filedslist一一对应
'
'
'方法   说明           参数
'BuildAll 用一张表格显示Recordset的全部数据     无
'BuildPage 显示带分页工具栏的表格        显示的当前页号,每页记录数,转页的url
'   (记录集必须有一个支持分页的CursorType)
'
'以下是作者信息及授权说明
'==========================希希table1.0==========================
'|                |
'|   Write By Showlin 2006          |
'|   未经作者书面允许,请勿用于商业用途       |
'|   Bug Report 和修改请Email给 Fzsalx@163.com     |
'|   欢迎光临作者blog Http://blog.csdn.net/showlin/    |
'|   祝我可爱的小女儿希希永远快乐健康!       |
'================================================================
'文件说明
'1. xxTable.asp 类文件
'2. xxtable.css 样式表
'3. xxtable.js 脚本文件
'4. demo.asp 演示文件

%>
<!-- #include file="xxTable.asp" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<link href="xxtable.css" _fcksavedurl=""xxtable.css"" rel="stylesheet" type="text/css">
<script src="xxtable.js"></script>
<script>

</script>
</head>

<body>
<%

'自定义函数对输出的值进行转换
function bbb(a)
 bbb= a+10
end function
dim conn,connstr,rs  
   connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+server.mappath("test.mdb")
   set conn=server.createobject("ADODB.CONNECTION")
   set rs=server.createobject("adodb.recordset")
   conn.open connstr
sql="select * from tb_user"

'生成recordset对象
'set rs=conn.execute(sql)
rs.open sql,conn,1,1

set table1=new xxTable 

'指定数据源,必须是一个recordset对象
table1.DataSource=rs

' 设定表格头,这决定了表格的样式
table1.head="<table width=""100%""  border=""1"" align=""center"" cellpadding=""1"" cellspacing=""1"" bordercolorlight=""#666666"" bordercolordark=""#ffffff"">"

'是否需要表标题栏,默认为true
table1.WriteTitle=true

'表标题栏字符串,注意数量要和recordset的fields个数相同,默认输出recordset的所有fields.name
'table1.Title="id,登陆名,用户名,密码"
'要显示的rs对象的字段名,默认显示全部,注意和title一一对应
'table1.FieldsList="id,loginname,username,password"
'输出的值是否经过转换,注意和fieldsList一一对应
'table1.ValueOutPut="bbb,*,*,*"
'设置有编辑选项
table1.CanEdit=true
'设置编辑Url
table1.EditUrl="Edit.asp?action=edit"

'设置有删除选项
table1.CanDel=true

'设置删除Url
table1.DelUrl="Del.asp"
' 输出一个无分页的表
'table1.buildall
page=clng(request("page"))
if page=0 then page=1
'输出一个分页表,参数依次为页号,每页记录数,翻页Url
'注意,要使用分页,recordset对象拥有一个可分页的游标
table1.BuildPage page,1,"demo.asp"
%>
</body>
</html>

 

 

 

-----xxtable.asp-----

<%
'---------------------------希希Table1.0说明-----------------------------------------------
'属性   说明        默认值      
'DataSource 数据源采用的recordset对象    无
'Head  表格头,决定表格的显示方式    <table width="100%"  border="1" cellspacing="0" cellpadding="0"> 
'CanEdit 是否显示编辑栏       false
'EditUrl 处理编辑动作的地址      无
'EditField 传递参数到编辑页面的字段    id
'CanDel  是否显示删除栏       false
'DelUrl  处理删除动作的地址      无
'DelField 传递参数到删除页面的字段    id
'WriteTitle 是否显示标题行       true
'Title  显示标题的栏目名称(用","分割)   Recordset的所有Fields
'FieldsList 显示recordset对象的字段列表(用","分割) 所有Fields
'ValueOutPut 输出值支持外挂函数转换     *
'    例如"*,*,*,changeto,*,*"
'   表示第四列的值用自定义函数changeto转换
'   注意要和title和Filedslist一一对应
'
'
'方法   说明           参数
'BuildAll 用一张表格显示Recordset的全部数据     无
'BuildPage 显示带分页工具栏的表格        显示的当前页号,每页记录数,转页的url
'   (记录集必须有一个支持分页的CursorType)
'
'以下是作者信息及授权说明
'==========================希希table1.0==========================
'|                |
'|   Write By Showlin 2006          |
'|   未经作者书面允许,请勿用于商业用途       |
'|   Bug Report 和修改请Email给 Fzsalx@163.com     |
'|   欢迎光临作者blog Http://blog.csdn.net/showlin/    |
'|   祝我可爱的小女儿希希永远快乐健康!       |
'|   xxtable.js中全选借鉴了网上的源代码,在此致谢
'================================================================
Class xxTable
 Private xDataSource '数据源
 Private xHead  '表格头
 Private xWriteTitle '是否写表格标题
 Private xTitle  '表格标题项目
 Private xFieldsList '要写得Fields列表
 Private xEdit  '是否需要编辑栏
 Private xDel  '是否需要删除栏
 Private xEditUrl '编辑的Url
 Private xDelUrl  '删除的Url
 Private xBindEditField '绑定传送的编辑字段
 Private xBindDelField '绑定传送的删除字段
 Private xValueOutPut   '输出的Value格式
 Private Sub Class_Initialize
  xHead="<table width=""100%""  border=""1"" cellspacing=""0"" cellpadding=""0"">"
  xWriteTitle=true
  xTitle="*"
  xEdit=false
  xDel=false
  xBindEditField="id"
  xBindDelField="id"
  xFieldsList="*"
  xValueOutPut="*"
 End Sub  
 Private Sub Class_Terminate()
  set xDataSource=nothing
 End Sub 

 Public Property Let ValueOutPut(TempValueOutPut)
  xValueOutPut=TempValueOutPut
 end Property
 Public Property Let Head(TempHead)
  xHead=TempHead
 end Property

 Public Property Let CanEdit(TempEdit)
  xEdit=TempEdit
 end Property

 Public Property Let EditUrl(TempEditUrl)
  xEditUrl=TempEditUrl
 end Property

 Public Property Let FieldsList(TempFieldsList)
  xFieldsList=TempFieldsList
 end Property

 Public Property Let CanDel(TempDel)
  xDel=TempDel
 end Property
 Public Property Let DelUrl(TempDelUrl)
  xDelUrl=TempDelUrl
 end Property

 Public Property Let EditField(TempEditField)
  xBindEditField=TempEditField
 end Property
 Public Property Let DelField(TempDelField)
  xBindDelField=TempDelField
 end Property


 Public Property Let WriteTitle(TempWriteTitle)
  xWriteTitle=TempWriteTitle
 end Property

 Public Property Let Title(TempTitle)
  xTitle=TempTitle
 end Property
 
  
 Public Property Let DataSource(TempDataSource)
  select case typename(TempDataSource)
   case "Recordset"
    set xDataSource=TempDataSource'.clone
   case "Variant()"
    xDataSource=TempDataSource
   case else
  end select

 end Property 
 Public Sub BuildAll()
  dim iTable,tempfieldslist,tempsubtitle,temptableclass,tempValueOutPut
  if xDel then response.write "<form action=""" & xDelUrl & """ name=""TableDelForm"" method=""post"">"
  response.write xHead
  select case TypeName(xDataSource)
   case "Recordset"
    if not xDataSource.eof then '有记录
     xDataSource.movefirst
     if xWriteTitle then  '要写标题
      response.write "<tr class=""xtablehead"">"
      if xTitle="*" then '默认写fields.name
       for iTable=0 to xDataSource.fields.count-1
        response.write "<td>" & xDataSource.fields(iTable).name & "</td>"
       next
      else    '写自定义标题
       tempsubtitle=split(xTitle,",")
       for iTable=0 to ubound(tempsubtitle)
        response.write "<td>" & tempsubtitle(iTable) & "</td>"
       next
      end if
      if xEdit then response.write "<td width=""30"">编辑</td>"
      if xDel then response.write "<td width=""30"">删除</td>"     
      response.write "</tr>"
     end if
     do until xDataSource.eof  '循环写数据
       if temptableclass="xtableline2" then
        temptableclass="xtableline1"
       else
        temptableclass="xtableline2"
       end if
      response.write "<tr class=""" & temptableclass & """  onmouseover=""ChangeTableStyle(this);"" onmouseout=""restoreTableStyle(this);"">"
      if xFieldsList="*" then '输出所有字段
       if xValueOutPut="*" then '默认输出字段的值
        for iTable=0 to xDataSource.fields.count-1
         response.write "<td>" & xDataSource.fields(iTable).value & "</td>"
        next
       else '输出字段转换的值
        tempValueOutPut=split(xValueOutPut,",")
        for iTable=0 to xDataSource.fields.count-1
         if tempValueOutPut(iTable)="*"  then  '对应字段输出的是值
          response.write "<td>" & xDataSource.fields(iTable).value & "</td>"
         else '对应字段输出的是要求转换后的值
          response.write "<td>"
          response.write eval(tempValueOutPut(iTable) & "(""" & xDataSource.fields(iTable).value & """)")
          response.write "</td>"
         end if
        next       
       end if
      else '输出fieldsList里指定的字段
       tempFieldsList=split(xFieldsList,",")
       if xValueOutPut="*" then '默认输出字段的值       
        for iTable=0 to ubound(tempFieldsList)
         response.write "<td>" & xDataSource(tempFieldsList(iTable)) & "</td>"
        next
       else '输出字段转换的值
        tempValueOutPut=split(xValueOutPut,",") 
        for iTable=0 to ubound(tempFieldsList)
         if tempValueOutPut(iTable)="*" then '对应的字段输出原值
          response.write "<td>" & xDataSource(tempFieldsList(iTable)) & "</td>"
         else  '对应的字段用自定义函数转换后输出
          response.write "<td>"
          response.write eval(tempValueOutPut(iTable) & "(""" & xDataSource(tempFieldsList(iTable)) & """)")
          response.write "</td>"
         end if
        next       
       end if
      end if
      
      if xEdit then
       response.write "<td width=""30""><a href=""" & xEditUrl
       if instr(xEditUrl,"?")>0 then
        response.write "&" & xBindEditField & "=" & xDataSource(xBindEditField)
       else
        response.write "?" & xBindEditField & "=" & xDataSource(xBindEditField)
       end if
       response.write """>编辑</a></td>"
      end if
      if xDel then response.write "<td width=""30""><input name=""piliang"" type=""checkbox"" value=""" & xDataSource(xBindDelField) & """/></td>"
      response.write "</tr>"
      xDataSource.movenext
     loop
    response.write "</table>"
    if xDel then
     response.write xHead
     response.write "<tr class=""xtabledel""><td>"
     call DelTools
     response.write "</td></tr></table>"
    end if  
    if xDel then response.write "</form>"  

    else        '输出无数据
     response.write "<tr>"
     response.write "<td colspan=""" & xDataSource.fields.count-1 & """ align=""center""><font size=""2"" color=""red"">没有任何数据!</font></td></tr>"
     response.write "</table>"
     if xDel then response.write "</form>"
    end if
    
   case "Variant()"
   case else
  end select
 end sub
 
 Public sub BuildPage(page,ps,url)
  dim iTable1,tempFieldsList,tempsubtitle,temptableclass,tempValueOutPut
  response.write xHead
  if xDel then response.write "<form action=""" & xDelUrl & """ name=""TableDelForm"" method=""post"">"
  select case TypeName(xDataSource)
   case "Recordset"
    if xDataSource.CursorType <>1 then
     response.write "<tr class=""xtableline1""><td align=""center"">该记录不支持分页</td></tr></table>"
     response.end
    end if
    if not xDataSource.eof then '有记录
     xDataSource.movefirst
     if xWriteTitle then  '要写标题
      response.write "<tr class=""xtablehead"">"
      if xTitle="*" then '默认写fields.name
       for iTable=0 to xDataSource.fields.count-1
        response.write "<td>" & xDataSource.fields(iTable).name & "</td>"
       next
      else    '写自定义标题
       tempsubtitle=split(xTitle,",")
       for iTable=0 to ubound(tempsubtitle)
        response.write "<td>" & tempsubtitle(iTable) & "</td>"
       next
      end if
      if xEdit then response.write "<td width=""30"">编辑</td>"
      if xDel then response.write "<td width=""30"">删除</td>"       
      response.write "</tr>"
     end if
     xDataSource.pagesize=ps
     if page <1 then
      xDataSource.absolutepage=1
     else
      if page>xDataSource.pagecount then
       xDataSource.absolutepage=xDataSource.pagecount
      else
       xDataSource.absolutepage = page 
      end if
     end if
     for iTable1=1 to ps  '循环写数据
       if temptableclass="xtableline2" then
        temptableclass="xtableline1"
       else
        temptableclass="xtableline2"
       end if
      response.write "<tr class=""" & temptableclass & """  onmouseover=""ChangeTableStyle(this);"" onmouseout=""restoreTableStyle(this);"">"
      if xFieldsList="*" then '输出所有字段
       if xValueOutPut="*" then '默认输出字段的值      
        for iTable=0 to xDataSource.fields.count-1
         response.write "<td>" & xDataSource.fields(iTable).value & "</td>"
        next
       else '输出字段转换的值
        tempValueOutPut=split(xValueOutPut,",")      
        for iTable=0 to xDataSource.fields.count-1
         if tempValueOutPut(iTable)="*"  then  '对应字段输出的是值        
          response.write "<td>" & xDataSource.fields(iTable).value & "</td>"
         else '对应字段输出的是要求转换后的值
          response.write "<td>"
          response.write eval(tempValueOutPut(iTable) & "(""" & xDataSource.fields(iTable).value & """)")
          response.write "</td>"
         end if    
        next
       end if    
      else  '输出字段列表里标注的字段
       tempFieldsList=split(xFieldsList,",")
       if xValueOutPut="*" then '默认输出字段的值       
        for iTable=0 to ubound(tempFieldsList)
         response.write "<td>" & xDataSource(tempFieldsList(iTable)) & "</td>"
        next
       else '输出字段转换的值
        tempValueOutPut=split(xValueOutPut,",") 
        for iTable=0 to ubound(tempFieldsList)
         if tempValueOutPut(iTable)="*" then '对应的字段输出原值
          response.write "<td>" & xDataSource(tempFieldsList(iTable)) & "</td>"
         else  '对应的字段用自定义函数转换后输出
          response.write "<td>"
'          response.write tempValueOutPut(iTable) & "(''" & xDataSource(tempFieldsList(iTable)) & "')"
          response.write eval(tempValueOutPut(iTable) & "(""" & xDataSource(tempFieldsList(iTable)) & """)")
          response.write "</td>"
         end if
        next       
       end if       
      end if      
      if xEdit then
       response.write "<td width=""30""><a href=""" & xEditUrl
       if instr(xEditUrl,"?")>0 then
        response.write "&" & xBindEditField & "=" & xDataSource(xBindEditField)
       else
        response.write "?" & xBindEditField & "=" & xDataSource(xBindEditField)
       end if
       response.write """>编辑</a></td>"
      end if
      if xDel then response.write "<td width=""30""><input name=""piliang"" type=""checkbox"" value=""" & xDataSource(xBindDelField) & """/></td>"
      response.write "</tr>"
      xDataSource.movenext
      if xDataSource.eof then exit for
     next
     if xDel then response.write "</form>"
     response.write "</table>"
     response.write xHead
     response.write "<tr class=""xtabledel"">"
     response.write "<td width=""60%"">"
     PageTool page,xDataSource.pagecount,Url
     response.write "</td>"
     if xDel then
      response.write "<td>"
      call DelTools
      response.write "</td>"
     end if  
     response.write "</tr></table>"
    else        '输出无数据
     response.write "<tr>"
     response.write "<td colspan=""" & xDataSource.fields.count-1 & """ align=""center""><font size=""2"" color=""red"">没有任何数据!</font></td></tr>"
     response.write "</table>"
     if xDel then response.write "</form>"
    end if
    
   case "Variant()"
   case else
  end select

  end sub
 
 Private sub DelTools()
  response.write "<input type=""button"" value=""全选"" onClick=""chkall(TableDelForm)"">"
  response.write "&nbsp;<input type=""button"" value=""全不选"" onClick=""unchkall(TableDelForm)"">"
  response.write "&nbsp;<input type=""button"" value=""删除"" onClick=""if(validate(TableDelForm)){document.getElementById('TableDelForm').submit();}"">"
 end sub
 
 Private sub PageTool(Page,TotalPage,Url)
  if page>totalpage then page=totalpage
  response.write "<table width=""95%"" border=""0""><form name=""pagefrm1"" id=""pagefrm1"" method=""post"" action="""& url & """><tr><td align=""right""><font size=""2"">"
  response.write "&nbsp;" & page & "/" & totalpage & "&nbsp;&nbsp;"
  if page=1 or page>totalpage then
   response.write "首 页&nbsp;&nbsp;上一页"
  else
   if instr(url,"?")>0 then
    response.write "<a href=""" & url & "&page=1"">首 页</a>&nbsp;&nbsp;<a href=""" & url & "&page=" & page-1 & """>上一页</a>"
   else
    response.write "<a href=""" & url & "?page=1"">首 页</a>&nbsp;&nbsp;<a href=""" & url & "?page=" & page-1 & """>上一页</a>"
   end if
  end if
  response.write "&nbsp;&nbsp;"
  if page=totalpage or totalpage=0 or page>totalpage then
   response.write "下一页&nbsp;&nbsp;末 页"
  else
  if instr(url,"?")>0 then
   response.write "<a href=""" & url & "&page=" & page+1 & """>下一页</a>&nbsp;&nbsp;<a href=""" & url & "&page=" & totalpage & """>末 页</a>&nbsp;&nbsp;"
  else
   response.write "<a href=""" & url & "?page=" & page+1 & """>下一页</a>&nbsp;&nbsp;<a href=""" & url & "?page=" & totalpage & """>末 页</a>&nbsp;&nbsp;"
  end if
  end if
  response.write "&nbsp;&nbsp;转到<input name=""page"" type=""text"" id=""page"" value=""" & page & """ size=""3"" maxlength=""5"" class=""input"">页</font>"
'  response.write "<input type=""button"" name=""Submit"" value=""Go"" onclick=""document.getElementById('pagefrm1').submit();"">"
  response.write "<input type=""submit"" name=""Submit"" value=""Go"">"
  response.write "</td></tr></form></table>" 
 end sub
end Class
%>

 

 

 

---------xxtable.js----------

// JavaScript Document
 var s_temp_className="";
 function ChangeTableStyle(obj){
  s_temp_className=obj.className; 
  obj.className="xtablelight";
 }
 function restoreTableStyle(obj){
  obj.className=s_temp_className;
 }

    function validate(obj_form){ //删除按扭的功能
  var ccount=0;
  var len=0;
  var frm = obj_form;        //得到要操作的form;
  var length = frm.elements.length;        //得到frm中的元素个数;
  for(var i=0;i<length;i++){
   if (frm(i).type=='checkbox') len=len+1;
  }
   // alert(checkbox.length);
  if (len>1){
   for (var i=0;i<obj_form.piliang.length;i++){
    if (obj_form.piliang[i].checked){
     ccount=ccount+1;
    }
   }
     // alert(ccount);
   if (ccount<=0){
    alert("请先选择要删除的项目");
    return false;
   }else{
//    if (confirm("删除后不能恢复!你确定要删除这"+ccount+"项?")) obj_form.submit();
    return confirm("删除后不能恢复!你确定要删除这"+ccount+"项?")
   }
  }else if (len=1){
   if (obj_form.piliang.checked==true){
//    if (confirm("删除后不能恢复!你确定要删除这1项?")) obj_form.submit();
    return confirm("删除后不能恢复!你确定要删除这1项?")
   }else{
    alert("请先选择要删除的项目");
    return false;
   }
  }else if (len<1){
   alert("出错,请重试或联系管理员!");
   return false;
  }
 }

 function chkall(obj_form){   //全选按钮的功能
  //alert(item.length);
  var frm = obj_form;        //得到要操作的form,详见注释1;
  var length = frm.elements.length;        //得到frm中的元素个数;
  var tt = frm.piliang;
  var length2 = tt.length;    //得到复选框的个数;
  var len=0;
  for(var i=0;i<length;i++){
   if (frm(i).type=='checkbox') len=len+1;
  }
  //alert(len);
  if (len>1){
   for (var i = 0; i <length2; i++){
    tt[i].checked = true;
    // alert(item[i].value);
   }
  }else if (len==1){
   tt.checked=true;
  }else if (len<1){
   alert("出错,请重试或联系管理员!");
  }
 }

 function unchkall(obj_form){   //取消全选的按钮
 //alert(item.length);
  var frm = obj_form;        //得到要操作的form,详见注释1;
  var length = frm.elements.length;        //得到frm中的元素个数;
  var tt = frm.piliang;
  var length2 = tt.length;    //得到复选框的个数;
  var len=0;
  for(var i=0;i<length;i++){
   if (frm(i).type=='checkbox') len=len+1;
  }
  //alert(len);
  if (len>1){
   for (var i = 0; i <length2; i++){
    tt[i].checked = false;
    // alert(item[i].value);
   }
  }else if (len==1){
   tt.checked=false;
  }else if (len<1){
   alert("出错,请重试或联系管理员!");
  }
 }

 

 

 

-----------------xxtable.css--------

/* CSS Document */
/* 标题样式 */
.xtablehead {
 background-color: #aacbee;
 text-align:center;
 font-weight:bolder;
 line-height:20px;
 font-size:12px;
}
/* 行1样式 */
.xtableline1 {
 background-color: #f2f7fe;
 line-height:20px;
 font-size:12px;
}
/* 行2样式 */
.xtableline2 {
 background-color: #FFFFFF;
 line-height:20px;
 font-size:12px;
}
/* Over行样式 */
.xtablelight {
 background-color: #d1e2fe;
 line-height:20px;
 font-size:12px;
}
/*删除工具栏样式*/
.xtabledel{
 background-color: #d1e2fe;
 line-height:20px;
 font-size:12px;
 text-align:center; 
}
td{
 padding-left:5px;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:52252次
    • 积分:802
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:4篇
    • 译文:1篇
    • 评论:17条
    文章分类
    最新评论