HTML

<pre name="code" class="html"><!--ui-grid css-->
<link rel="stylesheet" type="text/css" href="../lib/angular-ui/ui-grid/ui-grid.min.css">
<div class="gridStyle" ui-grid="gridOptions" ui-grid-selection ui-grid-resize-columns ui-grid-auto-resize ui-grid-exporter ui-grid-edit ui-gird-pagination ui-grid-cellnav>
</div>
<!--ui-grid js-->
<script src="../lib/angular-ui/ui-grid/ui-grid.min.js"></script>
<!--ui-grid excel export-->
<script src="../lib/angular-ui/ui-grid/csv.js"></script>
<!--ui-grid pdf export-->
<script src="../lib/angular-ui/ui-grid/pdfmake.min.js"></script>
<script src="../lib/angular-ui/ui-grid/vfs_fonts.js"></script>
<!--ui-grid-selection 选择行指令-->
<!--ui-grid-resize-columns 表格宽可拉伸指令-->
<!--ui-grid-auto-resize 自动使用div的高度和宽度指令-->
<!--ui-grid-exporter 导出指令-->
<!--ui-grid-edit 编辑指令-->
<!--ui-gird-pagination 分页指令-->
<!--ui-gird-pagination 分页指令-->
<!--ui-grid-cellnav 单元格指令-->
<!--gridStyle 自定义设置样式-->

JS

angular.module('app', ['ui.grid','ui.grid.selection','ui.grid.resizeColumns','ui.grid.autoResize','ui.grid.edit','ui.grid.exporter','ui.grid.pagination','ui.grid.cellNav'])

.controller('RootCtrl', function($scope,i18nService) {//前四个基本上是必用到的 后面的可以根据自身情况去加
// 国际化; i18nService.setCurrentLang('zh-cn'); $scope.gridOptions = {
data : 'myData', //基础属性 enableSorting : true,//是否支持排序(列) useExternalSorting : false,//是否支持自定义的排序规则 enableRowHeaderSelection : false, enableGridMenu : false,//是否显示表格 菜单 showGridFooter: true,//时候显示表格的footer enableHorizontalScrollbar : 1,//表格的水平滚动条 enableVerticalScrollbar : 1,//表格的垂直滚动条 (两个都是 1-显示,0-不显示) selectionRowHeaderWidth : 30, enableCellEditOnFocus:false,//default为false,true的时候单击即可打开编辑(cellEdit为true的时候,需要引入'ui.grid.cellNav') //分页属性 enablePagination: true, //是否分页,default为true enablePaginationControls: true, //使用默认的底部分页 paginationPageSizes: [10, 15, 20], //每页显示个数选项 paginationCurrentPage:1, //当前的页码 paginationPageSize: 10, //每页显示个数 paginationTemplate:"<div></div>", //自定义底部分页代码 totalItems : 0, // 总数量 useExternalPagination: true,//是否使用分页按钮 //选中 rowTemplate: "<div ng-dblclick=\"grid.appScope.onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" ui-grid-cell></div>",//双击行事件 enableFooterTotalSelected: true, // 是否显示选中的总数,default为true,如果显示,showGridFooter 必须为true enableFullRowSelection : true, //是否点击行任意位置后选中,default为false,当为true时,checkbox可以显示但是不可选中 enableRowHeaderSelection : true, //是否显示选中checkbox框 ,default为true enableRowSelection : true, // 行选择是否可用,default为true; enableSelectAll : true, // 选择所有checkbox是否可用,default为true; enableSelectionBatchEvent : true, //default为true modifierKeysToMultiSelect: false ,//default为false,为true时只能按ctrl或shift键进行多选,这个时候multiSelect必须为true; multiSelect: true ,// 是否可以选择多个,默认为true; noUnselect: false,//default为false,选中后是否可以取消选中 selectionRowHeaderWidth:30 ,//default为30,设置选择列的宽度 //api onRegisterApi : function (gridApi) {
$scope.gridApi = gridApi; $scope.gridApi.edit.on.afterCellEdit($scope,function(rowEntity){
//编辑离开事件
}); $scope.gridApi.selection.on.rowSelectionChanged($scope,function(row,event){
//行选中事件
});
}, //导出(只支持csv,扩展性不太好) exporterAllDataFn: function(){//导出全部
return getAllData();
}, exporterCsvColumnSeparator: ',', exporterCsvFilename:'testdown.csv', exporterFieldCallback : function ( grid, row, col, value ){//导出回调可以过滤条件
return value;
}, exporterHeaderFilterUseName : true, exporterMenuCsv : true, exporterMenuLabel : "Export", exporterMenuPdf : true, exporterOlderExcelCompatibility : false,//是否兼容低版本excel exporterPdfCustomFormatter : function ( docDefinition ) {
docDefinition.styles.footerStyle = { bold: true, fontSize: 10 }; return docDefinition;
}, exporterPdfFooter :{
text: '', style: ''
}, exporterPdfDefaultStyle : {
fontSize: 11,font:'simblack' //font 设置自定义字体
}, exporterPdfFilename:'testdown.pdf', exporterPdfFooter: function(currentPage, pageCount) {
return currentPage.toString() + ' of ' + pageCount;
}, exporterPdfHeader : function(currentPage, pageCount) {
return currentPage.toString() + ' of ' + pageCount;
}, exporterPdfMaxGridWidth : 720, exporterPdfOrientation : 'landscape',// 'landscape' 或 'portrait' pdf横向或纵向 exporterPdfPageSize : 'A4',// 'A4' or 'LETTER' exporterPdfTableHeaderStyle : {
bold: true, fontSize: 12, color: 'black'
}, exporterPdfTableLayout : null, exporterPdfTableStyle: {
margin: [0, 5, 0, 15]
}, exporterSuppressColumns : ['name'],//过滤不需要的列 exporterSuppressMenu: false, //列属性设置 columnDefs: [{ field: 'name', displayName: '名字', width: '100', //宽度设置 enableColumnMenu: false,// 是否显示列头部菜单按钮 //enableHiding: false, //suppressRemoveSort: true, enableCellEdit: false, // 是否可编辑 cellEditableCondition:function($scope){
return boolean;//是否编辑控制
}, visible:true,是否显示default为true, cellTemplate : '<a href="" ng-click="grid.appScope.viewPages(row.entity);">{{row.entity.name==1?"重写":""}}</a>',//重写cell cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
//做一些判断。。。 return 'red'//自定义样式
}, //cell下拉 editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownOptionsArray: [],//[{name:1,nameText:'Yoko'}] editDropdownIdLabel: 'name',//id editDropdownValueLabel: 'nameText',//显示的名字 cellFilter:"nameFilet"//过滤器
} ],
}; var myData=[{name:''}];
});

自定义指令

.directive('dblClickRow', ['$compile', '$parse', function ($compile, $parse) {
return {
priority: -190, // run after default uiGridCell directive restrict: 'A', scope: false, compile: function ($element, attr) {
// Get the function at ng-dblclick for ui-grid var fn = $parse(attr['ngDblclick'], /* interceptorFn */ null, /* expensiveChecks */ true); return function ngEventHandler(scope, element) {
element.on('dblclick', function (event) {
var callback = function () {
if ($scope.gridApi.grid.selection.lastSelectedRow) {
fn($scope, { $event: event, row: $scope.gridApi.grid.selection.lastSelectedRow.entity });
}
}; $scope.$apply(callback);
} )
};
}
};
}])

ui-grid使用详解的更多相关文章

  1. LigerUI之Grid使用详解(三)——字典数据展示

    一.问题概述 在开发web信息管理系统时,使用Web前端框架可以帮助我们快速搭建一组风格统一的界面效果,而且能够解决大多数浏览器兼容问题,提升开发效率.在关于LigerGrid的前两篇的内容里,给大家 ...

  2. css之Grid Layout详解

    css之Grid Layout详解 CSS Grid Layout擅长将页面划分为主要区域,或者在从HTML基元构建的控件的各个部分之间定义大小,位置和图层之间的关系. 与表格一样,网格布局使作者能够 ...

  3. iOS开发——UI篇&ScrollView详解

    创建方式 1:StoryBoard/Xib 这里StoarBoard就不多说,直接拖就可以,说太多没意思,如果连这个都不会我只能先给你跪了! 2:代码: CGRect bounds = [ [ UIS ...

  4. 【iOS 开发】基本 UI 控件详解 (UIButton | UITextField | UITextView | UISwitch)

    博客地址 : http://blog.csdn.net/shulianghan/article/details/50051499 ; 一. UI 控件简介 1. UI 控件分类 UI 控件分类 : 活 ...

  5. LigerUI之Grid使用详解(一)——显示数据 --分页

    http://www.cnblogs.com/jerehedu/p/4218560.html 首先给大家介绍最常用的数据展示组件Grid,使用步骤如下: 1.页面中正确引入样式文件及相应组件 < ...

  6. LigerUI之Grid使用详解(一)——显示数据

    目录: 一.概述 二.Grid使用步骤 三.使用Grid展示数据 四.源码下载 一.概述 在开发web信息管理系统时,使用Web前端框架可以帮助我们快速搭建一组风格统一的界面效果,而且能够解决大多数浏 ...

  7. 管理系统UI: System Bar 详解

    Google原文: http://developer.android.com/training/system-ui/index.html 管理系统UI之一:淡化System Bar(Dimming t ...

  8. android自定义UI模板图文详解

    不知道大家在实际开发中有没有自定义过UI模板?今天花时间研究了一下android中自定义UI模板,与大家分享一下. 每个设计良好的App都是自定义标题栏,在自定义标题栏的过程中大部分人可能都是自定义一 ...

  9. Android UI性能优化详解

    设计师,开发人员,需求研究和测试都会影响到一个app最后的UI展示,所有人都很乐于去建议app应该怎么去展示UI.UI也是app和用户打交道的部分,直接对用户形成品牌意识,需要仔细的设计.无论你的ap ...

  10. 【IOS 开发】基本 UI 控件详解 (UIDatePicker | UIPickerView | UIStepper | UIWebView | UIToolBar )

    转载注明出处 : http://blog.csdn.net/shulianghan/article/details/50348982 一. 日期选择器 (UIDatePicker) UIDatePic ...

随机推荐

  1. libevent源码深度剖析八

    libevent源码深度剖析八 ——集成信号处理 张亮 现在我们已经了解了libevent的基本框架:事件管理框架和事件主循环.上节提到了libevent中I/O事件和Signal以及Timer事件的 ...

  2. WDCP从php5.2升级到5.3的办法,以及升级过程中iconv错误的处理

    从wdcp官方论坛我们可以找到一个询问升级的帖子,然后管理员在回复中也提供了升级方法: cd /tmp wget -c http://dl.wdlinux.cn:5180/soft/php-5.3.1 ...

  3. the install of mysql in Linux System

    一.下载MySql 浏览器打开 https://www.mysql.com/downloads/mysql/#downloads 下载 我下载的版本是Red Hat 5 版本的 https://www ...

  4. keepalived配置

    keepalived配置 之前已经安装完成,接下来我们配置keepalived. 假设我的ip地址如下: server1:192.168.0.150 server2:192.168.0.157 vip ...

  5. 34.UCASE() LCASE() 函数

    UCASE() 函数 UCASE 函数把字段的值转换为大写. SQL UCASE() 语法 SELECT UCASE(column_name) FROM table_name SQL UCASE() ...

  6. Vue.js组件调用用及其组件通信

    1.需要import,然后components注册.然后如下代码调用. <template> <header></header> //注册后才能这样使用 <b ...

  7. Mac OS 10.8 中的 OpenGL 开发环境设置(转)

    转自:http://www.th7.cn/Program/cp/201305/137743.shtml 一.XCode 4.5 在项目的"Build Phases">&quo ...

  8. Eclipse平台下配置Go语言开发环境(Win7)

    <Go语言编程>中写到:“从功能和易用性等方面考虑, Eclipse+GoEclipse.LiteIDE这两个环境在所有IDE里面是表现最好的”,所以笔者打算采用Eclipse+GoEcl ...

  9. 独立部署GeoWebCache

    在进行GIS项目开发中,常使用Geoserver作为开源的地图服务器,Geoserver是一个JavaEE项目,常通过Tomcat进行部署.而GeoWebCache是一个采用Java实现用于缓存WMS ...

  10. 「BZOJ 1001」狼抓兔子

    题目链接 luogu bzoj \(Solution\) 这个貌似没有什么好讲的吧,直接按照这个给的图建图就好了啊,没有什么脑子,但是几点要注意的: 建双向边啊. 要这么写,中间还要写一个\(whil ...