[转]Format a ui-grid grid column as currency
本文转自: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的更多相关文章
- NGUI UI Grid, two column
NGUI UI Grid, two column, set Arrangement Horizontal, Column Limit 2.
- kendo ui中grid页面参数问题
kendo ui 中grid 算是最长用的控件之一,当使用分页效果时,我们要传递分页参数与自己定义的参数如: var dataSource = new kendo.data.DataSource({ ...
- wx.grid.Grid
# -*- coding: cp936 -*- import wx import wx.grid import wx.lib.gridmovers as gridmovers import pymss ...
- wxPython控件学习之wx.grid.Grid 表格控件
wxPython控件学习之wx.grid.Grid (包括对GridCellEditor和GridCelRender的扩展,以支持更多的grid cell 样式, 以GridCellColorEdit ...
- Python3 tkinter基础 grid(row,column) 窗体的布局
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- kendo ui之grid列表
1.test_grid.jsp <html><head> <%@ include file="/WEB-INF/jsp/common/top.jsp" ...
- Unity3D 使用 UI 的 Grid Layout Group 组件。
1.首先创建一个容器,用于存放列表项的内容. 这里使用 Panel 来做为容器. 这里要注意! “Grid Layout Group”是要增加在容器的游戏对象里. 同时,只有容器对象的子对象才有排列效 ...
- Python Tkinter模块 Grid(grid)布局管理器参数详解
在使用Tkinter模块编写图像界面时,经常用到pack()和grid()进行布局管理,pack()参数较少,使用方便,是最简单的布局,但是当控件数量较多时,可能需要使用grid()进行布局(不要在同 ...
- Kendo UI Grid 批量编辑使用总结
项目中使用Kendo UI Grid控件实现批量编辑,现在将用到的功能总结一下. 批量编辑基本设置 Kendo Grid的设置方法如下: $("#grid").kendoGrid( ...
随机推荐
- list<T>集合中的Remove()、RemoveAt()、RemoveRange()、RemoveAll()的用法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- DataGridViewComboBoxColumn值无效解决方法
值无效,可能是你下拉框选项,没有这样的值,而你却设置这个值. dataGridView1.Rows[i].Cells[1].Value = "选项一"; 解决方法就是在窗体的构造函 ...
- 记开发个人图书收藏清单小程序开发(六)Web开发
Web页面开发暂时是没有问题了,现在开始接上Ptager.BL的DB部分. 首先需要初始化用户和书房信息.因为还没有给其他多余的设计,所以暂时只有个人昵称和书房名称. 添加 Init Razor Pa ...
- 3-C#面向对象概念
本篇博客对应视频讲解 回顾 前两篇博文带大家快速的感知一下使用C#编写程序是怎样的过程,能实现什么样的功能.同时也提到了面向对象的概念.本篇文章就是更加详细的去将面向对象编程中常见的概念进行示例说明, ...
- std::shared_ptr之deleter的巧妙应用
本文由作者邹启文授权网易云社区发布. std::shared_ptr 一次创建,多处共享,通过引用计数控制生命周期. 实例 在邮箱大师PC版中,我们在实现搜索时,大致思路是这样的: 每一个账号都有一个 ...
- MVC框架入门准备(一)
最近开发一套自己的框架,开发了一个多月,已传到git,学到了挺多,系列文章我会慢慢写挺多 这里先讲大致框架多用到的某些函数,我这里先列举一部分,网上对函数的定义,参数说明等,我就不照搬了,记录自己的理 ...
- docker启动时报错
docker安装成功后,启动时报错. 1.后来排查后发现yum install docker安装的是从test存储库中安装的. 后来我指定了特定的版本后,而且从stable存储库安装的,以后再启动就好 ...
- Chrome 中删除单条浏览记录
悲伤...之前用非隐私窗口观看了小电影.于是打开 chrome://settings/ ...... 现在才知道 windows 上使用 shift + del 即可删除该浏览记录 ....... 以 ...
- P4090 [USACO17DEC]Greedy Gift Takers
题目链接 题意分析 首先 如果当前序列中一头奶牛拿不到礼物的话 那么他后面的奶牛也拿不到礼物 所以我们可以二分 由于可以操作无限次 所以我们对于当前\([1,mid)\)的奶牛按照\(c\)值排序之后 ...
- HTML03--表单、input、框架、URL
接上一篇“HTML02随笔”,在这里单独说一下HTML中最重要的标签--表单<form> 1.表单form:用于收集用户输入 <form action="" me ...