In my extjs6 project I have a datefield. When I getvalue it comes back as '2017-07-26T00:00:00'. How can I convert this to 07-26-2017?
I am trying the below which is coming back blank.
var newVal = Ext.Date.format(value, 'm-d-Y')
screenshot below
As per the docs,
Ext.Date.parse makes a javascript date from a string.
Ext.Date.format makes a string from a javascript date.
Since you need to convert a string to a string, you have to combine the two:
Ext.Date.format(Ext.Date.parse('2017-07-26T00:00:00','c'), 'm-d-Y')
You don't need to use
Ext.Date.format and Ext.Date.parse functions
just change the xtype and format property to your gridcolumn
xtype: 'datecolumn',
format: 'm-d-Y'
Example code set grid column property
columns: [
{
text: 'Date',
dataIndex: 'date',
xtype: 'datecolumn',
format:'m-d-Y'
}
],
This will give the output as in '07-26-2017' format..
No need to use renderer as well
hope ull try this
Related
Can someone help me to figure out a way to arrange the columns irrelevant of it columns array positioning? For example, in below grid columns array i just want to display Phone as 1st column and Name as 2nd column. How can i achieve that programmatically?
Columns Array:-
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email'
}, {
text: 'Phone',
dataIndex: 'phone'
}]
While debugging the grid column config with Chrome developer tools, i figured out a parameter "fullColumnIndex" which value getting increased for every column. But specifying that explicitly doesn't make any difference :(
Thanks!
You can do it by using reconfigure method. Docs — http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.panel.Table-method-reconfigure
Here is the description of this method:
reconfigure( [store], [columns] )
Reconfigures the grid / tree with a new store/columns. Either the store or the > columns can be omitted if you don't wish to change them.
The enableLocking config should be set to true before the reconfigure method is > executed if locked columns are intended to be used.
Parameters
store : Ext.data.Store (optional)
The new store. You can pass null if no new store.
columns : Object[] (optional)
An array of column configs
I have an object that has a date column in the it inside an ArrayStore. I then bind that ArrayStore to a grid using the store property. Currently i am using the following string formatter to display the dt in a custom format: formatter: 'date("d M Y")'. This work with no issue and the dates appear as 13 Oct 2014. I would like to uppercase the Oct part. I have tried the following thing I have found online that does not work and produces errors: 'uppercase(date("d M Y"))'. There does not appear to be much documentation on fromatters besides saying it is a string.
How can I uppercase this?
columns:
{
items: [
{ text: 'Date', dataIndex: 'date', editor: 'datefield', formatter: 'uppercase(date("d M Y"))' }
]
}
The formats available on dates are same as here
It doesn't appear there is a particular month with all uppercase however it could be achieved with a renderer like so:
instead of formatter: 'uppercase(date("d M Y"))'
something like this:
renderer: function(value){ return Ext.util.Format.date(value, 'd M Y').toUpperCase(); }
I have a property grid and we set the source for this from a controller. There is a date field that needs formatting. I checked the documentation but the example is not so easy to understand.
The grid view just has the grid defined. The controller gets the values from the server and then uses setSource to populate the grid.
I tried this:
sourceConfig: {
installationDate: {
renderer: Ext.util.Format.date('d.m.Y H:i:s')
}
}
How do I format the date using sourceConfig?
Provide a renderer function in your sourceConfig. You can use the utility function Ext.util.Format.dateRenderer to generate it. To set the format for the corresponding editor, use the date field's format config.
sourceConfig: {
'dateAttribute': {
renderer: Ext.util.Format.dateRenderer('Y-m-d'),
editor: {
xtype: 'datefield',
format: 'd.m.Y'
}
}
}
}
Also see this fiddle.
EDIT:
As pointed out in the comments below, it is important that the keys of sourceConfig match exactly with the keys as used in the actual source in order for the configuration to apply correctly.
I am trying to create a timefield combo box with extJS. I have done this successfully but now I have a problem when I get the value that I select in the combo box.
First the code for making the timefield:
items :[{
fieldLabel: 'Start Time',
name: 'startTime',
xtype: 'timefield',
id: 'startTime',
format: 'H:i',
altFormats:'H:i',
increment: 30
}]
What I want is to get the value in a 24h format. In order to get the value from the time field I use this code:
var startTime = Ext.getCmp('startTime').getSubmitValue();
The problem is that instead of getting the time in 24hour format, the values are transformed into 12 hours format. For example, while I select from the combo the time: 00:00 when I use getSubmitValue() the value is transformed into 12:00 AM, which is not very useful in my case.
My question is: Is there a way to keep the format of the time exactly how it is in the combo box? That would be a 24hour format.
I hope it's clear what I am trying to say.
Thanks
Dimitris
The reason is simple.
getValue returns date object, getSubmitValue returns formatted date.
You just need to format a date received by getValue method.
var field = Ext.getCmp('startTime');
var value = field.getValue();
var formattedValue = Ext.Date.format(value, 'H:i');
Sample here
I found out that if I use the:
var startTime = Ext.getCmp('startTime').getRawValue();
I retrieve the time in 24 format.
In Sencha Touch 2 I have a model with the following fields, DateTimeStart if rendered in a List it shows in this format
Mon Feb 11 2013 11:55:00 GMT +100 (W. Europe Standard Time)
I need to create another field (DateTimeStartConverted) based on DateTimeStart
I need to convert such date in a more short format using 'Y-m-d'.
Printing the result of DateTimeStartConverted in my conversion method it does not display any result (no errors has been throw).
Any idea how to fix it?
{
name: 'DateTimeStart',
type: 'date',
dateFormat: 'MS'
}, {
name: 'DateTimeStartConverted',
type: 'date',
convert: function(value, record){
var jsonDate = record.get('DateTimeStart');
return Ext.Date.format(jsonDate, 'Y-m-d');
}
}
If you just need to display the date properly in a list item template, then you can use the :date() function within your template:
{
xtype: 'list',
...
itemTpl: '<p>Date display test - {DateTimeStart:date("m/d/Y")}</p>',
...
}
As for your convert function, it looks sound, but what do you get for the value and record arguments? Knowing those values would help a lot.