ngGrid单元格的值是一个枚举值,我怎么使用枚举的名字吗? [英] ngGrid cell value is an enum value, how do I use the enum name?

查看:610
本文介绍了ngGrid单元格的值是一个枚举值,我怎么使用枚举的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的ngGrid定义:

This is my ngGrid definition:

$scope.notesGrid = { 
    data: 'notes',
    enableHighlighting: true,
    enablePinning: false,
    enableColumnResize: true,
    keepLastSelected: false,
    columnDefs: [
        {field:'date', displayName:'Date', cellFilter:'date:\'yyyy-MM-dd\'', cellClass:'align-right'},
        {field:'noteId', displayName:'Code', cellClass:'align-right'},
        {field:'type', displayName:'Sale/Rent'}],
    selectedItems: $scope.selectedNotes,
    multiSelect: false,
    afterSelectionChange: function (rowItem, event) {
    }
};

该JSON重新presenting一个音符(从JSON阵列票据)是这样的:

The JSON representing a single note (from the JSON Array notes) is like this:

{
    noteId: 5,
    date: '2014/09/18',
    type: 1                 /* 1 means Sale, 2 means Rent */
}

我不希望打印1或2,在类型小区。

我想这要取决于价值打印出售或出租。

I don't want to print "1" or "2" in the "type" cell.
I want to print "Sale" or "Rent" depending on the value.

问:什么是实现这一目标的最佳途径?你会使用cellTemplate? cellTemplate听起来更像是一个看起来正感觉的东西。我在做一些测试与cellTemplate但我注意到,默认cellTemplate是HTML方面非常齐全。在NG-网格为模板维基他们这样说:

Question: What is the best way to achieve this? Would you use a cellTemplate? cellTemplate sounds more like a "look-n-feel" thing. I was doing some tests with cellTemplate but I noticed that the default cellTemplate is very complete in terms of html. In ng-grid's wiki for templating they say this:

https://github.com/angular-ui/ng-grid/维基/模板

 Default Cell Template:
 <div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text>{{row.getProperty(col.field)}}</span></div>

我不希望使用一个复杂的模板是,默认已经是非常复杂的。

I don't want to be using a complex template and the default is already very complex.

也许我应该我的整个注释 JSON阵列插入到前重新映射 notesGrid.data ?什么是优雅的解决方案?

Maybe I should re-map my entire notes JSON Array before plugging into the notesGrid.data? What is an elegant solution?

推荐答案

我会做的JSON变换有网格的数据提供明确的名称。

I would do a transform on the json to have clear names available in the grid data.

  angular.forEach($scope.myData, function(value) {
    if (value.type == 1) {
      value.typeName = 'Sale';
    } else {
      value.typeName = 'Rent';
    }
  });

如果你想给用户一个过滤器的输入,只要他能在以后进入SEARCHTEXT这可能是很方便的。

This may be handy if you want to give the user a filter input where he can enter a searchtext at a later point.

看这里

这篇关于ngGrid单元格的值是一个枚举值,我怎么使用枚举的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆