网站的后台,多数是需要使用datatable来展示数据的,因为datatable的功能比较强大,可以更好的使用。

引用css

<link href="../../static/assets/advanced-datatable/media/css/demo_page.css" rel="stylesheet" />
<link href="../../static/assets/advanced-datatable/media/css/demo_table.css" rel="stylesheet" />

html代码

<!--筛选条件-->
<div class="col-sm-12" style="margin-top: 10px;">
<input type="text" class="form-control" id="txtmobile" placeholder="手机号码" style="display: inline-block; width: 200px;"/>
<input type="text" class="form-control" id="txtrealname" placeholder="真实姓名" style="display: inline-block; width: 200px;"/>
<input type="text" class="form-control Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" onclick="WdatePicker()" placeholder="登录时间开始" id="txtlogintimestart" style="display: inline-block; width: 200px; height: 32px;"/>-
<input type="text" class="form-control Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" onclick="WdatePicker()" placeholder="登录时间结束" id="txtlogintimeend" style="display: inline-block; width: 200px; height: 32px;"/>
<button type="button" class="btn btn-primary " style="display: inline-block;" onclick="articlesearch()">搜索</button>
</div> <!--Table-->
<div class="col-sm-12">
<table class="table table-hover" id="hidden-table-info">
<thead>
<tr>
<th class="hidden-phone">编号</th>
<th class="hidden-phone">手机号码</th>
<th class="hidden-phone">真实姓名</th>
<th class="hidden-phone">支付宝</th>
<th class="hidden-phone">支付宝二维码</th>
<th class="hidden-phone">微信</th>
<th class="hidden-phone">微信二维码</th>
<th class="hidden-phone">开户银行</th>
<th class="hidden-phone">银行卡号</th>
<th class="hidden-phone">开户人</th>
<th class="hidden-phone">账户余额</th>
<th class="hidden-phone">添加时间</th>
<th class="hidden-phone">操作</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>

js代码

 <script type="text/javascript" src="../../static/assets/advanced-datatable/media/js/jquery.dataTables.js"></script>
<script type="text/javascript">
var oTable;
var mobile;
var logintimestart;
var logintimeend;
var realname;
//创建表格
$(document).ready(function () {
oTable = $('#hidden-table-info').dataTable({
"aaSorting": [],
"bProcessing": true,
"bServerSide": true,
"serverSide": true,
"aLengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
"sPaginationType": "full_numbers",
"bFilter": false,
"bSort": true,
"sAjaxSource": "../../handler/workerHandler.aspx",
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push({ name: "action", value: "GetWorkerData" });
aoData.push({ name: "mobile", value: $("#txtmobile").val() });
aoData.push({ name: "realname", value: $("#txtrealname").val() });
aoData.push({ name: "logintimestart", value: $("#txtlogintimestart").val() });
aoData.push({ name: "logintimeend", value: $("#txtlogintimeend").val() });
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
}, "aoColumnDefs": [{
"aTargets": [-1],
"mRender": function (data, type, full) {
return '<button class="btn btn-primary btn-xs" title="点击编辑标题" onclick="btn_workeredit(' data ',$(this))" style="margin-bottom:10px;">编辑</button><br/><button class="btn btn-primary btn-xs" title="点击删除" onclick="btn_worderdelete(' data ')">删除</button>';
},
}],
"aoColumns": [
{ "mData": "workerID" },
{ "mData": "mobile" },
{ "mData": "realName" },
{ "mData": "alipay" },
{
"mData": "alipayQRCode", "bSortable": false, "fnRender": function (obj) {
var data = obj.aData.alipayQRCode;
if (data != "" && data != null) {
return '<a href="' data '" target="_blank" title="点击查看原图"><img src="' data '" style="width:80px;height:80px;" /></a>';
} else {
return "";
}
}
},
{ "mData": "wechat" },
{
"mData": "wechatQRCode", "bSortable": false, "fnRender": function (obj) {
var data = obj.aData.wechatQRCode;
if (data!=""&&data!=null) {
return '<a href="' data '" target="_blank" title="点击查看原图"><img src="' data '" style="width:80px;height:80px;" /></a>';
} else {
return "";
}
}
},
{ "mData": "bank" },
{ "mData": "bankCardNumber" },
{ "mData": "bankCardName" },
{ "mData": "fund" },
{
"mData": "addTime", "fnRender": function (obj) {
var date = obj.aData.addTime;
return DataTable_TimeFormat(date);
}
},
{ "mData": "workerID", "bSortable": false },
],
}); $("#hidden-table-info_length").append("&nbsp;<button type='button' class='btn btn-danger' onclick='btn_reset()'>重置查询条件</button>&nbsp;<button type='button' class='btn btn-danger' onclick='btn_workeradd()'>添加工作人员</button>"); }); //时间格式化
function DataTable_TimeFormat(date) {
if (date != "" && date != null) {
var reg = /\./;//用来验证数字,包括小数的正则
if (reg.test(date)) {
date = date.split('.')[0];
}
return date.replace("T", " ");
} else {
return "";
}
} //搜索
function articlesearch(sort) {
mobile = $("#txtmobile").val();
realname = $("#txtrealname").val();
logintimestart = $("#txtlogintimestart").val();
logintimeend = $("#txtlogintimeend").val();
$("#hidden-table-info").dataTable().fnPageChange('first', true);
} //重置搜索
function btn_reset() {
$("#txtmobile").val("");
$("#txtrealname").val("");
$("#txtlogintimestart").val("");
$("#txtlogintimeend").val(""); mobile = null;
realname = null;
logintimestart = null;
logintimeend = null; $("#hidden-table-info").dataTable().fnPageChange('first', true);
}
</script>

服务端代码

private object data = "";
private object result = "";
private int sEcho, iDisplayStart, iDisplayLength, sortid, count;
private bool sorttype;
protected void Page_Load(object sender, EventArgs e)
{
string act = null;
try
{
act = Request["action"].ToString();
sEcho = Convert.ToInt32(Request["sEcho"]);
iDisplayStart = Convert.ToInt32(Request["iDisplayStart"]);//开始记录数
iDisplayLength = Convert.ToInt32(Request["iDisplayLength"]);//结束记录数
if (!int.TryParse(Request["iSortCol_0"], out sortid))//按哪列来排序
{
sortid = -1;
}
sorttype = Request["sSortDir_0"] == "asc" ? false : true;//升序还是降序 if (!string.IsNullOrEmpty(act))
{
switch (act)
{
case "GetWorkerData": GetWorkerData(); break;//获取工作人员信息
}
} result = data;
}
catch (Exception ex)
{
result = ReturnMsg(Enum_return.失败, ex.Message, null);
} Response.Write(result);
}
#region 获取工作人员
private void GetWorkerData()
{
//按条件搜索
string mobile = Request["mobile"];//手机号码
string realname = Request["realname"];//用户类型
string logintimestart = Request["logintimestart"];//登录时间开始
string logintimeend = Request["logintimeend"];//登录时间结束 //获取所有数据
List<yw_houseAgent_worker> list = null;
IQueryable<yw_houseAgent_worker> result = Ctx.yw_houseAgent_worker; #region 排序区分
switch (sortid)
{
case 0:
if (sorttype) result = result.OrderByDescending(c => c.workerID);
else result = result.OrderBy(c => c.workerID);
break;
case 1:
if (sorttype) result = result.OrderByDescending(c => c.mobile);
else result = result.OrderBy(c => c.mobile);
break;
case 2:
if (sorttype) result = result.OrderByDescending(c => c.realName);
else result = result.OrderBy(c => c.realName);
break;
case 3:
if (sorttype) result = result.OrderByDescending(c => c.alipay);
else result = result.OrderBy(c => c.alipay);
break;
case 5:
if (sorttype) result = result.OrderByDescending(c => c.wechat);
else result = result.OrderBy(c => c.wechat);
break;
case 7:
if (sorttype) result = result.OrderByDescending(c => c.bank);
else result = result.OrderBy(c => c.bank);
break;
case 8:
if (sorttype) result = result.OrderByDescending(c => c.bankCardNumber);
else result = result.OrderBy(c => c.bankCardNumber);
break;
case 9:
if (sorttype) result = result.OrderByDescending(c => c.bankCardName);
else result = result.OrderBy(c => c.bankCardName);
break;
case 10:
if (sorttype) result = result.OrderByDescending(c => c.fund);
else result = result.OrderBy(c => c.fund);
break;
case 11:
if (sorttype) result = result.OrderByDescending(c => c.addTime);
else result = result.OrderBy(c => c.addTime);
break;
default:
if (sorttype) result = result.OrderByDescending(c => c.workerID);
else result = result.OrderBy(c => c.workerID);
break;
}
#endregion if (!string.IsNullOrEmpty(mobile) || !string.IsNullOrEmpty(realname) || !string.IsNullOrEmpty(logintimestart) || !string.IsNullOrEmpty(logintimeend)) //搜索情况
{
#region 搜索情况
if (mobile.Trim().Length > 0)//手机号码
{
result = result.Where(c => c.mobile.Contains(mobile));
}
if (realname.Trim().Length > 0)//姓名
{
result = result.Where(c => c.realName.Contains(realname));
}
if (logintimestart.Trim().Length > 0 && logintimeend.Trim().Length > 0)//搜索查询时间
{
DateTime bstart = Convert.ToDateTime(logintimestart);
DateTime bend = Convert.ToDateTime(logintimeend);
result = result.Where(c => c.addTime >= bstart && c.addTime <= bend);
}
#endregion
} count = result.Where(c => c.serialID == CurrentSerialID && c.isDelete == false).Count();
list = result.Where(c => c.serialID == CurrentSerialID && c.isDelete == false).Skip(iDisplayStart).Take(iDisplayLength).ToList(); string str = SerializeTableData(sEcho, count, list);
Response.Write(str);
Response.End();
}
#endregion

datatable实例教程的更多相关文章

  1. 图解CSS3制作圆环形进度条的实例教程

    圆环形进度条制作的基本思想还是画出基本的弧线图形,然后CSS3中我们可以控制其旋转来串联基本图形,制造出部分消失的效果,下面就来带大家学习图解CSS3制作圆环形进度条的实例教程 首先,当有人说你能不能 ...

  2. Python导出Excel为Lua/Json/Xml实例教程(三):终极需求

    相关链接: Python导出Excel为Lua/Json/Xml实例教程(一):初识Python Python导出Excel为Lua/Json/Xml实例教程(二):xlrd初体验 Python导出E ...

  3. Python导出Excel为Lua/Json/Xml实例教程(二):xlrd初体验

    Python导出Excel为Lua/Json/Xml实例教程(二):xlrd初体验 相关链接: Python导出Excel为Lua/Json/Xml实例教程(一):初识Python Python导出E ...

  4. Python导出Excel为Lua/Json/Xml实例教程(一):初识Python

    Python导出Excel为Lua/Json/Xml实例教程(一):初识Python 相关链接: Python导出Excel为Lua/Json/Xml实例教程(一):初识Python Python导出 ...

  5. 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器

    本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...

  6. Solr 4.0 部署实例教程

    Solr 4.0 部署实例教程 Solr 4.0的入门基础教程,先说一点部署之后肯定会有人用solrj,solr 4.0好像添加了不少东西,其中CommonsHttpSolrServer这个类改名为H ...

  7. React 入门实例教程(转载)

    本人转载自: React 入门实例教程

  8. 分享本年度最佳的15个 Photoshop 实例教程

    毫无疑问,Photoshop 是任何其类型的设计相关工作的最佳工具.有这么多东西,你可以用它来设计,发挥你的想象力,一切皆有可能. 现在,几乎所有的封面图像都会用 Photoshop 来修饰. 您可能 ...

  9. 值得 Web 开发人员学习的20个 jQuery 实例教程

    这篇文章挑选了20个优秀的 jQuery 实例教程,这些 jQuery 教程将帮助你把你的网站提升到一个更高的水平.其中,既有网站中常用功能的的解决方案,也有极具吸引力的亮点功能的实现方法,相信通过对 ...

随机推荐

  1. Sublime Text 3激活

    Sublime Text 3激活方式: 一.修改hosts文件: 1:windows系统:      找到 C:\Windows\System32\drivers\etc\hosts 这个文件,  用 ...

  2. CentOS7 JDK1.8部署详解

    一.下载 首先需要将本地下载好的jdk包拷贝到Linux中:scp jdk-8u91-linux-x64.tar.gz hadoop@192.168.***.***:~/software/ //星号处 ...

  3. 第三方jar上传到Maven私服(Nexus)

    mvn deploy:deploy-file -DgroupId=taobao-sdk -DartifactId=taobao-sdk-java -Dversion=1.0 -Dpackaging=j ...

  4. .NET MVC 控制器和行为

    行为就是可访问方法(public) 行为返回类型必须是 ActionResult 或者其派生类,基本上返回类型为以下四种之一 View(视图路径) Json(对象或者对象集合) Content(字符串 ...

  5. ES6语法的数组查询

    setProductId(param){ console.log(param); let prod = this.products.find(item =>{ return item.prodC ...

  6. SSO 单点登录

    一.单系统登录机制 1.http无状态协议 web应用采用browser/server架构,http作为通信协议.http是无状态协议,浏览器的每一次请求,服务器会独立处理,不与之前或之后的请求产生关 ...

  7. 2017-11-04 Sa Oct 消参

    2017-11-04 Sa $ P(-3, 0) $ 在圆C $ (x-3)^2 + y^2 = 8^2 $ 内,动圆M与圆相切且过P点,求M点轨迹. 设切点 $ A(a, b) $,圆心 \(M(x ...

  8. Python单元测试unittest【转自https://www.cnblogs.com/feng0815/p/8045850.html】

    [转自https://www.cnblogs.com/feng0815/p/8045850.html] Python中有一个自带的单元测试框架是unittest模块,用它来做单元测试,它里面封装好了一 ...

  9. vue 关键词模糊查询

    页面html,绑定的列表数据为datas,关键词为 select_words,如下图 其中d.accounts和d.roleName是需要进行搜索的字段,也可以进行大小写都可以

  10. OpenStack 安装:nova服务

    上一篇介绍了glance,并且成功创建了一个镜像,这一篇介绍Nova. 首先创建Nova用户,需要记得先source环境变量,然后创建Nova用户,并设置密码为nova [root@linux-nod ...