PDA

View Full Version : [CLOSED] Export Date Format



canusr1
Sep 09, 2013, 8:59 AM
Hello there,

I have an export function to export excel as in

http://examples2.ext.net/#/GridPanel/Miscellaneous/Export_Data_PostBack/

I wanna get date as 'd/m/YY' format in exported excel.

May I know how to achieive this?

Thanks.

Daniil
Sep 09, 2013, 12:33 PM
Hi @canusr1,

I can suggest to try to modify data using the prepare option of the getRowsValues method.


App.GridPanel1.getRowsValues({
prepare: function (data, record) {
data.lastChange = Ext.Date.format(data.lastChange, "d/m/y");
}
});

See also
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Date-method-format

canusr1
Sep 11, 2013, 1:15 AM
Hello Daniil,

Thanks for the solution. I applied your code to my javascript as follow:



var SaveDataForExportExcel = function () {
App.hStoreData.setValue
(
Ext.encode(App.gvTransactionList.getRowsValues
(
{ filterField: function (r, name, value) { return name != 'RECORD_STATUS' && name != 'TRANS_ID' && name != 'PROFILE_ID' && name != 'EXPORT_FLAG' && name != 'SALESREP_ID' && name != 'SALESREP_DISPLAY'; } }, { selectedOnly: false },
{ prepare: function (data, record) { data.TRANSDATE = Ext.Date.format(data.TRANSDATE, "d/m/y"); data.PROCESSED_DATE = Ext.Date.format(data.PROCESSED_DATE, "d/m/y"); data.CLOSED_DATE = Ext.Date.format(data.CLOSED_DATE, "d/m/y"); alert('TRANDSTE: ' + data.TRANSDATE + ' PROCESSED_DATE: ' + data.PROCESSED_DATE + ' CLOSED_DATE: ' + data.CLOSED_DATE); } }
)
));
};


When I alert the date column's value, I got the format 'd/m/y' as I required.

6881

However in the exported excel, the date value remains as

TRANSDATE
2013-06-27T00:00:00

PROCESSED_DATE
2013-05-29T00:00:00

CLOSED_DATE
2013-08-06T00:00:00

I don't want time stamp to appear in the exported excel file.

Please advise me for that.

Thank you.


Hi @canusr1,

I can suggest to try to modify data using the prepare option of the getRowsValues method.


App.GridPanel1.getRowsValues({
prepare: function (data, record) {
data.lastChange = Ext.Date.format(data.lastChange, "d/m/y");
}
});

See also
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Date-method-format

Daniil
Sep 11, 2013, 6:14 AM
I just tried it with this example with the Last Change column.
http://examples2.ext.net/#/GridPanel/Miscellaneous/Export_Data_PostBack/

It appears to be working for me.

Though, I got confused a bit. Initially, I tested that example as it is. So, the dates appeared as "2013-09-01T00:00:00". Then I tested with the "prepare" function. When I opened the exported file I saw "2013-09-01T00:00:00" again. It was confusing. Then I closed Excel and re-opened the file. After that the dates appeared as "01/09/13". So, somehow Excel didn't refresh. Maybe, you are facing the same issue.