1

I once again need to do something that sounds simple but is infact frustratingly evading me.

On my company's intranet site we have a large table of data that has a javascript filter applied to it so that managers and other interested parties can quickly locate the rows that are relevant to them. The filter I am using can be found at http://tablefilter.free.fr/ .

My issue arises when I need to have a button to export the filtered results to Excel so that the managers can access the data offline. There are many straight forward options for exporting the HTML table to excel but I have been unable to figure out how to get JUST the filtered results to export. (Note: This intranet site will only be accessed via IE)

There is a function as part of the javascript table filter, GetFilteredData(), that will grab the filtered data cells and input these into an array, i think called filteredData[]. This array is formated as such: [rowindex,[value1,value2,value3...]].

So how do I get this array into an Excel or csv file? Again, this will be accessed only by IE so activeX objects and controls are acceptable.

Also I should probably note that I cannot use server-side technologies so please limit your responses to the confines of HTML, javascript and activeX. Thanks!

Spags
  • 531
  • 5
  • 13
  • 26

3 Answers3

2

FYI: DataTables has a nice plugin called TableTools which can export table to csv on client-side. It's achieved using Flash. If you are satisfied with the filter of DataTables, I think this would be a good solution.

http://www.datatables.net/extras/tabletools/

Jeremy
  • 4,261
  • 1
  • 14
  • 23
0

If you are using IE starting at version 8, you can use data: URLs. Just generate the URL and point the borwser there using location.href. The data in CSV can be generated by javascript and base64 encoded.

marc
  • 5,855
  • 1
  • 23
  • 32
  • can you give an example of this. I tried the same approach but it seems it works only on chrome. Here is my attempt http://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side – Sam007 Mar 18 '13 at 17:01
-1

You might want to consider an approach that relies on string manipulation.

Once you have this array, you can turn it into a JSON string. Try this popular lightweight library (json2.js):

https://github.com/douglascrockford/JSON-js

Example:

text = JSON.stringify(['e', {pluribus: 'unum'}]);
// text is '["e",{"pluribus":"unum"}]'

You should have something like

var dataString = '["rowindex",["value1","value2","value3"]]'

At this point you could use some regex replacement on the string to format it to either style.

Chris Bosco
  • 1,080
  • 10
  • 16