ui-date-format in nggrid cell template - angularjs

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
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
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
Error: Syntax Error: Token 'undefined' not a primary expression at column NaN of the expression [{ dateFormat:] starting at [{ 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.

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). 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'
}]

Related

Selecting date gives an object, not the dates

When I select dates and apply the filter, the startDate and endDate both are objects and i can't seem to be able to get the selected days.
I have already tried to select the attributes inside of the object, but it doesn't give me a good date.
I have the following code:
CONTROLLER
$scope.datePicker = {
date: {startDate: null, endDate: null},
options: {
maxSpan: {
days: 31
},
maxDate: moment(),
locale: {
separator: ' - ',
format: "D/MM/YYYY"
},
monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro',
'Outubro', 'Novembro', 'Dezembro'
]
}
};
HTML
<input class="filter-select date-picker" type="text"
date-range-picker
options="datePicker.options"
max="datePicker.options.maxDate"
ranges="datePicker.opstions.maxSpan.days"
ng-model="datePicker.date" />
I also have a watcher that logged the following image:
Does anyone knows how to get the the startDate and endDate values as a simple string or a Date format?
You can use moment to get the date with the format you expect.
For Example:
let startDate = moment($scope.datePicker.date.startDate).format("DD-MM-YYYY");
let endDate = moment($scope.datePicker.date.startDate).format("DD-MM-YYYY");
To know about various date formats you can check this on moment date formats

Date time conversion in extJS or sencha

hello there's I want to convert 03-04-2017 12:00AM to 2017-12-01 12:00:00
how can I do it in Ext Js
currently my code is:
this.ToDatePicker = Ext.create('Ext.form.field.Text', {
xtype: 'textfield',
name: 'name',
labelAlign: 'top',
fieldLabel: 'Date Time',
value: Ext.Date.format(new Date(), "d-m-Y h:iA"),
listeners: {
scope: this,
afterrender: function (c) {
c.getEl().on('click', function (e) {
console.log(e.target)
NewCssCal_DisableAfterToday(Ext.get(e.target).dom.id, 'ddmmyyyy', 'dropdown', true, 12)
});
}
}
});
this.ToCalenderIcon = new Ext.Container({
html: "<img class='calIcons' src='public/touchWorldCssJs/images/cal.gif'/>",
scope: this,
padding: '27 5 5 5',
listeners: {
scope: this,
afterrender: function (c) {
c.getEl().on('click', function (e) {
if (Ext.get(e.target).hasCls('calIcons')) {
console.log(Ext.get(e.target).dom.id);
NewCssCal_DisableAfterToday(me.ToDatePicker.inputEl.id, 'ddmmyyyy', 'dropdown', true, 12)
}
});
}
}
});
this.ToCalenderIcon after rendering this set date formate like 03-04-2017 12:00AM So I need to convert this to 2017-12-01 12:00:00
The AM/PM notion isn't supported by JavaScript natively as far as I could tell, so you'll have to do the parsing according to the specified format through Ext.Date.
In your toDatePicker, you explicitly format the date to be "d-m-Y h:iA".
To get that back into a different format you need to first parse it (as JavaScript's native Date can't parse the resulting string):
Ext.Date.format(Ext.Date.parse("03-04-2017 12:00AM", "d-m-Y h:iA"), "d-m-Y h:i:s")
I hope that's what you were looking for.
If you're instead interested how to make the 3rd of April look like the first of December, you should just write 1st of December in the first place.

How to set culture to Kendo grid column?

I have try to set a culture to Ireland Currency '€' to the footerTemplate. But it always set the US '$' Currency in footerTemplate.
Sample column:
{
field: "IEGrantTotalAvg",
title: "%",
type: "number",
filterable: false,
format: "{0:c3}",
attributes: { "class": "right-align" },
footerTemplate: function (data) {
return "<div style='white-space:initial;float:right'>" + " " + kendo.toString((Avg == null ? 0 : Avg), "c3") + "</div>";
}
}
Thanks in advance!
You will need to set the current culture in Kendo. See documentation here. Note that you will also need to include the respective culture script to the page.
I have created a JS Fiddle showing currency formatting with culture en-IE in the footer template.

Angularjs ui grid date filter between date range not working

I am using Angular UI grid and I have a date column in which I need to have a filter that filters between start and end date without any date picker
Looking at that example, I tried adding type:'date' to the column definition, however the grid still doesn't filter out rows before the date typed into the 'from...' filter box and after the date typed into the 'to...' filter box.
Anything that I am missing something ?
{ field: 'mixedDate',
type: 'date',
width: '15%',
cellFilter: 'date:"mediumDate"',
filters:[
{
condition: uiGridConstants.filter.GREATER_THAN,
placeholder: 'greater than'
},
{
condition: uiGridConstants.filter.LESS_THAN,
placeholder: 'less than'
}]}
I'm looking for functionality like the Age column here: http://ui-grid.info/docs/#/tutorial/103_filtering
except with dates instead of numbers.

Binding date value to ng-model in angular kendo date picker

I have an api which return the date in this format "014-08-26T15:10:45.402Z" i am using angular kendo ui .The problem i am facing is the date is not getting bound to the kendo date picker.Could someone help me out .
<input kendo-date-picker ng-model="emp.datestart" k-format="MM/dd/yyyy" />
In order to have the Kendo DatePicker working with a string date value model you need:
1) Use k-ng-model instead of ng-model.
2) Tell the widget in which exact format the date will be parsed.
<input kendo-date-picker k-ng-model="emp.datestart" k-options="datePickerOptions" />
Then at your AngularJS controller you will specify the date parsing format, for example:
$scope.datePickerOptions = {
parseFormats: ["yyyy-MM-ddTHH:mm:ss"]
};
you can use something like this
<h4>Select date:</h4>
<input
kendo-date-time-picker
k-options="monthSelectorOptions"
data-k-ng-model="dateObject"
data-ng-model="dateString.startDate"
style="width: 100%;" />
var startDate = new Date();
$scope.monthSelectorOptions = {
value: startDate,
format: "dd/MM/yyyy h:mm tt",
parseFormats: ['ddd MMM dd yyyy'],
animation: {
close: {
effects: "fadeOut zoom:out",
duration: 300
},
open: {
effects: "fadeIn zoom:in",
duration: 300
}
},
culture: "de-DE",
};
And here is complete solution on kendo dojo

Resources