JqGrid: export formatted data

Purpose . To export the data displayed in the jqGrid as CSV, supporting existing formatting. Make a generic utility for use across multiple web pages using jqGrid to export data.

Thanks to the great questions posted for exporting data before, I can create csv formatted data from jqgrid and feed it to the backend to be saved as a CSV file.

Steps taken :

  • Used jqGrid('getGridParam', 'data')

    to get all data in a row
  • Used jqGrid('getGridParam', 'colNames')

    to get colnames
  • A separate section with a tab has been created - no problem.

Problem . Since I used 'data'

, the column values ​​are raw values, not formatted values.
For example, from the backend, the date comes as long - 1411674947000

, but using custom formatting in the jqgrid it renders as 2014-09-25 19:55:47

.

Likewise, there are error codes that come in as numeric values, but are formatted to display some text.
The goal is to use a formatted value like '2014-09-25 19:55:47' in the csv output instead of '1411674947000'.

+3


source to share


1 answer


Not sure exactly how the data becomes CSV - but before exporting the data, you can use a Javascript function toUTCString()

to convert timestamps to human readable strings:

var oldDate = new Date(1411674947000);
var newDate = oldDate.toUTCString();
console.log(newDate); // Thu, 25 Sep 2014 19:55:47 GMT

      



Here's a JSFiddle .

0


source







All Articles