angularJs中datatable实现
<table datatable dtOptions="dtOptionsExample2" class="table table-striped m-b-none"></table>
controller设置:
[javascript] view plaincopy
print?
- <span style="font-weight: normal;">$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:;">阿司法所</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
- });
- }
- }</span>
- <span style="font-size:14px;">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);
- }
- }
- });
- </span>
angularJs中datatable实现相关推荐
- angularJS中directive与controller之间的通信
当我们在angularJS中自定义了directive之后需要和controller进行通讯的时候,是怎么样进行通讯呢? 这里介绍3种angular自定义directive与controller通信的 ...
- AngularJs中的directives(指令part1)
一.指令的职责 指令的职责是修改DOM结构,并将作用域和DOM连接起来.即指令既要操作DOM,将作用域内的数据绑定到DOM节点上,又要为DOM绑定事件调用作用域内的对应的方法. 二.创建自定义指令 ...
- AngularJS中使用HTML5摄像头拍照
1. 项目背景 公司开发一个网站,在做用户头像修改的时候领导提到增加一个由摄像头拍照实现修改头像的功能.因为我们网站是基于Html5进行开发,所以就直接采用H5来实现拍照.起初觉得这个功能很简单,但是 ...
- AngularJS中的指令全面解析(必看)
出处: http://www.jb51.net/article/84665.htm 说到AngularJS,我们首先想到的大概也就是双向数据绑定和指令系统了,这两者也是AngularJS中最为吸引人的 ...
- 转: 理解AngularJS中的依赖注入
理解AngularJS中的依赖注入 AngularJS中的依赖注入非常的有用,它同时也是我们能够轻松对组件进行测试的关键所在.在本文中我们将会解释AngularJS依赖注入系统是如何运行的. Prov ...
- 转;说说AngularJS中的$parse和$eval
说说AngularJS中的$parse和$eval AngularJS的初学者常常会对$parse和$eval两个内建服务感到有些困惑,今天我们就来说说AngularJS中的$parse和$eval. ...
- Angularjs 中select回显后重复选项的解决
Angularjs 中select回显后重复选项的解决 (1)Angularjs 中select回显代码,records和categoryValueList都是后台返回的 <!DOCTYPE h ...
- 在AngularJS中读取查询参数的最简洁方法是什么?
本文翻译自:What's the most concise way to read query parameters in AngularJS? I'd like to read the values ...
- 如何在AngularJS中使用ng-repeat迭代键和值?
本文翻译自:How to iterate over the keys and values with ng-repeat in AngularJS? In my controller, I have ...
最新文章
- keras module 'tensorflow' has no attribute 'placeholder'
- 技能UP:SAP CO掌上配置手册
- 快来看看Google出品的Protocol Buffer,别仅仅会用Json和XML了
- delphi 停电文本数据丢失_NLP中的文本分析和特征工程
- 计算机软件著作权奖励资金绩效目标,专项资金项目绩效目标表.pdf
- DotText研究资料整理
- Android Studio(12)----Git使用教程之本地仓库的基本操作
- [android] 切换界面的通用处理
- Introduction to Computer Networking学习笔记(二十二):TCP拥塞控制-基本方法 AIMD
- 【PyTorch】深度学习实战之PyTorch实现线性回归
- 四叉树与八叉树原理 / AABB OBB / 碰撞检测优化
- DP转HDMI/VGA方案设计电路图参考|AG6320参考电路原理图PCB电路图
- Windows电脑如何控制安卓手机
- 计算机连接网络被限制,电脑连接wifi出现网络受限的解决方法
- 阿里云推高校YY计划助推大学生创业潮
- 设计模式之适配器模式--简单实例分析
- 如何进行系统的架构设计?
- R7 5800H 3060 ubuntu20 配置全纪录(一)主要包括:N卡驱动、网卡驱动、virtualenv、CUDA and pytorch
- CSS3入门基础(详解)
- panada python_Python Pandas