({ getDatetimeasusertimezone : function(component,datetime, offset){ // create Date object for current location var d = new Date(datetime); // convert to msec // add local time zone offset // get UTC time in msec var utc = d.getTime() + (d.getTimezoneOffset() * 60000); // create new Date object for different city // using supplied offset var nd = new Date(utc + (3600000*offset)); // return time as a string return nd.toLocaleString(); }, sortData : function(component,fieldName,sortDirection){ var data = component.get("v.filteredData"); //function to return the value stored in the field var key = function(a) { return a[fieldName]; } var reverse = sortDirection == 'asc' ? 1: -1; // to handel number/currency type fields if(fieldName == 'CreatedDate' || fieldName == 'LastModifiedDate'){ data.sort(function(a,b){ var a = key(a) ? key(a) : ''; var b = key(b) ? key(b) : ''; return reverse * ((a>b) - (b>a)); }); } else{// to handel text type fields data.sort(function(a,b){ var a = key(a) ? key(a).toLowerCase() : '';//To handle null values , uppercase records during sorting var b = key(b) ? key(b).toLowerCase() : ''; return reverse * ((a>b) - (b>a)); }); } //set sorted data to accountData attribute component.set("v.filteredData",data); }, convertArrayOfObjectsToCSV : function(component,objectRecords){ // declare variables var csvStringResult, counter, keys, columnDivider, lineDivider; // check if "objectRecords" parameter is null, then return from function if (objectRecords == null || !objectRecords.length) { return null; } // store ,[comma] in columnDivider variabel for sparate CSV values and // for start next line use '\n' [new line] in lineDivider varaible columnDivider = ','; lineDivider = '\r\n'; // in the keys valirable store fields API Names as a key // this labels use in CSV file header keys = ['Id','HIC_ShopifySync__Store__c','Name','HIC_ShopifySync__Shopify_Id__c','HIC_ShopifySync__Info__c','HIC_ShopifySync__Is_Webhook__c','HIC_ShopifySync__Error_id__c','CreatedDate','LastModifiedDate' ]; csvStringResult = ''; csvStringResult += keys.join(columnDivider); csvStringResult += lineDivider; for(var i=0; i < objectRecords.length; i++){ counter = 0; for(var sTempkey in keys) { var skey = keys[sTempkey] ; if(counter > 0){ csvStringResult += columnDivider; } if(skey == 'HIC_ShopifySync__Info__c'){ csvStringResult += '"' + objectRecords[i][skey].replace(/['"']+/g, '').replace(/['#']+/g, '') + '"' ; }else{ csvStringResult += '"' + objectRecords[i][skey] + '"' ; } counter++; } // inner for loop close csvStringResult += lineDivider; }// outer main for loop close // return the CSV formate String return csvStringResult; } })