2
$scope.exportData = function ($searchProductDetails) {
    alasql('SELECT * INTO CSV("searchProductDetails.CSV",?) FROM ?',[$searchProductDetails]);
        };

searchProductDetails = [
   {
     "@search.score": 1.634418,
     "brandName": "Aashirvaad",
     "productId": "16361",
     "highLevelCategory": "Food",
     "lowLevelCategory": "Flour / Atta",
     "subCategory": "Wheat Flour / Atta",
     "productName": "Aashirvaad Sharbati Atta",
     "productImageUrl": "Cooking_Aashirvaad-Sharbati-Atta.jpg",
     "P1PKBrandsId": 10009
    },
    {
     "@search.score": 1.5750113,
     "brandName": "Pillsbury",
     "productId": "22017",
     "highLevelCategory": "Food",
     "lowLevelCategory": "Flour / Atta",
     "subCategory": "Wheat Flour / Atta",
     "productName": "Pillsbury Chakki Fresh Atta",
     "productImageUrl": "Cooking_Pillsbury-Chakki-Fresh-Atta.jpg",
     "P1PKBrandsId": 10823
    }
]

I don't want to export @search.score, P1PKBrandsId and productImageUrl but now I can export all and I need export in CSV format only.

2 Answers 2

1

You can use REMOVE COLUMNS modifier. AlaSQL will remove all unnecessary columns for you. Try this code:

$scope.exportData = function ($searchProductDetails) {
    alasql('SELECT * REMOVE COLUMNS [@search.score], P1PKBrandsId, \
         productImageUrl INTO CSV("searchProductDetails.CSV",{headers:true}) FROM ?',
         [$searchProductDetails]);
};
Sign up to request clarification or add additional context in comments.

Comments

0

Try below Code:

var productData = angular.copy(searchProductDetails);  
var finalJson =[];  
angular.forEach(productData, function(obj) {
            finalJson.push({"brandName": obj.brandName, 
                "productId": obj.productId,
                "highLevelCategory": obj.highLevelCategory,
                "lowLevelCategory": obj.lowLevelCategory,
                "subCategory": obj.subCategory,
                "productName": obj.productName,
            });
        });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.