如果列类型为date,我想设置date格式。
我的代码如下:
<div ng-repeat="col in gridColumnDefs">
<div pi-grid-column sort-enable="true" sort-direction="0"
filter-enable="true" column-width="185px"
display-name="{{col.DisplayName}}"
column-type="{{col.ColumnType.toLowerCase()"
property-name="{{col.Name}}">
</div>
</div>如果我知道列类型,可以编写类似这样的代码:
<div pi-grid-column sort-enable="true" column-width="100px"
sort-direction="0" display-name="Date 1" property-name="Date1"
column-type="date" date-format="dd/MM/yyyy" filter-enable="true">
</div>我使用ng-repeat,gridColumnDef是我的列数组。
display-name="{{col.DisplayName}}" : 'Date1'
column-type="{{col.ColumnType.toLowerCase()" : "date"
property-name="{{col.Name}} : "date1"if col.ColumnType = "date" ? date-format: dd/MM/yyyy。我不知道如何在html页面中使用div标签
如果columnType = date,则应设置date-format,如果columnType != date未设置date-format。
有什么想法吗?
发布于 2017-01-20 23:43:57
您可以使用角度表达式插入自定义属性日期格式所需的逻辑:
<div pi-grid-column sort-enable="true" column-width="100px"
sort-direction="0" display-name="Date 1" property-name="Date1"
column-type="date" date-format="{{ col.ColumnType === 'date' ? 'date' : 'dd/MM/yyyy' }}" filter-enable="true">
</div>我建议将此逻辑移动到控制器,并调用一个方法来检索正确的值:
$scope.defineDateFormat = function _defineDateFormat(column) {
return column.ColumnType === 'date' ? 'date' : 'dd/MM/yyyy';
}然后:
<div pi-grid-column sort-enable="true" column-width="100px"
sort-direction="0" display-name="Date 1" property-name="Date1"
column-type="date" date-format="{{ defineDateFormat(col) }}" filter-enable="true">
</div>https://stackoverflow.com/questions/41752205
复制相似问题