AngularJS UI 网格,如何用 $0.00 过滤货币

AngularJS UI Grid, How to filter currency with $0.00

我正在使用 AngularJS UI-Grid 并尝试过滤定价。过滤适用于小数点后面不是 0 的任何数字。

$scope.GridOptions = {
            enableFiltering: true,
            rowEditWaitInterval: -1,
            multiSelect: true,
            enableColumnMenus: false,
            columnDefs: [
                { name: 'Name', field: 'Item', width: '15%' },
                { name: 'Price', field: 'Price', type: 'number', cellFilter: 'currency', width: '6%' },
                { name: 'Current Price', field: 'CurrentPrice', type: 'number', cellFilter: 'number: 2', width: '12%' }
            ]

2 after decimal, 0 after decimal

根据文档@http://ui-grid.info/docs/#/api/ui.grid.class:GridOptions.columnDef 将单元格 'type' 属性的字段类型更改为 'numberstr'

为了得到一个漂亮的货币栏,我不得不跳过太多的障碍,但希望将来会考虑到这一点。这最适合我:

JS - 添加 cellFilter:number:2cellClass:'currency' 到列定义:

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

CSS - 将这两个样式定义添加到您的 css:

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

最终结果:

您可以在我的原始回答中阅读更多相关信息 here