Code Monkey home page Code Monkey logo

Comments (2)

kaue avatar kaue commented on June 8, 2024

Try the option orderHeaders: false

from jsonexport.

kzimic avatar kzimic commented on June 8, 2024

That solved the problem, Thanks!

var jsonexport = require('jsonexport');

var options = {
    orderHeaders: false
};

router.get('/:catid', function (req, res, next) {

    var catData;

    models.Product.findAll({

        where: {parent_id: req.params.catid},
        include: [
            {
                model: models.ProductNumeric
            },
            {
                model: models.ProductAlphanumeric
            }
        ]

    }).then(function (category) {
        var dt = datetime.create();
        var currentDate = dt.format('Y/m/d');
        jsonexport(JSON.parse(JSON.stringify(category)),options,function(err, csv){
            if(err) return console.log(err);
            res.setHeader('Content-disposition', 'attachment; filename=category_' + req.params.catid + '_' + currentDate + '.csv');
            res.setHeader('Content-type', 'text/csv');
            res.charset = 'UTF-8';
            res.write(csv);
            res.end();
        });

    });
});

//CSV

id,parent_id,regular,parent,child,configuration,name,alias,part_number,status,published,pb_free,rohs,hirel,is_new,registerable,navigation,search
84192,3551,1,0,0,(none),name,alias,PD-LPM-0102EP,Obsolete,1,0,0,0,0,1,1,1
84193,3551,1,0,0,(none),name,alias,PD-NPM-0305EP,Obsolete,1,0,0,0,0,1,1,1
84194,3551,1,0,0,(none),name,alias,PD-NPM-0306EP,Obsolete,1,0,0,0,0,1,1,1
84944,3551,1,0,0,(none),name,alias,PD70101ILQ,In Production,1,1,1,0,0,1,1,1
84945,3551,1,0,0,(none),name,alias,PD70201ILQ,In Production,1,1,1,0,0,1,1,1
84195,3551,1,0,0,(none),name,alias,PD-NPM-0307EP,Obsolete,1,0,0,0,0,1,1,1
84196,3551,1,0,0,(none),name,alias,PD-NPM-0308EP,Obsolete,1,0,0,0,0,1,1,1
136582,3551,1,0,0,0,name,alias,PD81001,In Production,1,1,1,0,0,1,1,1

from jsonexport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.