lightswitch05 / table-to-json

Serializes HTML tables into JSON objects.
http://lightswitch05.github.io/table-to-json/
MIT License
756 stars 172 forks source link

Export Any table to Json #30

Closed alexander26k closed 7 years ago

alexander26k commented 8 years ago

Hello. I have any table on page. Calling a function like this: var table = $('.report').tableToJSON(); but there are some problems. The script reads the header only the first table, and on it already puts the data. How to make that code takes into account the headers of each table? thanks in advance

lightswitch05 commented 8 years ago

I am not able to help without knowing what the HTML of the table looks like. Please share an example, it would be even more helpful if you put it on Plunker: http://plnkr.co/edit/iQFtcEEZkvsMJ2UqcrlW?p=preview

alexander26k commented 8 years ago

I create an example. Please see http://plnkr.co/edit/5SU9isbYSnlq5N4okEwz?p=preview

lightswitch05 commented 8 years ago

tableToJson only works with a single table, you cannot use it on multiple tables by making a generalized selector.

If you want table toJson to work on all the tables, you have to call it on each table and join the results:

        var entireTable = [];
        var table1 = $('#tReports1').tableToJSON();
        var table2 = $('#tReports2').tableToJSON();
        var table3 = $('#tReports3').tableToJSON();
        entireTable = entireTable.concat(table1);
        entireTable = entireTable.concat(table2);
        entireTable = entireTable.concat(table3);

http://plnkr.co/edit/OaV0MHEBqZRxcmc3WogC?p=preview