本文转自:https://stackoverflow.com/questions/27747184/format-a-ui-grid-grid-column-as-currency-rc-3-0

You can use 'currency' cellFilter to format your data.

$scope.gridOptions = {
enableSorting: true,
columnDefs: [
{name: 'Award Title', field: 'projectTitle', minWidth: 100 },
{name: 'Amount', field: 'awardAmount', cellFilter: 'currency' }}
]
};

Have a look at this nice article : http://brianhann.com/6-ways-to-take-control-of-how-your-ui-grid-data-is-displayed/

In summary your options are :

  • Bindings
  • Cell Filters
  • Cell Templates
  • Links
  • Buttons
  • Custom directives

I have used the cell Filter option myself (code translated to your case, not tested):

$scope.gridOptions = {
enableSorting: true,
columnDefs: [
{
name: 'Award Title',
field: 'projectTitle', minWidth: 100
}, {
name: 'Amount',
field: 'awardAmount',
cellFilter: 'currencyFilter'
}
]
};

With filter defined hereunder :

app.filter('currencyFilter', function () {
return function (value) {
return value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
});

Cheers, G

I'm late to the party, but wanted to share the best thing that worked for me:

JS:

myGrid.columnDefs = [{
field: "Sale",
cellFilter: 'number:2',
cellClass:'currency'
}]

CSS:

.currency{
text-align:right;
}
.currency .ui-grid-cell-contents:before{
content: '$';
float: left;
}

Final result:


Details:

First I tried using cellFilter:'currency' as mentioned in a previous answer, but it didn't allow for various dollar amounts and didn't align the values to the right:

So then I added a currency class, and right-align, which fixed alignment, but not different dollar amounts.

Unfortunately, I wasn't able to find an easy fix for this (although I feel like there is one out there somewhere), so I had to change the cellFilter from currency to number:2 - this means "Always show 2 decimals".

Then I wanted a dollar sign at the left of the cell (to avoid varying dollar amounts), for that I added the following css:

.currency .ui-grid-cell-contents:before{
content: '$';
float: left;
}

Which left me with the final result:

[转]Format a ui-grid grid column as currency的更多相关文章

  1. NGUI UI Grid, two column

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

  2. kendo ui中grid页面参数问题

    kendo ui 中grid 算是最长用的控件之一,当使用分页效果时,我们要传递分页参数与自己定义的参数如: var dataSource = new kendo.data.DataSource({ ...

  3. wx.grid.Grid

    # -*- coding: cp936 -*- import wx import wx.grid import wx.lib.gridmovers as gridmovers import pymss ...

  4. wxPython控件学习之wx.grid.Grid 表格控件

    wxPython控件学习之wx.grid.Grid (包括对GridCellEditor和GridCelRender的扩展,以支持更多的grid cell 样式, 以GridCellColorEdit ...

  5. Python3 tkinter基础 grid(row,column) 窗体的布局

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. kendo ui之grid列表

    1.test_grid.jsp <html><head> <%@ include file="/WEB-INF/jsp/common/top.jsp" ...

  7. Unity3D 使用 UI 的 Grid Layout Group 组件。

    1.首先创建一个容器,用于存放列表项的内容. 这里使用 Panel 来做为容器. 这里要注意! “Grid Layout Group”是要增加在容器的游戏对象里. 同时,只有容器对象的子对象才有排列效 ...

  8. Python Tkinter模块 Grid(grid)布局管理器参数详解

    在使用Tkinter模块编写图像界面时,经常用到pack()和grid()进行布局管理,pack()参数较少,使用方便,是最简单的布局,但是当控件数量较多时,可能需要使用grid()进行布局(不要在同 ...

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

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

随机推荐

  1. 2:C#TPL探秘

    理论: 1. 只要方法是 Task类型的返回值,都可以用 await 来等待调用获取返回值. 2. 如果一个返回 Task类型的方法被标记了 async,那么只要方法内部直接 return T 这个 ...

  2. iOS 获取 UITabViewController 和 UINavigationController 的图标位置

    这些图标是放在 UITabBar 和 UINavigationBar 里的.所以只要遍历它们的 subViews,找到类型是 UIButton 的就可以了. 所有想获取它们的相对位置很容易. 获取到相 ...

  3. python网络编程--操作系统介绍

    1.操作系统介绍 操作系统位于计算机硬件与应用软件之间,本质也是一个软件.操作系统由操作系统的内核(运行于内核态,管理硬件资源)以及系统调用(运行于用户态,为应用程序员写的应用程序提供系统调用接口)两 ...

  4. 获取BinaryReader中读取的文件名

    BinaryReader br; br = null; br = new BinaryReader(new FileStream("E:demo.txt", FileMode.Op ...

  5. jquery源码解析:attr,prop,attrHooks,propHooks详解

    我们先来看一下jQuery中有多少个方法是用来操作元素属性的. 首先,看一下实例方法: 然后,看下静态方法(工具方法): 静态方法是内部使用的,我们外面使用的很少,实例方法才是对外的. 接下来,我们来 ...

  6. [Objective-C语言教程]错误处理(22)

    在Objective-C编程中,错误处理由Foundation框架中提供的NSError类提供处理. 与仅使用错误代码或错误字符串相比,NSError对象封装了更丰富且更具可扩展性的错误信息. NSE ...

  7. Haproxy搭建Web群集

    一.Haproxy与LVS LVS不支持正则处理,不能实现动静分离,对于大型网站,LVS的实施配置复杂,维护成本相对较高 Harpoxy是一款可提供高可用性,负载均衡.及基于TCP和HTTP应用的代理 ...

  8. H5入门基础(一)

    我们还是围绕这几个问题来学习: 1.什么是H5? 2.为什么要用H5? 3.怎么用H5? 1.什么是H5? ♦HTML是指超文本标记语言(Hyper Text Markup Language). ♦H ...

  9. Dubbo自定义日志拦截器

    前言 上一篇文章 Spring aop+自定义注解统一记录用户行为日志 记录了 web层中通过自定义注解配合Spring aop自动记录用户行为日志的过程.那么按照分布式架构中Dubbo服务层的调用过 ...

  10. JavaScript创建对象的4种方法

    我们有很多种方式去构造一个对象.可以构造一个对象字面量,也可以和new前缀连用去调用一个构造器函数,或者可以使用Object.create方法去构造一个已经存在的对象的新实例,还可以调用任意一个会返回 ...