本文介绍了angularJs中datatable实现,有需要的小伙伴可以参考下

html引用derective:
复制代码 代码如下:
<table datatable dtOptions="dtOptionsExample2" class="table table-striped m-b-none"></table>
controller设置:
$scope.dtOptions = {
"bProcessing": true,
"bServerSide": true,
iDisplayLength: 5,
sAjaxSource: 'http://10.188.192.200:8080/employee/page?deptId='+ data,
sAjaxDataProp: 'aaData',
"sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
sPaginationType: "full_numbers",
"aoColumns":
[
{ "mData": "employeeId" },
{ "mData": "employeeName",
"sClass": "center",
"mRender": function(data,type,full) {
return '<a class="emplyeeInfoLink" href="javascript:;" rel="external nofollow" >阿司法所</a>';
}
},
{ "mData": "employeeEmail" },
{ "mData": "employeeMobilePhoneMaster" }
],
/*"aoColumnDefs":[
{
"aTargets":[4],
"mData": null
}
],*/
"fnServerData": function( sUrl, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax({
"url": sUrl,
beforeSend: function(xhr) {
xhr.withCredentials = true;
},
"data": aoData,
"type": 'get',
"success": fnCallback,
"cache": false
});
}
}
angular.datatable.js:
angular.module('datatablesDirectives', []).directive('datatable', function ($http) {
return {
// I restricted it to A only. I initially wanted to do something like
// <datatable> <thead> ... </thead> </datatable>
// But thead elements are only valid inside table, and <datatable> is not a table.
// So.. no choice to use <table datatable>
restrict: 'A',
link: function ($scope, $elem, attrs) {
var options = {};
// Start with the defaults. Change this to your defaults.
options = {}
// If dtOptions is defined in the controller, extend our default option.
if (typeof $scope.dtOptions !== 'undefined') {
angular.extend(options, $scope.dtOptions);
}
// If dtoptions is not declared, check the other options
if (attrs['dtoptions'] === undefined) {
// Get the attributes, put it in an options
// We need to do a switch/case because attributes does not retain case
// and datatables options are case sensitive. Damn. It's okay! We need to detect
// the callbacks anyway and call it as functions, so it works out!
// I put what I needed, most of my settings are not dynamics except those 2.
for (property in attrs) {
switch (property) {
// This is the ajax source
case 'sajaxsource':
options['sAjaxSource'] = attrs[property];
break;
// This is the ajax data prop. For example, your result might be
// {code: 200, data: [ .. ]} -> in the case, sAjaxDataProp is data
case 'sajaxdataprop':
options['sAjaxDataProp'] = attrs[property];
break;
}
}
} else {
// If dtoptions is declare, extend the current options with it.
angular.extend(options, $scope.dtOptions);
}
// Just some basic validation.
if (typeof options['sAjaxSource'] === 'undefined') {
throw "Ajax Source not defined! Use sajaxsource='/api/v1/blabla'";
}
// for Angular http inceptors
if (typeof options['fnServerData'] === 'undefined') {
options['fnServerData'] = function (sSource, aoData, resultCb) {
$http.get(sSource, aoData).then(function (result) {
resultCb(result.data);
});
};
}
// Get the column options, put it in a aocolumn object.
// Obviously, mdata is the only one required.
// I personally just needed those 3, if you need other more feel free to add it.
// mData also accepts a function; I'm sure there's a more elegant way but for now
// it detects if it's a function, and if it is, do it.
options.aoColumns = [];
// Get the thead rows.
$elem.find('thead th').each(function() {
var colattr = angular.element(this).data();
//console.log(colattr);
//console.log('demodeo');
// Detects if it's a function. Must exist in scope.
if (colattr.mdata.indexOf("()") > 1) {
// Simple one-liner that removes the ending ()
var fn = $scope[colattr.mdata.substring(0, colattr.mdata.length - 2)];
// Throw an error if it's not a function.
if (typeof fn === 'function') {
options.aoColumns.push({
mData: fn,
sClass: colattr.sclass,
bVisible: colattr.bvisible,
mRender: colattr.mrender
});
} else {
throw "mData function does not exist in $scope.";
}
} else {
//console.log('<1?');
options.aoColumns.push({
mData: colattr.mdata,
sClass: colattr.sclass,
bVisible: colattr.bvisible,
mRender: colattr.mrender
});
}
});
// Load the datatable!
$elem.dataTable(options);
//console.log(options);
}
}
});
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# angularJs
# datatable
# angular
# angularjs表格ng-table使用备忘录
# AngularJS ng-table插件设置排序
# Angularjs+bootstrap+table多选(全选)支持单击行选中实现编辑、删除功能
# AngularJS中table表格基本操作示例
# angularjs实现table增加tr的方法
# 详解angularjs popup-table 弹出框表格指令
# 对比分析Django的Q查询及AngularJS的Datatables分页插件
# angularjs实现table表格td单元格单击变输入框/可编辑状态示例
# 大家多多
# 小伙伴
# 司法所
# aoColumnDefs
# aTargets
# employeeMobilePhoneMaster
# fnServerData
# employeeEmail
# aoData
# fnCallback
# sUrl
# null
# oSettings
# full
# return
# type
# mRender
# function
# emplyeeInfoLink
# external
相关文章:
如何在阿里云域名上完成建站全流程?
小建面朝正北,A点实际方位是否存在偏差?
如何规划企业建站流程的关键步骤?
小说建站VPS选用指南:性能对比、配置优化与建站方案解析
西安专业网站制作公司有哪些,陕西省建行官方网站?
微信小程序 五星评分(包括半颗星评分)实例代码
大连网站设计制作招聘信息,大连投诉网站有哪些?
如何注册花生壳免费域名并搭建个人网站?
佛山网站制作系统,佛山企业变更地址网上办理步骤?
代购小票制作网站有哪些,购物小票的简要说明?
简易网站制作视频教程,使用记事本编写一个简单的网页html文件?
潍坊网站制作公司有哪些,潍坊哪家招聘网站好?
网页设计与网站制作内容,怎样注册网站?
保定网站制作方案定制,保定招聘的渠道有哪些?找工作的人一般都去哪里看招聘信息?
建站之星展会模版如何一键下载生成?
如何快速生成专业多端适配建站电话?
如何挑选最适合建站的高性能VPS主机?
智能起名网站制作软件有哪些,制作logo的软件?
如何用美橙互联一键搭建多站合一网站?
香港网站服务器数量如何影响SEO优化效果?
平台云上自主建站:模板化设计与智能工具打造高效网站
如何用PHP快速搭建CMS系统?
建站主机选哪种环境更利于SEO优化?
如何用好域名打造高点击率的自主建站?
香港服务器网站卡顿?如何解决网络延迟与负载问题?
电视网站制作tvbox接口,云海电视怎样自定义添加电视源?
网站制作怎么样才能赚钱,用自己的电脑做服务器架设网站有什么利弊,能赚钱吗?
建站之星收费标准详解:套餐费用及年费价格表一览
北京制作网站的公司,北京铁路集团官方网站?
网站制作和推广的区别,想自己建立一个网站做推广,有什么快捷方法马上做好一个网站?
javascript基本数据类型及类型检测常用方法小结
如何做网站制作流程,*游戏网站怎么搭建?
制作旅游网站html,怎样注册旅游网站?
如何在Windows环境下新建FTP站点并设置权限?
如何用景安虚拟主机手机版绑定域名建站?
建站之星代理平台如何选择最佳方案?
如何在万网ECS上快速搭建专属网站?
如何用VPS主机快速搭建个人网站?
江苏网站制作公司有哪些,江苏书法考级官方网站?
如何在阿里云虚拟服务器快速搭建网站?
佛山企业网站制作公司有哪些,沟通100网上服务官网?
小捣蛋自助建站系统:数据分析与安全设置双核驱动网站优化
建站一年半SEO优化实战指南:核心词挖掘与长尾流量提升策略
建站之星后台密码遗忘或太弱?如何重置与强化?
如何撰写建站申请书?关键要点有哪些?
如何通过远程VPS快速搭建个人网站?
详解免费开源的DotNet二维码操作组件ThoughtWorks.QRCode(.NET组件介绍之四)
python的本地网站制作,如何创建本地站点?
如何制作网站标识牌,动态网站如何制作(教程)?
建站之星客服服务时间及联系方式如何?
*请认真填写需求信息,我们会在24小时内与您取得联系。