简体   繁体   English

nggrid单元格模板中的ui-date-format

[英]ui-date-format in nggrid cell template

I want a date picker in my cell so i have created a cell template 我想在我的单元格中使用日期选择器,因此我创建了一个单元格模板

var myDateTemplate= '<input type="text"  ng-model="row.entity.myDate"  />';

my col model is 我的col模型是

    var col = [{
                field : 'myDate',
                displayName : 'My Date',
                enableCellEdit : true,
                width : '130',
                cellTemplate : myDateTemplate,
                editableCellTemplate : myDateTemplate,
                resizable : true,
                sortable : false
            }]

it works fine and when i choose date i get it in mm/dd/yyyy format i want to change it to dd/mm/yyyy format to i added ui date format 它工作正常,当我选择日期我得到它的mm / dd / yyyy格式我想将其更改为dd / mm / yyyy格式我添加了ui日期格式

 var myDateTemplate = '<input ui-date="{ dateFormat: 'dd mm yyyy' }" ui-date-format="dd mm yyyy" ng-model="row.entity.myDate"/>';

when i use ui date format it will throw a error 当我使用ui日期格式时,它会抛出一个错误

Error: Syntax Error: Token 'undefined' not a primary expression at column NaN of the expression [{ dateFormat:] starting at [{ dateFormat:] 错误:语法错误:令牌'undefined'不是表达式[{dateFormat:]的列NaN处的主表达式,从[{dateFormat:]开始

and it is giving the date like 而它给出的日期就像

Mon Dec 23 2013 00:00:00 GMT+0530 (India Standard Time) instead of my preffered format. 2013年12月23日星期一00:00:00 GMT + 0530(印度标准时间)而不是我的优先格式。

I think you're close, just escape the quotes around your date format to make the proper string: 我认为你很接近,只是绕过日期格式的引号来制作正确的字符串:

var myDateTemplate = '<input ui-date="{ dateFormat: \'dd mm yyyy\' }" ui-date-format="dd mm yyyy" ng-model="row.entity.myDate"/>';

I'm not using the exact same cellTemplate you are (presumably your input field will work correctly once you escape the quotes). 我没有使用完全相同的cellTemplate(大概你的输入字段一旦你逃脱引号就能正常工作)。 This is working for me: 这对我有用:

columnDefs: [{
                field:'StartTime', 
                displayName:'Start Time', 
                cellFilter: 'date:\'MM/dd/yyyy HH:MM:ss\'' 
            }, {
                field:'duration', displayName:'Duration'
            }, {
                field:'distance', displayName:'Distance'
            }, {
                field:'typedesc', displayName:'Type'
            }, {
                field:'Drivers', displayName:'Drivers'
            }]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM