<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 angularjs的更多相关文章

  1. NGUI UI Grid, two column

    NGUI UI Grid, two column, set Arrangement Horizontal, Column Limit 2.

  2. Kendo Web UI Grid添加一个html控件如(checkbox,button)

    在Kendo Web UI Grid增加一个控件如效果图: <div id="grid1"></div><script> $("#gr ...

  3. kendo ui grid选中行事件,获取combobox选择的值

    背景: 以前用 telerik ui做的grid现在又要换成kendo ui,不过说句实话kendo ui真的比telerik好多,可以说超级升级改头换面.当然用的mvc的辅助方法,以前的teleri ...

  4. Kendo UI Grid 使用总结

    Kendo UI Grid控件的功能强大,这里将常用的一些功能总结一下. Kendo UI Grid 固定列 在使用Gird控件显示数据时,如果数据列过多,会出现横向滚动条,很多情况下,我们希望某些列 ...

  5. Kendo UI Grid 批量编辑使用总结

    项目中使用Kendo UI Grid控件实现批量编辑,现在将用到的功能总结一下. 批量编辑基本设置 Kendo Grid的设置方法如下: $("#grid").kendoGrid( ...

  6. angularjs之UI Grid 的刷新 本地数据源及HTTP数据源

    关键代码: 如果数据源是本地数据$("#hidJsonData").val("[]");   var myJsonData = [];   if ($(&quo ...

  7. AngularJS +Kendo UI Grid template

    var dataSource = new kendo.data.DataSource({ transport: { dataType: "json", read: inputUri ...

  8. [Asp.net mvc] Asp.net mvc Kendo UI Grid的使用(四)

    有段时间没写博客了,工作状态比较忙,抽空继续总结下Grid的使用,这次主要介绍模板以及其他官网介绍不详尽的使用方法.先Show出数据,然后讲解下.后台代码: public ActionResult O ...

  9. Kendo Web UI Grid数据绑定,删除,编辑,并把默认英文改成中文

    Kendo Web UI 是个不错的Jquery框.可惜老外写的,很多都是默认的英文,当然我们也可以设置成中文,接下来,我们就看看Grid是如何实现的数据绑定(Kendo Grid数据绑定实现有很多方 ...

  10. Asp.net mvc Kendo UI Grid的使用(二)

    上一篇文章对Kendo UI做了一些简单的介绍以及基本环境,这篇文章来介绍一下Grid的使用 先上效果图: 要实现这个效果在Controller在要先导入Kendo.Mvc.UI,Kendo.Mvc. ...

随机推荐

  1. 【转载】ARM与单片机的区别

    前几天在博客园的博问模块上面发布了一个博问,可能是我问题描述有些问题,被一个园友指出,ARM与单片机是不同的.所以我特地查了一下ARM与单片机的区别,之前一直以为ARM就是加强版的单片机,stm32无 ...

  2. 初次使用visual studio

    之前一直听闻VS是世界上最强IDE,但是害怕他的体积庞大,一直不敢使用.我一直喜欢轻便简洁的东西,编译器也是一样,所以刚开始我使用的是C-FREE5,虽然界面略显粗糙,和低调奢华有内涵的VS比起来,真 ...

  3. AppScan扫描建议 问题集

    1.1        AppScan扫描建议 若干问题的补救方法在于对用户输入进行清理. 通过验证用户输入未包含危险字符,便可能防止恶意的用户导致应用程序执行计划外的任务,例如:启动任意 SQL 查询 ...

  4. jQuery生成一个DIV容器,ID是"rating".

    我们需要一些服务器端代码,这个例子中用到了一个PHP文件,读取rating参数然后返回rating总数和平均数.看一下rate.php代码.虽然这些例子也可以不使用AJAX来实现,但显示我们不会那么做 ...

  5. TOP100summit:【分享实录】爆炸式增长的斗鱼架构平台的演进

    本篇文章内容来自2016年TOP100summit斗鱼数据平台部总监吴瑞城的案例分享. 编辑:Cynthia 吴瑞诚:斗鱼数据平台部总监 曾先后就职于淘宝.一号店. 从0到1搭建公司大数据平台.平台规 ...

  6. JSP学习_01

    JSP cookie是存储在客户机的文本文件,保存了大量的轨迹信息.通常有三个步骤可以识别回头客:1)服务器脚本发送一系列cookie到浏览器,如姓名.年龄.ID等2)浏览器在本地存储这些信息以备不时 ...

  7. Xcode 9运行h d f报错

    SocialSDKXib/UMSCommentInputController.xib: error: Illegal Configuration: Compiling IB documents for ...

  8. ArcGIS URL 组成

    转自帮助文档:http://server.arcgis.com/zh-cn/server/latest/administer/windows/components-of-arcgis-urls.htm ...

  9. SQL语句常见视图操作部分试题(一)

    创建一个名称为EMPLOYEES_VU的视图,它基于EMPLOYEES表中的雇员号.雇员名和部门号.将雇员名的列标题改为EMPLOYEE. CREATE VIEW EMPLOYEES_VU AS SE ...

  10. RHEL6 Systemtap 安装笔记

    以 RHEL6u3 为例 1  Systemtap 安装 yum install systemtap 跟systemtap有关的有6,7个,全装上,别偷懒 就用yum安装,别傻傻的去下rpm包,吃力不 ...