Search code examples
angularjsangular-ui-gridpdfmake

Format a date on Pdfmake


I have used pdfmake library to export pdf content with the Angular UI Grid.Could you tell me how to format the date on it ? Thanks.

Currently it shows like this :

enter image description here

Angular grid it's like this :

enter image description here

 {
   name: app.localize('BrDateReceived'),
   field: 'bpoHeaderPerformedFors[0].dateReceived',
   cellFilter: 'date:\'MM/dd/yyyy\'',
   width: 140,
 },

Solution

  • Good discussion : cellFilter does not work with the Pdfmake

    UPDATE

    I discovered that UI-grid has a function in gridoptions that allows you to call back on each cell. Using angular-moment and the gridoptions.exporterFieldCallback I was able to change each cell in the PDF. Look at lines 43 to 47 in the app.js file in this plnkr.

    Also, note that I updated the link below to use angular-moment with the correct repo on github. The one I used earlier was not the one I would recommend.

    Good luck!

    Original Answer

    I suggest importing angular-moment into your app, and then using it in your document definition. I have done this successfully before. Like this:

    {text: 'DATE: ' + moment(bpoHeaderPerformedFors[0].dateReceived).format("MM-DD-YYYY")}
    

    View more about angular-moment or full docs of momentjs (which the angular version is based).

    Good luck!