jquery datatables+MVC+WCF

view

@{
Layout = null;
}

<!DOCTYPE html>
<html>
<head>
<title>111</title>
<link href="~/Content/jquery.dataTables.css" rel="stylesheet" />

<script src="~/Scripts/jquery-1.11.1.js"></script>
<script src="~/Scripts/jquery.dataTables.js"></script>

<script type="text/javascript">
$(document).ready(function () {
$(‘#myDataTable‘).dataTable({
"bServerSide": true,
"bProcessing": true,
"sAjaxSource": "/User/GetAllUserDtoHandler",
"aoColumns": [{
"bVisible": true,
"mData": "UserName",
"aTargets": [0]
}, {
"bVisible": true,
"mData": "RealName",
"aTargets": [1]
}, {
"bVisible": true,
"mData": "RoleName",
"aTargets": [2]
}, {
"bVisible": true,
"mData": "DeptName",
"aTargets": [3]
}, {
"bVisible": true,
"mData": "CompanyName",
"aTargets": [4]
}, {
"bVisible": true,
"mData": "Address",
"aTargets": [5]
}, {
"bVisible": true,
"mData": "MobilePhone",
"aTargets": [6]
}],

"aoColumnDefs": [{
sDefaultContent: ‘‘,
aTargets: [‘_all‘]
}],

"oLanguage": {
"sProcessing": "正在加载中......",
"sLengthMenu": "每页显示 _MENU_ 条记录",
"sZeroRecords": "没有数据!",
"sEmptyTable": "表中无数据存在!",
"sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录",
"sInfoEmpty": "显示0到0条记录",
"sInfoFiltered": "数据表中共为 _MAX_ 条记录",
"oPaginate": {
"sFirst": "首页",
"sPrevious": "上一页",
"sNext": "下一页",
"sLast": "末页"
}
}
});
});
</script>
</head>
<body>
<table id="myDataTable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>
用户名
</th>
<th>
真实姓名
</th>
<th>
角色
</th>
<th>
所属部门
</th>
<th>
所属单位
</th>
<th>
地址
</th>
<th>
电话号码
</th>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>

 

controller

public JsonResult GetAllUserDtoHandler(DataTableParameter param)
{
using (ChannelFactory<IUserService> channelFactory = new ChannelFactory<IUserService>("userService"))
{
IUserService proxy = channelFactory.CreateChannel();
var userDtos = proxy.GetAllUserDto(param.iDisplayStart, param.iDisplayLength);

if (userDtos.Count > 0)
{
var list = new List<object>();
foreach (UserDto u in userDtos)
{
list.Add(new
{
u.UserName,
u.RealName,
u.RoleName,
u.DeptName,
u.CompanyName,
u.Address,
u.MobilePhone
});
}

return Json(new
{
sEcho = param.sEcho,
iTotalRecords = userDtos.Count,
iTotalDisplayRecords = userDtos.Count,
aaData = list
}, JsonRequestBehavior.AllowGet);
}
}

return null;
}

 

WCF后台略

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。