html引用derective:

<table datatable dtOptions="dtOptionsExample2" class="table table-striped m-b-none"></table>
controller设置:

[javascript] view plaincopy

print?

  1. <span style="font-weight: normal;">$scope.dtOptions = {
  2. "bProcessing": true,
  3. "bServerSide": true,
  4. iDisplayLength: 5,
  5. sAjaxSource: 'http://10.188.192.200:8080/employee/page?deptId='+ data,
  6. sAjaxDataProp: 'aaData',
  7. "sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
  8. sPaginationType: "full_numbers",
  9. "aoColumns":
  10. [
  11. { "mData": "employeeId" },
  12. { "mData": "employeeName",
  13. "sClass": "center",
  14. "mRender": function(data,type,full) {
  15. return '<a class="emplyeeInfoLink" href="javascript:;">阿司法所</a>';
  16. }
  17. },
  18. { "mData": "employeeEmail" },
  19. { "mData": "employeeMobilePhoneMaster" }
  20. ],
  21. /*"aoColumnDefs":[
  22. {
  23. "aTargets":[4],
  24. "mData": null
  25. }
  26. ],*/
  27. "fnServerData": function( sUrl, aoData, fnCallback, oSettings ) {
  28. oSettings.jqXHR = $.ajax({
  29. "url": sUrl,
  30. beforeSend: function(xhr) {
  31. xhr.withCredentials = true;
  32. },
  33. "data": aoData,
  34. "type": 'get',
  35. "success": fnCallback,
  36. "cache": false
  37. });
  38. }
  39. }</span>
angular.datatable.js:
[javascript] view plaincopy print?
  1. <span style="font-size:14px;">angular.module('datatablesDirectives', []).directive('datatable', function ($http) {
  2. return {
  3. // I restricted it to A only. I initially wanted to do something like
  4. // <datatable> <thead> ... </thead> </datatable>
  5. // But thead elements are only valid inside table, and <datatable> is not a table.
  6. // So.. no choice to use <table datatable>
  7. restrict: 'A',
  8. link: function ($scope, $elem, attrs) {
  9. var options = {};
  10. // Start with the defaults. Change this to your defaults.
  11. options = {}
  12. // If dtOptions is defined in the controller, extend our default option.
  13. if (typeof $scope.dtOptions !== 'undefined') {
  14. angular.extend(options, $scope.dtOptions);
  15. }
  16. // If dtoptions is not declared, check the other options
  17. if (attrs['dtoptions'] === undefined) {
  18. // Get the attributes, put it in an options
  19. // We need to do a switch/case because attributes does not retain case
  20. // and datatables options are case sensitive. Damn. It's okay! We need to detect
  21. // the callbacks anyway and call it as functions, so it works out!
  22. // I put what I needed, most of my settings are not dynamics except those 2.
  23. for (property in attrs) {
  24. switch (property) {
  25. // This is the ajax source
  26. case 'sajaxsource':
  27. options['sAjaxSource'] = attrs[property];
  28. break;
  29. // This is the ajax data prop. For example, your result might be
  30. // {code: 200, data: [ .. ]} -> in the case, sAjaxDataProp is data
  31. case 'sajaxdataprop':
  32. options['sAjaxDataProp'] = attrs[property];
  33. break;
  34. }
  35. }
  36. } else {
  37. // If dtoptions is declare, extend the current options with it.
  38. angular.extend(options, $scope.dtOptions);
  39. }
  40. // Just some basic validation.
  41. if (typeof options['sAjaxSource'] === 'undefined') {
  42. throw "Ajax Source not defined! Use sajaxsource='/api/v1/blabla'";
  43. }
  44. // for Angular http inceptors
  45. if (typeof options['fnServerData'] === 'undefined') {
  46. options['fnServerData'] = function (sSource, aoData, resultCb) {
  47. $http.get(sSource, aoData).then(function (result) {
  48. resultCb(result.data);
  49. });
  50. };
  51. }
  52. // Get the column options, put it in a aocolumn object.
  53. // Obviously, mdata is the only one required.
  54. // I personally just needed those 3, if you need other more feel free to add it.
  55. // mData also accepts a function; I'm sure there's a more elegant way but for now
  56. // it detects if it's a function, and if it is, do it.
  57. options.aoColumns = [];
  58. // Get the thead rows.
  59. $elem.find('thead th').each(function() {
  60. var colattr = angular.element(this).data();
  61. //console.log(colattr);
  62. //console.log('demodeo');
  63. // Detects if it's a function. Must exist in scope.
  64. if (colattr.mdata.indexOf("()") > 1) {
  65. // Simple one-liner that removes the ending ()
  66. var fn = $scope[colattr.mdata.substring(0, colattr.mdata.length - 2)];
  67. // Throw an error if it's not a function.
  68. if (typeof fn === 'function') {
  69. options.aoColumns.push({
  70. mData: fn,
  71. sClass: colattr.sclass,
  72. bVisible: colattr.bvisible,
  73. mRender: colattr.mrender
  74. });
  75. } else {
  76. throw "mData function does not exist in $scope.";
  77. }
  78. } else {
  79. //console.log('<1?');
  80. options.aoColumns.push({
  81. mData: colattr.mdata,
  82. sClass: colattr.sclass,
  83. bVisible: colattr.bvisible,
  84. mRender: colattr.mrender
  85. });
  86. }
  87. });
  88. // Load the datatable!
  89. $elem.dataTable(options);
  90. //console.log(options);
  91. }
  92. }
  93. });
  94. </span>

angularJs中datatable实现相关推荐

  1. angularJS中directive与controller之间的通信

    当我们在angularJS中自定义了directive之后需要和controller进行通讯的时候,是怎么样进行通讯呢? 这里介绍3种angular自定义directive与controller通信的 ...

  2. AngularJs中的directives(指令part1)

    一.指令的职责   指令的职责是修改DOM结构,并将作用域和DOM连接起来.即指令既要操作DOM,将作用域内的数据绑定到DOM节点上,又要为DOM绑定事件调用作用域内的对应的方法. 二.创建自定义指令 ...

  3. AngularJS中使用HTML5摄像头拍照

    1. 项目背景 公司开发一个网站,在做用户头像修改的时候领导提到增加一个由摄像头拍照实现修改头像的功能.因为我们网站是基于Html5进行开发,所以就直接采用H5来实现拍照.起初觉得这个功能很简单,但是 ...

  4. AngularJS中的指令全面解析(必看)

    出处: http://www.jb51.net/article/84665.htm 说到AngularJS,我们首先想到的大概也就是双向数据绑定和指令系统了,这两者也是AngularJS中最为吸引人的 ...

  5. 转: 理解AngularJS中的依赖注入

    理解AngularJS中的依赖注入 AngularJS中的依赖注入非常的有用,它同时也是我们能够轻松对组件进行测试的关键所在.在本文中我们将会解释AngularJS依赖注入系统是如何运行的. Prov ...

  6. 转;说说AngularJS中的$parse和$eval

    说说AngularJS中的$parse和$eval AngularJS的初学者常常会对$parse和$eval两个内建服务感到有些困惑,今天我们就来说说AngularJS中的$parse和$eval. ...

  7. Angularjs 中select回显后重复选项的解决

    Angularjs 中select回显后重复选项的解决 (1)Angularjs 中select回显代码,records和categoryValueList都是后台返回的 <!DOCTYPE h ...

  8. 在AngularJS中读取查询参数的最简洁方法是什么?

    本文翻译自:What's the most concise way to read query parameters in AngularJS? I'd like to read the values ...

  9. 如何在AngularJS中使用ng-repeat迭代键和值?

    本文翻译自:How to iterate over the keys and values with ng-repeat in AngularJS? In my controller, I have ...

最新文章

  1. keras module 'tensorflow' has no attribute 'placeholder'
  2. 技能UP:SAP CO掌上配置手册
  3. 快来看看Google出品的Protocol Buffer,别仅仅会用Json和XML了
  4. delphi 停电文本数据丢失_NLP中的文本分析和特征工程
  5. 计算机软件著作权奖励资金绩效目标,专项资金项目绩效目标表.pdf
  6. DotText研究资料整理
  7. Android Studio(12)----Git使用教程之本地仓库的基本操作
  8. [android] 切换界面的通用处理
  9. Introduction to Computer Networking学习笔记(二十二):TCP拥塞控制-基本方法 AIMD
  10. 【PyTorch】深度学习实战之PyTorch实现线性回归
  11. 四叉树与八叉树原理 / AABB OBB / 碰撞检测优化
  12. DP转HDMI/VGA方案设计电路图参考|AG6320参考电路原理图PCB电路图
  13. Windows电脑如何控制安卓手机
  14. 计算机连接网络被限制,电脑连接wifi出现网络受限的解决方法
  15. 阿里云推高校YY计划助推大学生创业潮
  16. 设计模式之适配器模式--简单实例分析
  17. 如何进行系统的架构设计?
  18. R7 5800H 3060 ubuntu20 配置全纪录(一)主要包括:N卡驱动、网卡驱动、virtualenv、CUDA and pytorch
  19. CSS3入门基础(详解)
  20. panada python_Python Pandas

热门文章

  1. Web Storage 与cookies
  2. Deploy sahara on openstack-icehouse
  3. 基于Boost无锁队列实现的内存池
  4. Windows PowerShell 2.0创建调用脚本文件
  5. cisco 基础配置命令中文解析 1
  6. 推特警告称开发者 API 密钥或遭泄露
  7. 微软WIP漏洞奖励计划新增基于攻击场景的奖励类别,最高$10万
  8. 推特称攻击者利用其 API 匹配用户名和电话号码
  9. JDBC与Mysql,Oracle数据类型之间的对应关系
  10. 支撑EB级规模的大数据平台深度揭秘