https://github.com/angular-ui/ui-grid/wiki/Templating

    $scope.gridOptions = {
        data: self.myData,
        enableCellEditOnFocus: true, //enables the editor on a single click, if you use enableCellEdit: true you would have to doubleclick
        columnDefs: [{ field: ‘firstName‘, displayName: ‘First Name‘, width: 90 },
                     { field: ‘lastName‘, displayName: ‘Last Name‘, width: 80 },
                     { field: ‘age‘, cellClass: ‘ageCell‘, headerClass: ‘ageHeader‘,
                       editableCellTemplate: ‘<div><form name="inputForm"><input type="number" ng-class="\‘colt\‘ + col.uid" ui-grid-editor ng-model="MODEL_COL_FIELD"></form></div>‘ } ]
 };

angular-ui/ui-grid

Code Issues 1,324 Pull requests 8 Projects 0 Wiki Pulse Graphs

Templating

Omaigad edited this page on 3 Aug 2016 · 40 revisions

Pages 10

Clone this wiki locally

Check latest default templates at ui-grid/templates

Row Templates



Default Row Template:

// passed in as a string
    <div ng-style="{ ‘cursor‘: row.cursor }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell {{col.cellClass}}"><div class="ngVerticalBar" ng-style="{height: rowHeight}" ng-class="{ ngVerticalBarVisible: !$last }">&nbsp;</div><div ng-cell></div></div>

Example:

    $scope.gridOptions = {
        data: self.myData,
        rowTemplate: ‘<div ng-style="{\‘cursor\‘: row.cursor, \‘z-index\‘: col.zIndex() }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell {{col.cellClass}}" ng-cell></div>‘
 };

That way you can add some styling!

Default header template:

<div ng-style="{ height: col.headerRowHeight }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngHeaderCell" ng-header-cell></div>


Double Click on Row Template:

Example:

    $scope.gridOptions = {
        data: self.myData,
        rowTemplate: ‘<div ng-dblclick="onDblClickRow(row)" ng-style="{ \’cursor\’: row.cursor }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell {{col.cellClass}}"><div class="ngVerticalBar" ng-style="{height: rowHeight}" ng-class="{ ngVerticalBarVisible: !$last }">&nbsp;</div><div ng-cell></div></div>‘
 };

    $scope.onDblClickRow = function(rowItem) {
        // do something here with rowItem.rowIndex
    };

Cell Templates



Default Cell Template:

<div class="ui-grid-cell-contents" >{{grid.getCellValue(row, col)}}</div>

Example:

    $scope.gridOptions = {
        data: self.myData,
        columnDefs: [{ field: ‘firstName‘, displayName: ‘First Name‘, width: 90, cellTemplate: ‘<div class="ui-grid-cell-contents" >{{grid.getCellValue(row, col)}}</div>‘ },
                     { field: ‘lastName‘, displayName: ‘Last Name‘, width: 80 },
                     { field: ‘age‘, cellClass: ‘ageCell‘, headerClass: ‘ageHeader‘ } ]
 };

Editable Cell Templates



It is possible to make the cells editable, and you can even define your own template for the editor.

Default Editable Cell Template:

<div><form name="inputForm"><input type="INPUT_TYPE" ng-class="‘colt‘ + col.uid" ui-grid-editor ng-model="MODEL_COL_FIELD"></form></div>

Example (‘number‘ style input for the age column):

    $scope.gridOptions = {
        data: self.myData,
        enableCellEditOnFocus: true, //enables the editor on a single click, if you use enableCellEdit: true you would have to doubleclick
        columnDefs: [{ field: ‘firstName‘, displayName: ‘First Name‘, width: 90 },
                     { field: ‘lastName‘, displayName: ‘Last Name‘, width: 80 },
                     { field: ‘age‘, cellClass: ‘ageCell‘, headerClass: ‘ageHeader‘,
                       editableCellTemplate: ‘<div><form name="inputForm"><input type="number" ng-class="\‘colt\‘ + col.uid" ui-grid-editor ng-model="MODEL_COL_FIELD"></form></div>‘ } ]
 };

When editing a cell, the ng-cell-has-focus directive will broadcast a message named ngGridEventStartCellEdit to let all children know that you can now give yourself focus. When the editable cell template is done with editing (usually on a blur event) you need to emit ngGridEventEndCellEdit to let ng-cell-has-focus know that you are done editing and it will then show the non-editable cell template. The reasoning for this is (good quote): "Now I can wrap my input elements in divs/spans, whatever and control exactly what element‘s blur triggers the end edit" - @swalters.

If you search for the ‘ngInput‘ directive in ng-grid‘s source code, you will find that that is exactly what this directive implements for input elements. So if you need to create your own ‘cell editor‘, you could create your own directive that would listen to and emit the right events, to make your component work as expected.

An example (used for ng-input directive):

scope.$on( ‘uiGridEventBeginCellEdit‘, function () { elm.focus(); } ); //focus the input element on ‘start cell edit‘
angular.element( elm ).bind( ‘blur‘, function () { scope.$emit( ‘uiGridEventEndCellEdit‘ ); } ); //when leaving the input element, emit the ‘end cell edit‘ event

Remember also to name the form as ‘inputForm‘ in order to enable CANCEL EDIT and END EDIT differentiation based on form validation.

Header Cell Templates



Default Header Cell Template:

<div class="ngHeaderSortColumn {{col.headerClass}}" ng-style="{‘cursor‘: col.cursor}" ng-class="{ ‘ngSorted‘: !noSortVisible }">
    <div ng-click="col.sort($event)" ng-class="‘colt‘ + col.index" class="ngHeaderText">{{col.displayName}}</div>
    <div class="ngSortButtonDown" ng-show="col.showSortButtonDown()"></div>
    <div class="ngSortButtonUp" ng-show="col.showSortButtonUp()"></div>
    <div class="ngSortPriority">{{col.sortPriority}}</div>
    <div ng-class="{ ngPinnedIcon: col.pinned, ngUnPinnedIcon: !col.pinned }" ng-click="togglePin(col)" ng-show="col.pinnable"></div>
</div>
<div ng-show="col.resizable" class="ngHeaderGrip" ng-click="col.gripClick($event)" ng-mousedown="col.gripOnMouseDown($event)"></div>

Example:

var myHeaderCellTemplate = ‘<div class="ngHeaderSortColumn {{col.headerClass}}" ng-style="{cursor: col.cursor}" ng-class="{ ngSorted: !noSortVisible }">‘+
                               ‘<div ng-click="col.sort($event)" ng-class="\‘colt\‘ + col.index" class="ngHeaderText">{{col.displayName}}</div>‘+
                               ‘<div class="ngSortButtonDown" ng-show="col.showSortButtonDown()"></div>‘+
                               ‘<div class="ngSortButtonUp" ng-show="col.showSortButtonUp()"></div>‘+
                               ‘<div class="ngSortPriority">{{col.sortPriority}}</div>‘+
                             ‘</div>‘+
                             ‘<div ng-show="col.resizable" class="ngHeaderGrip" ng-click="col.gripClick($event)" ng-mousedown="col.gripOnMouseDown($event)"></div>‘;
$scope.gridOptions = {
        data: self.myData,
        columnDefs: [{ field: ‘firstName‘, displayName: ‘First Name‘, width: 90, headerCellTemplate: myHeaderCellTemplate },
                     { field: ‘lastName‘, displayName: ‘Last Name‘, width: 80 },
                     { field: ‘age‘, cellClass: ‘ageCell‘, headerClass: ‘ageHeader‘ ]
 };
时间: 2024-10-14 08:51:39

https://github.com/angular-ui/ui-grid/wiki/Templating的相关文章

go语言的一个gui 开源 项目 https://github.com/andlabs/ui

go语言的一个gui 开源 项目  https://github.com/andlabs/ui 1 安装  mingw-w64  链接地址: http://mingw-w64.sourceforge.net/download.php 2 liteide 配置: # native compiler windows 386 GOROOT=c:\go GOBIN=%GOROOT%\bin GOARCH=386 GOOS=windows CGO_ENABLED=1 PATH=C:\Program Fil

阿里云 Angular 2 UI框架 NG-ZORRO介绍

说明: Angular2出来后,一直想找个基于Angular2的前端后台管理框架,但一直没有找到比较适合的.前段时间在Angular官网资源无意之间看到NG-ZORRO,NG-ZORRO由阿里计算平台事业部.阿里云等不同部门的一些小伙伴在原业务组件的基础上共同构建而成,而且已开源,现在是0.6.0的版本,组件功能已经很齐全了,更符合我们国人使用习惯,已兼容Angular 5.0版本.是目前为止我见过的最全面.最好.最符合国人使用习惯的管理后台angular 2 UI模板. 文档查看官方网站:ht

Angular第三方UI组件库

一.Angular第三方UI组件库(github搜“awesome angular ")-----lonic 概述:是一个第三方的适用于移动端App的UI组件库,可以与Angular/React/Vue.js组合,也可以独立使用. 九种主题色:primary.secondary.tertiary.danger.warning.success.dark.medium.light 2.页面结构:<ion-app> <ion-header> <ion-toolbar>

kendo ui中grid页面参数问题(1)

kendo ui 中grid 算是最长用的控件之一,当使用分页效果时,我们要传递分页参数与自己定义的参数如: 1 var dataSource = new kendo.data.DataSource({ 2 transport: { 3 read : { 4 url : "对应后台路径", 5 contentType : "application/json", 6 type : "POST", 7 dataType : "json&qu

angular router ui bug !

https://github.com/angular-ui/ui-router/issues/600 https://github.com/angular-ui/ui-router/issues/2229 看完以上的问题,可想是没有结果的! 具体问题: $urlRouterProvider.when("/", "/companys");  被执行时如果有prevent.default 是不可以以加载templateURl的! 避开方法是用template .

https://github.com/wytings

博客中写了很多比较杂乱的东西,有时候可能一时看不出效果,毕竟代码问题确实是 “Talk is cheap. Show me the code” 所以,就开了一个github,把一些日常比较好用的东西,都写成实例放在上面,这样也许比单纯的文字会对大家更有用一些. 地址:https://github.com/wytings/SuperAndroid

https://github.com/miaozhongfeng/my-repository.git浅谈数组求和java实验

          这次作业呢,我是用java来写的,虽然java只是自己假期里看的一点点,但是人总是要接触新事物的,应该不断向前.          说明:这次作业有一个遗憾,就是我花了一个下午真真没搞懂POI包的使用,是我的智商问题吗?由于作业提交比较急迫,暂时先放弃,用的java的文件流,男人嘛,就是要敢舍敢弃!(是我胡说八道的).当然,不搞懂它我是不会罢休的!拭目以待!          好了,不瞎扯了.进入正题吧.我用的编译软件是my Eclipse2014(这个软件不得不说:真TM好

结对项目https://github.com/bxoing1994/test/blob/master/源代码

所选项目名称:文本替换      结对人:曲承玉 github地址 :https://github.com/bxoing1994/test/blob/master/源代码 用一个新字符串替换文本文件中所有出现每个字符串的地方.文件名和字符串都作为命令行参数进行传递.给出相应的测试文件和测试字符串. 项目设计方案        一起选定项目敲定大体结构后,我负责测试和修改,搭档负责写的代码 首先,需要定义一个命令把文本文档读入内存,并进行异常处理:然后定义一个写数据流,以便于替换:最后将内存中修改

fatal: could not read Username for &#39;https://github.com&#39;: No such file or directo

Git push origin master报错 fatal: could not read Username for 'https://github.com': No such file or directo 原因使用https方式的时候 在git remote add origin 的https url 里面没有用户名和密码 修改为如下: git remote add origin https://{username}:{password}@github.com/{username}/pro

Github错误:fatal: Authentication failed for &#39;https://github.com/ ...

GitHub push代码发生错误:fatal: Authentication failed for 'https://github.com/ ... 使用的https提交,在用SourceTree提交代码时候发生错误,返回的错误提示说: fatal: Authentication failed for 'https://github.com/ ... 如图所示: 解决方案,重新执行git config命令配置用户名和邮箱即可: git config -–global user.name "xx