Hi I have a table where I have some columns that need to be exported as currency and some to exported as date
But datatables export date as string. I know the reason to export in the format as specified by the user. But my client needs to do some calculations for which he wants the column to be exported as date and not as string. Does anyone have any ideas how to do it?
Note* I have tried orthogonal option=> Its not working
Below is the code that refers to the problem:
var buttonCommon = {
exportOptions: {
format: {
body: function ( data, column, row ) {
// Strip $ from salary column to make it numeric
return column === 5 ?
data.replace( /[$,]/g, '' ) :
data;
}
}
}
};
Here the user is converting string column to number. Is there anything with which I can convert string to date?
I have tried this code
exportOptions: {
format: {
body: function ( data, column, row ) {
// Strip $ from salary column to make it numeric
var customDate = new Date('2016/10/10');
customDate = (customDate.getMonth() + 1) + '/' + customDate.getDate() + '/' + customDate.getFullYear();
return column === 12 ? customDate: data;
}
},
columns: ':visible',
},
But it still returns 10/10/2016 10/10/2016 10/10/2016 10/10/2016
*as string
hope it may work for you. add below code according to your code,it detect data which is in the date format dd/mm/yyyy
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
if (sData !== null && sData.match(/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20|21)\d\d$/))
{
return 'date-uk';
}
return null;
}
);
and to use this code you have to use this
<script src="//cdn.datatables.net/plug-ins/1.10.12/type-detection/date-uk.js"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.