本文转自: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. BEAUTIFUL

    DESCRIPTION:一个长度为n 的序列,对于每个位置i 的数ai 都有一个优美值,其定义是:找到序列中最长的一段[l, r],满足l<i<r,且[l, r] 中位数为ai(我们比较序 ...

  2. 我编写 33 个 VSCode 扩展的原因以及管理扩展的经验

    简评:使用工具的同时自己创造一些工具或扩展,是一件很棒的事情. 以下"我"指原作者 Fabio 大家好,我叫 Fabio,是一位自学成才的开发人员,热衷于开源和授权.我也喜欢自己制 ...

  3. Express-及中间件的简单理解

    Express Express 是一个基于node平台,保持最小规模的灵活的 Node.js Web 应用程序开发框架,在Node.js基础上扩展对了web应用开发所需要的基础功能为 Web 和移动应 ...

  4. null、 is_null() 、empty() 、isset() PHP 判断变量是否为空

    PHP中,在判断变量是否为空的时候,总会纠结应该选用哪个函数,下面列取常用的多种情况,其中1/3经过我的验证,其它来自网络,验证后使用... 使用 PHP 函数对变量 $x 进行比较 表达式 gett ...

  5. shell ssh远程执行命令

    [root@backup shell]# vi backup.sh #!/bin/sh ipAddress=172.17.167.38 ssh -tt root@$ipAddress -p 22 &l ...

  6. 嵌入式C语言自我修养 05:零长度数组

    5.1 什么是零长度数组 顾名思义,零长度数组就是长度为0的数组. ANSI C 标准规定:定义一个数组时,数组的长度必须是一个常数,即数组的长度在编译的时候是确定的.在ANSI C 中定义一个数组的 ...

  7. 编程开发之--java多线程学习总结(5)

    4.对继承自Runnable的线程进行锁机制的使用 package com.lfy.ThreadsSynchronize; import java.util.concurrent.locks.Lock ...

  8. python里有意思的文件查找glob模块

    python标准库之glob介绍 glob 文件名模式匹配,不用遍历整个目录判断每个文件是不是符合. 1.通配符 星号(*)匹配零个或多个字符 import glob for name in glob ...

  9. scrapy框架安装及使用

    一.Windows安装 Twisted下载及安装 在https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载对应的Twisted的版本文件 在命令行进入到Twist ...

  10. 使用二叉搜索树实现一个简单的Map

    之前看了刘新宇大大的<算法新解>有了点收获,闲来无事,便写了一个二叉搜索树实现的Map类. java的Map接口有很多不想要的方法,自己定义了一个 public interface IMa ...