Jsgrid: Export Data and Columns

Created on 7 Jul 2015  Â·  24Comments  Â·  Source: tabalinas/jsgrid

Hello Tabinas, I am too glad with this amazing tool, It really helped me in tall my tasks but I tried to find in methods and functions the function to export data table and columns to Java Script object or json format. I made a dynamic table and if possible tell me a easy way to export. My final result will be a CSV file and I have the parser but I need separate header columns and data to put in json format.

enhancement

Most helpful comment

@OnlyBelter
easiest way to do it now, imho, is to use function JSONToCSVConvertor from http://stackoverflow.com/a/32509639
For example,

$(function () {
       $("#exporttable").click(function () {
           var data = $('#jsGrid').jsGrid('option', 'data');
           JSONToCSVConvertor(data, "Report", true);
       })
   });

It works pretty fine for me

All 24 comments

Currently, data export is not supported. Sounds like a good enhancement. Thank you!
What you can do is get the value of the option data and map items to format you wish (CSV or whatever).

Hi, I wanted to check if any progress made on this suggestion. I also wanted to be able to export the grid data to CSV but don't know really where to start apart from the fact that the values are in the data array.

No progress on the suggestion. Maybe this can help http://jsfiddle.net/terryyounghk/kpegu/?

Hi Tabalinas, may I know how to get value from the option data?

@hasanw07, what do you mean by "option data"?

Hi Tabalinas,

I want to extract all updated data from js-grid in JSON format. Is there any method/option for that?

Thanks

Best regards,
Hasan Widjaya

On 14 Sep 2016, at 5:15 AM, Artem Tabalin [email protected] wrote:

@hasanw07, what do you mean by "option data"?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Thank you for such an awesome tool!

I ran into this issue as well. I need to "export" the grid as JSON.

@hasanw07, @georgeu2000: The option data allows to read all grid items. Have you tried this one?

@tabalinas - OK, I see. Thank you.

To get header values:

$('#grid').data( 'JSGrid' ).fields[ 0 ].name

This is the first header value.

To get rows:

$('#grid').data( 'JSGrid' ).data[ 0 ]

This is the first row.

Iterate over these two arrays to create JSON.

Here's a Gist that does it. https://gist.github.com/georgeu2000/29b4d17168708208266e44ff5c197f4f

Usage: json = createJSON();
Looks for '#jsGrid'.

I'll work on adding it to JS Grid with tests.

@tabalinas - I tried to write a test, but I don't see how you are setting up the table. Can you give me an example spec that would be good to work from?

About the code: I guess it's better to read data option with an api method:

var data = $('#grid').jsGrid('option', 'data');

As for your question: I'm not sure I understand what you mean.

All that code is not necessary.

If you set up your table as <div id="jsGrid" ... then you can get the JSON with

var data = $("#jsGrid").jsGrid("option", "data");
var result = JSON.stringify(data);

Hi @tabalinas any progress on this Enhancement. Looking to export my data to excel sheet

@kishorejv: not sure the export to xlsx format will be supported.
The easiest way now is to export just reading items (code below) and then putting it all in csv:

var data = $('#grid').jsGrid('option', 'data');

jsGrid is really great, easy to use and powerful. Little pity is that we cannot export data. Could you please add this function(export data from jsGrid to .csv file) in jsGrid? It's really useful.

@OnlyBelter
easiest way to do it now, imho, is to use function JSONToCSVConvertor from http://stackoverflow.com/a/32509639
For example,

$(function () {
       $("#exporttable").click(function () {
           var data = $('#jsGrid').jsGrid('option', 'data');
           JSONToCSVConvertor(data, "Report", true);
       })
   });

It works pretty fine for me

Thank you very much @pavel1992 , I will try it.

Many thanks for such amazing tool!

Have you ever tried to render JsGrid with electron. If so, would be able to advise on how to do it or show an example?

Cheers

@adripurkayastha, no I have not. How is it different for electron?
Probably this SO issue could help http://stackoverflow.com/questions/32621988/electron-jquery-is-not-defined
If not then, please, open a separate issue so we can work on it.

Thanks! will refer to the link, and if that doesn't help, I will start a separate issue.

I am not able to retrieve the grid data using the following, any advice?
var data = $('#grid').jsGrid('option', 'data');

but it works for fields.
var data = $('#grid').jsGrid('option', 'fields');

Many thanks.

@hllau9, your code should work. Probably, grid is just empty when you are trying to get items. If you still have this problem, please open a separate issue.

Is excel export still unsupported ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

comiscienceknight picture comiscienceknight  Â·  3Comments

GlennSeymon picture GlennSeymon  Â·  5Comments

danielson317 picture danielson317  Â·  3Comments

Julian-B90 picture Julian-B90  Â·  4Comments

julmot picture julmot  Â·  3Comments