PDA

View Full Version : Problem with date/time and column width



hieu79vn
10 Apr 2012, 7:53 AM
Hello,

I use Json.net to transform a datatable to json string. When I bind this string with panelgrid all columns are showed except the data column. The date format of Json is YYYY-MM-DDTHH:mm:SS.xx
How can I format the data column to DD/MM/YY HH:mm:SS

Furthermore, I have an actioncolumn with an icon inside. I set its width and minWidth to 20 pixel but it seems that the width of column is always greater than 30px. How can I reduce the width of this column?

{
xtype:'actioncolumn',
minWidth : 15,
width:15,
items: [{
icon: '<%=ImagePath%>star_white.gif',
tooltip: 'Favorite'
}]
},
33825
Thank you
Tang

scottmartin
10 Apr 2012, 9:18 AM
You can use a renderer to format your date:




function render_date(val) {
val = Ext.util.Format.date(val, 'm/d/Y');
return val;
}
..

{ dataIndex: 'date_field', header: 'MyDate', renderer: render_date }


Regards,
Scott.

hieu79vn
10 Apr 2012, 11:15 PM
Hi Scott. Thank you for your reply.
I did as your instruction but it display NanNan in the column.

chramer
11 Apr 2012, 12:38 AM
Make sure that you set the type for the date field in the model :


fields : [
...
{name : 'DATE', type : 'date', dateFormat : ..},
...
]

And then check this : http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Field-cfg-dateFormat

hieu79vn
12 Apr 2012, 12:03 AM
Thanks chramer but i have the same problem. I think because the gridPanel don't know json date format. Maybe we must format the json string date to the format that is known by gridPanel.
But I dont know what is the format recognized by gridPanel and do you have any idea for the convertion function?

chramer
12 Apr 2012, 12:18 AM
can you show us the json returned by the server ?

scottmartin
12 Apr 2012, 4:22 AM
Date is returned in DB format: "2011-08-08" (string)

Scott.

chramer
12 Apr 2012, 5:38 AM
Forgot it!
Add this to the model..

type : 'date'
and this to the column..

xtype: 'datecolumn'
Test case here : http://jsfiddle.net/serju/SuXV5/

hieu79vn
13 Apr 2012, 5:07 AM
Hi Chramer,

Could you have a look at this?
http://jsfiddle.net/SuXV5/14/
the date column doesn't show data

Thanks.

scottmartin
13 Apr 2012, 6:21 AM
What are you seeing when you run? I see a date value based on your data (see attached)
34005

Scott.

hieu79vn
13 Apr 2012, 6:38 AM
I will retry it.
Thank you very much :x:x:x:x:x:x:x