Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export with input Number #45

Closed
Gektor0508 opened this issue Oct 30, 2015 · 2 comments
Closed

Export with input Number #45

Gektor0508 opened this issue Oct 30, 2015 · 2 comments
Labels

Comments

@Gektor0508
Copy link

I have an input type=number in my table and this plugin don't export the value. Is it possible to do this?

@hhurz
Copy link
Owner

hhurz commented Oct 30, 2015

Use the onCellHtmlData option for doing this. Here is an example: https://jsfiddle.net/9kfvge22/2
To export this table:

<table>
  <thead>
  <tr>
    <th>C1</th>
    <th>C2</th>
    <th>C3</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td><input type="number" id="r1c0"></td>
    <td>B</td>
    <td>C</td>
  </tr>
  <tr>
    <td>D</td>
    <td>E</td>
    <td>F</td>
  </tr>
  </tbody>
</table>

use the folowing tableExport options:

function DoOnCellHtmlData(cell, row, col, data) {
  var result = "";
  if (data != "") {
    var html = $.parseHTML( data )

    $.each( html, function() {
      if ( typeof $(this).html() === 'undefined' )
        result += $(this).text();
      else if ( $(this).is("input") )
        result += $('#'+$(this).attr('id')).val();
      else
        result += $(this).html();
    });
  }
  return result;
}

$('table').tableExport({
  type: 'txt',
  onCellHtmlData: DoOnCellHtmlData}
);

In case you changed the input value to 5, the result would be:

C1,C2,C3
5,B,C
D,E,F

Note: The onCellHtmlData function depends on the content of the table you want to export. The DoOnCellHtmlData function shown above is just an example that meets the requirements of your question.

hhurz pushed a commit that referenced this issue Oct 30, 2015
@Gektor0508
Copy link
Author

Thanks a lot for the fast response. Everything you described worked fine for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants