Giter Site home page Giter Site logo

table-to-json's Introduction

Table To JSON

Build Status license

jQuery plugin to serialize HTML tables into javascript objects.

Links

CDN

It is recommended to pull this tool into your project directly. But if you insist to use a CDN, here is one:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/jquery.tabletojson.min.js" integrity="sha256-H8xrCe0tZFi/C2CgxkmiGksqVaxhW0PFcUKZJZo1yNU=" crossorigin="anonymous"></script>

Features

  • Automatically finds column headings
    • Override found column headings by using data-override="overridden column name"
    • Always uses first row as column headings regardless of th and td tags
  • Override cell values column names by using data-override="new value"
  • Ignorable columns
  • Not confused by nested tables
  • Works with rowspan and colspan

Options

  • ignoreColumns
    • Array of column indexes to ignore.
    • Default: []
  • onlyColumns
    • Array of column indexes to include, all other columns are ignored. This takes presidence over ignoreColumns when provided.
    • Default: null - all columns
  • ignoreHiddenRows
    • Boolean if hidden rows should be ignored or not.
    • Default: true
  • ignoreEmptyRows
    • Boolean if empty rows should be ignored or not.
    • Default: false
  • headings
    • Array of table headings to use. When supplied, treats entire table as values including the first <tr>
    • Default: null
  • allowHTML
    • Boolean if HTML tags in table cells should be preserved
    • Default: false
  • includeRowId
    • Either a boolean or a string. If true, the the id attribute on the table's <tr> elements will be included in the JSON as rowId. To override the name rowId, supply a string of the name you would like to use.
    • Default: false
  • textDataOverride
    • String containing data-attribute which contains data which overrides the text contained within the table cell
    • Default: 'data-override'
  • textExtractor
    • alias of extractor
  • extractor
    • Function : function that is used on all tbody cells to extract text from the cells; a value in data-override will prevent this function from being called. Example:

      $('table').tableToJSON({
        extractor : function(cellIndex, $cell) {
          // get text from the span inside table cells;
          // if empty or non-existant, get the cell text
          return $cell.find('span').text() || $cell.text();
        }
      });
      $('table').tableToJSON({
        extractor : function(cellIndex, $cell) {
          return {
            name: $cell.find('span').text(),
            avatar: $cell.find('img').attr('src')
          };
        }
      });
    • Object : object containing a zero-based cell index (this does not take colspan cells into account!) of the table; a value in data-override will prevent this function from being called. Example:

      $('table').tableToJSON({
        extractor : {
          0 : function(cellIndex, $cell) {
            return $cell.find('em').text();
          },
          1 : function(cellIndex, $cell) {
            return $cell.find('span').text();
          }
        }
      });
    • Default: null

Example

<table id='example-table'>
  <thead>
    <tr>
      <th>First Name</th>
      <th>Last Name</th>
      <th data-override="Score">Points</th></tr>
  </thead>
  <tbody>
    <tr>
      <td>Jill</td>
      <td>Smith</td>
      <td data-override="disqualified">50</td></tr>
    <tr>
      <td>Eve</td>
      <td>Jackson</td>
      <td>94</td></tr>
    <tr>
      <td>John</td>
      <td>Doe</td>
      <td>80</td></tr>
    <tr>
      <td>Adam</td>
      <td>Johnson</td>
      <td>67</td></tr>
  </tbody>
</table>

<script type="text/javascript">
  // Basic Usage
  var table = $('#example-table').tableToJSON();
  // table == [{"First Name"=>"Jill", "Last Name"=>"Smith", "Score"=>"disqualified"},
  //           {"First Name"=>"Eve", "Last Name"=>"Jackson", "Score"=>"94"},
  //           {"First Name"=>"John", "Last Name"=>"Doe", "Score"=>"80"},
  //           {"First Name"=>"Adam", "Last Name"=>"Johnson", "Score"=>"67"}]

  // Ignore first column (name)
  var table = $('#example-table').tableToJSON({
        ignoreColumns: [0]
  });
  // table == [{"Last Name"=>"Smith", "Score"=>"disqualified"},
  //           {"Last Name"=>"Jackson", "Score"=>"94"},
  //           {"Last Name"=>"Doe", "Score"=>"80"},
  //           {"Last Name"=>"Johnson", "Score"=>"67"}]
</script>

Contributing

  • Install Node.js.
    • this will also the npm package manager.
  • run npm install from app root directory.
    • This installs grunt and other dependencies See package.json for a full list.
  • run npm install -g grunt-cli.
  • run grunt to run tests and create a new build in /lib.
  • Make the changes you want.
  • Make tests for the changes.
  • Submit a pull request, please submit to the develop branch.

Looking for a server-side solution?

Colin Tremblay is working on a PHP implementation at HTML-Table-To-JSON

Special Thanks

  • imamathwiz for adding allowHTML option and various other changes.
  • nenads for adding headings option.
  • Mottie for adding rowspan & colspan support. Also adding the textExtractor & dataOverride feature!
  • station384 for adding includeRowId support.
  • dayAlone for adding ignoreEmptyRows option.
  • danielapsmaior for discovering and fixing a rowspan & colspan bug.
  • koshuang for adding extractor feature!
  • noma4i added feature "Skip columns where headers are not present"
  • cn-tools for reporting AND fixing a bug when using both ignoreEmptyRows and ignoreColumns options

table-to-json's People

Contributors

baw avatar cn-tools avatar dayalone avatar imamathwiz avatar koshuang avatar lightswitch05 avatar mottie avatar noma4i avatar station384 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

table-to-json's Issues

displaying JSON-data not inline

tableToJson.js works correctly and it was very useful for my project! but i want to display JSON-data in other way.

Now it works this way (inline):

[{"Title":"nikita","Sku":"245245245","Price ($)":"455"},{"Title":"anna","Sku":"2345","Price ($)":"678"}]

How I would like it to work:

[
    {
       "Title":"nikita",
       "Sku":"245245245",
       "Price ($)":"455"
    },{
       "Title":"anna",
       "Sku":"2345",
       "Price ($)":"678"
    }
]

how to change the code for correct output?

value of select in cell

Hi,
I have a problem, how can I get the value of a select that is contained in a cell?
Thanks in advance.

table-to-json + select + input

I have a project of multiplex tables , which have select and input.
I am using table- to- json and I take all the data and select the input data does not take me as I do to take further data I need to add an id to identify the property that is the information table .

imagen

Suggestion in tabletojson plugin

It would be more effective if it include code that allows custom html control values to take as input rather than simply taking static values from table.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/30103929-suggestion-in-tabletojson-plugin?utm_campaign=plugin&utm_content=tracker%2F228299&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F228299&utm_medium=issues&utm_source=github).

[Feature suggestion] data-valuetype

Maybe it is a good idea to add something like a data-valuetype attribute to the plugin so that you can parse the field for a specific type.
Currently everything gets returned as a string and it would be awesome if we could set in the table what kind of a type a certain value is and that the json returned from the table tries to parse the value's by the supplied data-valuetype.

Unable to get values of the editable cells

This is great plugin to convert html table to json objects. It worked perfectly fine for me until now.
But I have two table cells which are editable for the user, so I have put input tag inside my td.
I am getting the values of all the table cells except two td's having input element present inside it.

Can you please help me out with this issue?

Thanks

Clone Table not working

I have a table in my view but that's all contain input inside td element. If I directly try to call tableToJSON on my table, the json it produce contain empty values..So what I am trying to do is to clone the actual table and change the input field to plain text and then call tableToJSON on that clone variable but it produces empty array.. But If I use the actual table it works but that actually make changes visually as well which I really don't want...My code looks like this:

    var tempTable = $('#schedules table').clone();
    tempTable.find('tbody tr').each(function (index, tr) {
        $(this).find('td').each(function (tdIndex, td) {
            $(this).text($(this).find('input').val());
        })
    });

    var json = tempTable.tableToJSON({
        ignoreEmptyRows: true,
        headings: ["Type", "SubType", "ProductId", "QtyMin", "QtyMax", "Pricing"]
    });

    console.log(json); //produces empty array

some problem about value of table,thanks

I put the form in the table,
when I use table-to-json,
It cannot be displayed,
like this:

<table>
    <thead>
        <tr
            <th>id</th>
            <th>text</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td><input type="text"></td>
        </tr>
</table>

Should I do something? Thanks.

To add <td id="value" in json data

Hi

Firstly , Thanks for this amazing plugin, It saved lots of time

This is not an issue. Just I need some advice. How Could I get the td values ( <td id ="value") from each row and add it in JSON data ?

Export Any table to Json

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

Issue when converting DropdownList to Json

table to json

table to json1

regards
I am trying to convert a table that within your td contains dropdownlist
At the time of the conversion those drowdown takes all the options it contains, not only the selected option, I would greatly appreciate your collaboration in the solution of this problem.

Thank you in advance for your help

<th> tags are missing

I tried parsing the table below copied from Wiktionary (https://en.wiktionary.org/wiki/by%C4%87) via the Plunker Template.
The preview looked correct but once I hit the Convert! button, the alert window displayed only [].

<table class="wikitable inflection-table" style="margin: 1em auto;">
    <tbody>
        <tr>
            <th rowspan="2"></th>
            <th> 
            </th>
            <th colspan="3"><a href="/wiki/singular" title="singular">singular</a></th>
            <th colspan="2"><a href="/wiki/plural" title="plural">plural</a></th>
        </tr>
        <tr>
            <th><a href="/wiki/grammatical_person" title="grammatical person">person</a></th>
            <th><span class="gender"><abbr title="masculine gender">m</abbr></span></th>
            <th><span class="gender"><abbr title="feminine gender">f</abbr></span></th>
            <th><span class="gender"><abbr title="neuter gender">n</abbr></span></th>
            <th><span class="gender"><abbr title="masculine gender">m</abbr> <abbr title="personal">pers</abbr></span>
            </th>
            <th>other
            </th>
        </tr>
        <tr>
            <th colspan="2"><a href="/wiki/infinitive" title="infinitive">infinitive</a></th>
            <td colspan="5"><span class="Latn" lang="pl"><strong class="selflink">być</strong></span></td>
        </tr>
        <tr>
            <th rowspan="3"><a href="/wiki/present_tense" title="present tense">present indicative</a></th>
            <th><a href="/wiki/first_person" title="first person">1st</a></th>
            <td colspan="3"><span class="Latn" lang="pl"><a href="/wiki/jestem#Polish" title="jestem">jestem</a></span>,
                <span class="Latn" lang="pl"><a href="/wiki/-m#Polish" title="-m">-m</a></span></td>
            <td colspan="2"><span class="Latn" lang="pl"><a href="/wiki/jeste%C5%9Bmy#Polish"
                        title="jesteśmy">jesteśmy</a></span>, <span class="Latn" lang="pl"><a
                        href="/wiki/-%C5%9Bmy#Polish" title="-śmy">-śmy</a></span></td>
        </tr>
        <tr>
            <th><a href="/wiki/second_person" title="second person">2nd</a></th>
            <td colspan="3"><span class="Latn" lang="pl"><a href="/wiki/jeste%C5%9B#Polish"
                        title="jesteś">jesteś</a></span>, <span class="Latn" lang="pl"><a href="/wiki/-%C5%9B#Polish"
                        title="-ś">-ś</a></span></td>
            <td colspan="2"><span class="Latn" lang="pl"><a href="/wiki/jeste%C5%9Bcie#Polish"
                        title="jesteście">jesteście</a></span>, <span class="Latn" lang="pl"><a
                        href="/wiki/-%C5%9Bcie#Polish" title="-ście">-ście</a></span></td>
        </tr>
        <tr>
            <th><a href="/wiki/third_person" title="third person">3rd</a></th>
            <td colspan="3"><span class="Latn" lang="pl"><a href="/wiki/jest#Polish" title="jest">jest</a></span></td>
            <td colspan="2"><span class="Latn" lang="pl"><a href="/wiki/s%C4%85#Polish" title="są">są</a></span></td>
        </tr>
        <tr>
            <th rowspan="3"><a href="/wiki/past_tense" title="past tense">past indicative</a></th>
            <th><a href="/wiki/first_person" title="first person">1st</a></th>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82em#Polish" title="byłem">byłem</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82am#Polish" title="byłam">byłam</a></span></td>
            <td> 
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/byli%C5%9Bmy#Polish" title="byliśmy">byliśmy</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82y%C5%9Bmy#Polish" title="byłyśmy">byłyśmy</a></span>
            </td>
        </tr>
        <tr>
            <th><a href="/wiki/second_person" title="second person">2nd</a></th>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82e%C5%9B#Polish" title="byłeś">byłeś</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82a%C5%9B#Polish" title="byłaś">byłaś</a></span></td>
            <td> 
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/byli%C5%9Bcie#Polish" title="byliście">byliście</a></span>
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82y%C5%9Bcie#Polish"
                        title="byłyście">byłyście</a></span></td>
        </tr>
        <tr>
            <th><a href="/wiki/third_person" title="third person">3rd</a></th>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82#Polish" title="był">był</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82a#Polish" title="była">była</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82o#Polish" title="było">było</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/byli#Polish" title="byli">byli</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82y#Polish" title="były">były</a></span></td>
        </tr>
        <tr>
            <th rowspan="3"><a href="/wiki/future_tense" title="future tense">future tense</a></th>
            <th><a href="/wiki/first_person" title="first person">1st</a></th>
            <td colspan="3"><span class="Latn" lang="pl"><a href="/wiki/b%C4%99d%C4%99#Polish"
                        title="będę">będę</a></span></td>
            <td colspan="2"><span class="Latn" lang="pl"><a href="/wiki/b%C4%99dziemy#Polish"
                        title="będziemy">będziemy</a></span></td>
        </tr>
        <tr>
            <th><a href="/wiki/second_person" title="second person">2nd</a></th>
            <td colspan="3"><span class="Latn" lang="pl"><a href="/wiki/b%C4%99dziesz#Polish"
                        title="będziesz">będziesz</a></span></td>
            <td colspan="2"><span class="Latn" lang="pl"><a href="/wiki/b%C4%99dziecie#Polish"
                        title="będziecie">będziecie</a></span></td>
        </tr>
        <tr>
            <th><a href="/wiki/third_person" title="third person">3rd</a></th>
            <td colspan="3"><span class="Latn" lang="pl"><a href="/wiki/b%C4%99dzie#Polish"
                        title="będzie">będzie</a></span></td>
            <td colspan="2"><span class="Latn" lang="pl"><a href="/wiki/b%C4%99d%C4%85#Polish"
                        title="będą">będą</a></span></td>
        </tr>
        <tr>
            <th rowspan="3"><a href="/wiki/conditional" title="conditional">conditional</a></th>
            <th><a href="/wiki/first_person" title="first person">1st</a></th>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82bym#Polish" title="byłbym">byłbym</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82abym#Polish" title="byłabym">byłabym</a></span></td>
            <td> 
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/byliby%C5%9Bmy#Polish"
                        title="bylibyśmy">bylibyśmy</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82yby%C5%9Bmy#Polish"
                        title="byłybyśmy">byłybyśmy</a></span></td>
        </tr>
        <tr>
            <th><a href="/wiki/second_person" title="second person">2nd</a></th>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82by%C5%9B#Polish" title="byłbyś">byłbyś</a></span>
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82aby%C5%9B#Polish" title="byłabyś">byłabyś</a></span>
            </td>
            <td> 
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/byliby%C5%9Bcie#Polish"
                        title="bylibyście">bylibyście</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82yby%C5%9Bcie#Polish"
                        title="byłybyście">byłybyście</a></span></td>
        </tr>
        <tr>
            <th><a href="/wiki/third_person" title="third person">3rd</a></th>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82by#Polish" title="byłby">byłby</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82aby#Polish" title="byłaby">byłaby</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82oby#Polish" title="byłoby">byłoby</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/byliby#Polish" title="byliby">byliby</a></span></td>
            <td><span class="Latn" lang="pl"><a href="/wiki/by%C5%82yby#Polish" title="byłyby">byłyby</a></span></td>
        </tr>
        <tr>
            <th rowspan="3"><a href="/wiki/imperative" title="imperative">imperative</a></th>
            <th><a href="/wiki/first_person" title="first person">1st</a></th>
            <td colspan="3"><span class="Latn" lang="pl">niech <a href="/wiki/b%C4%99d%C4%99#Polish"
                        title="będę">będę</a></span></td>
            <td colspan="2"><span class="Latn" lang="pl"><a href="/wiki/b%C4%85d%C5%BAmy#Polish"
                        title="bądźmy">bądźmy</a></span></td>
        </tr>
        <tr>
            <th><a href="/wiki/second_person" title="second person">2nd</a></th>
            <td colspan="3"><span class="Latn" lang="pl"><a href="/wiki/b%C4%85d%C5%BA#Polish"
                        title="bądź">bądź</a></span></td>
            <td colspan="2"><span class="Latn" lang="pl"><a href="/wiki/b%C4%85d%C5%BAcie#Polish"
                        title="bądźcie">bądźcie</a></span></td>
        </tr>
        <tr>
            <th><a href="/wiki/third_person" title="third person">3rd</a></th>
            <td colspan="3"><span class="Latn" lang="pl">niech <a href="/wiki/b%C4%99dzie#Polish"
                        title="będzie">będzie</a></span></td>
            <td colspan="2"><span class="Latn" lang="pl">niech <a href="/wiki/b%C4%99d%C4%85#Polish"
                        title="będą">będą</a></span></td>
        </tr>
        <tr>
            <th colspan="2"><a href="/wiki/active" title="active">active</a> <a href="/wiki/adjectival"
                    title="adjectival">adjectival</a> <a href="/wiki/participle" title="participle">participle</a></th>
            <td><span class="Latn" lang="pl"><a href="/wiki/b%C4%99d%C4%85cy#Polish" title="będący">będący</a></span>
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/b%C4%99d%C4%85ca#Polish" title="będąca">będąca</a></span>
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/b%C4%99d%C4%85ce#Polish" title="będące">będące</a></span>
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/b%C4%99d%C4%85cy#Polish" title="będący">będący</a></span>
            </td>
            <td><span class="Latn" lang="pl"><a href="/wiki/b%C4%99d%C4%85ce#Polish" title="będące">będące</a></span>
            </td>
        </tr>
        <tr>
            <th colspan="2"><a href="/wiki/contemporary" title="contemporary">contemporary</a> <a href="/wiki/adverbial"
                    title="adverbial">adverbial</a> <a href="/wiki/participle" title="participle">participle</a></th>
            <td colspan="5"><span class="Latn" lang="pl"><a href="/wiki/b%C4%99d%C4%85c#Polish"
                        title="będąc">będąc</a></span></td>
        </tr>
        <tr>
            <th colspan="2"><a href="/wiki/anterior" title="anterior">anterior</a> <a href="/wiki/adverbial"
                    title="adverbial">adverbial</a> <a href="/wiki/participle" title="participle">participle</a></th>
            <td colspan="5"><span class="Latn" lang="pl"><a href="/wiki/bywszy#Polish" title="bywszy">bywszy</a></span>
            </td>
        </tr>
        <tr>
            <th colspan="2"><a href="/wiki/verbal_noun" title="verbal noun">verbal noun</a></th>
            <td colspan="5"><span class="Latn" lang="pl"><a href="/wiki/bycie#Polish" title="bycie">bycie</a></span>
            </td>
        </tr>
    </tbody>
</table>

Convert tables to JSON in multiple tabs

My problem has arisen when I use table-to-json lib combined with jQuery library "jQuery UI Tabs" to have multiple tabs within a single HTML file.
http://jsfiddle.net/ptVDm/171/
Add some more tabs and then, when you try to export(alert) the JSON object of each table in each tab (only the table of the selected tab is exported) , the rest of them are empty [] as you can see.

I would like to export all the JSON objects of each table in each tab.

Any advice would be appreciated.

Thank you in advance.

Values from COLSPAN duplicated

Hi, thanks for this code... finding it very useful. One thing we are running into is when using a table with colspan, the value is duplicated in the json output.

So for instance I have a table with 2 rows and 3 columns, and a COLSPAN. The values in the table would be row1: c1, c2, c3 | row2: c4, c5 (COLSPAN on columns 1 and 2 of second row).

The JSON output looks like this...

c1,c2,c3
c4,c4,c5

Any way around this?

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/27035195-values-from-colspan-duplicated?utm_campaign=plugin&utm_content=tracker%2F228299&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F228299&utm_medium=issues&utm_source=github).

Dropdown in TD not giving right value.

Hi,

I'm not able to get the proper value of dropdown that I added to one of the td.
Heres the fiddle: http://jsfiddle.net/sreedevi/qbuwd3k7/

<table id='example-table' class="table table-striped">
  <thead>
    <tr hidden>
      <th>First Name</th>
      <th>Last Name</th>
      <th data-override="Score">Points</th>
      <th>aggr</th></tr>
  </thead>
  <tbody>
    <tr>
      <td>Jill</td>
      <td>Smith</td>
      <td data-override="disqualified">50</td>
      <td><select type="text" class="gf-form-input" style="width:110px;">
                                                        <option value="avg">AVG</option>
                            <option value="count">COUNT</option></select></td></tr>
</table>

JSON output:

[{"First Name":"Jill","Last Name":"Smith","Score":"disqualified","aggr":"AVG\n COUNT"}]

Please help.

Thanks
Sree

Adding Rows, New Rows ignored

I was looking for the ability to add rows on the fly, so I wrote a simple button & related function. The elements are added, everything shows in the DOM correctly, no errors in the console. But the elements are unable to be edited as the other elements / preexisting are. I am unsure if this is user error (-- me) or if this is a bug or just feature that is lacking? Here is my code:

$(function(){
    $( ".addRow").click( function(){
        var target = this.id.substring(this.id.indexOf("_")+1);
        var table = document.getElementById("table_" + target);
        var row = table.getElementsByTagName('tbody')[0].insertRow(-1);
        var tdCount = table.firstElementChild.firstElementChild.childElementCount;
        for(i = 0; i < tdCount; i++){
            var cell = row.insertCell(i);
            var newText = document.createTextNode("testText");
            cell.appendChild(newText);
        }
    })
})  

<button class="button addRow" id="addrow_tablename">Add Row</button>

Thanks for the work, it is much appreciated! Great project.

How to return JSON array instead of text for specific column

I want to return a JSON array from an extractor like this:

`

10 : function(cellIndex , $cell){
                    var prlArray = [];
                    $cell.find('select option').each(function(){
                        //alert(this.value);
                        prlArray.push(this.value);
                    });
                    return JSON.parse(prlArray.toString());
                }

`

This extractor is causing error in because of "return JSON.parse(prlArray.toString());"
thanks in advance

Can we have a little more explanation?

I've been using this plugin so far and I'm a software engineer at a company. I would like to use this and I can as is but I'm trying to enable the feature to allowHTML. All I see as an explanation is that these are options but if I've never used plugins before and this is me learning... How do I know what that means?

You guys/girls have some great examples. I only wish and perhaps I recommend that there be one showing the options in use so that someone like me can easily learn and see. Maybe someone can give me a hint here so I can continue testing this plugin out and seeing how I'm going to use it?

Thanks for the plugin and I appreciate the work you all have done.

Ignore the first row/th

I have my table header that's being added as the first row of the string.
I was hoping there could be a feature to ignore the first row/header from the text

var table = $('#DataTab').tableToJSON({
                ignoreColumns:[5],
                headings: ['campus','building','room_num','capacity','room_type']
            });

Without jQuery and types

Hi,

First of all many thanks for the excellent work of the plugin.

I know this project is a jQuery plugin, but:

  • Is it possible to make a version that doesn't have jQuery as a dependency?
  • Other suggestion is if you could publish this project with types? I'm migrating a project from AngularJS to Angular and hopefully it was possible for the project to export the types to be used in this type of project with Typescript.

Thanks!

Adding additional data

Hey there!

This is a very handy jQuery plugin. I wonder how could I add additional data that is not a column of the table.

For instance, there I have a column with an image where I use extractor to get the image src. In addition to the image src, I would like to add the image width and height to the generated JSON. How would I do that?

Thanks

Typecast certain columns

I am having problem typecasting my table's one column to a integer type as everything is being read a string

Extract values by column

Currently, tabletojson follows the row-oriented approach of HTML ; what's the easiest path if one wants to convert a table column by columb first, by keeping the behaviour of the plugin intact (auto extraction of hash dicts from first row/col etc.) ?

Can it be done by preprocessing or post-processing the data ? Or does it require a heavy evolution of the plugin (I don't easily see, with the current code, how much work it asks for) ?

Is it possible to extract all tables in HTML string?

I am used to the node.js "table-as-JSON" package, it lets me extract all tables that are in HTML string. This is very useful for parsing, and tables that have no ids. Is this functionality part of the table to json package?

example:

// Convert an HTML blob into an array of all the tables on the page
var tabletojson = require('tabletojson');
var tablesAsJson = tabletojson.convert(html);
var firstTableAsJson = tablesAsJson[0];
var secondTableAsJson = tablesAsJson[1];

link: https://www.npmjs.com/package/tableasjson

how to install package and which files do I need?

Hello,

I want to use this package with c# asp.net and jQuery. How do I get this package working? Is it something like the cdn link and which files do I need to get it working?

Thank you in advance.

Greetings,
Mouaad

Prefilter callback on property name

One issue I have come across is when a table header has an odd name
example
'Col 1 / ID'

this is valid it would render as
{'Col 1 / ID': 'someValue'}

but parsing it is where it becomes an issue. It can be used in JavaScript by calling it as
var col1 = parsedJson['Col 1 / ID'];
but you can't call it as
var col1 parsedJson.Col 1 / ID;

This issue is even more pronounced in other languages, C#, Java, Tcl.

The person could filter the JSON text and clean the property names, but that would be a lot of logic that would have to be implemented, or done in a regex that is beyond me.

What I propose is adding a new option. if the option is null or undefined, the current behavior continues. But if there is a function object, we call that function and pass in the string that is going to be set as the property, the return value from the function is what we use as the property.

something like this.

tableToJSON(
{ 
   callbackFunction : function (data) { return data.replace('/','').replace(' ','_' ); }
});

This gives the option to the end user to filter text, process it, map it if they want.

I can implement it.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/4712466-prefilter-callback-on-property-name?utm_campaign=plugin&utm_content=tracker%2F228299&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F228299&utm_medium=issues&utm_source=github).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.