rainabba / jquery-table2excel

jQuery Plugin to export HTML tabled to Excel Spreadsheet Compatible Files
595 stars 663 forks source link

Exlude Column? #9

Open Jevuska opened 9 years ago

Jevuska commented 9 years ago

Hello rainabba, It's great simple plugin. But is there any option to exclude a column base on 'colgroup' or 'th' ?

ferman2147 commented 9 years ago

Any tr tag you add class=".noExl" will be excluded. I haven't tried it for th though, why don't you try and see if it works?

rainabba commented 9 years ago

col and col group were deprecated in HTML 4.01 and the reality is there aren't "columns" in an html table which makes manipulating them very tricky.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup

As ferman2147 suggested, the plugin already supports row exclusion using the .noExl class. It wouldn't be hard to add individual cell exclusion and then it would be up to you to ensure all the cells in a "column" were marked and then you could implicitly exclude them.

TODO: Add individual cell exclusion using .noExl

Jevuska commented 9 years ago

ya @ferman2147 , i've try before but no luck, and @rainabba I add individual cell exclusion using .noExl in the same column not work too, so I create another code outside like this one to remove a column.

$('table').delegate('td,th', 'click', function() {
 var index = this.cellIndex;
  $(this).closest('table').find('tr').each(function() {
   this.removeChild(this.cells[ index ]);
  });
 });

any suggestion how to include in this plugin?

ferman2147 commented 9 years ago

What you need to do is pretty simple. Here is a screenshot for you. Note that you should give the id attribute to your table like < table id="myTable". (Looking at the the screenshot I realised that I forgot to do so.;) ) adsiz

nshah31 commented 9 years ago

To remove columns i am using this

$(o).find("tr").not(e.settings.exclude).each(function (i, o) { var cloneRow = $(o).clone(); $(cloneRow).find(e.settings.exclude).remove(); var html = $(cloneRow).html(); tempRows += "<tr>" + html + "</tr>"; });

jaydeepgiri commented 9 years ago

Thanks https://github.com/nshah31 (nshah31)..

Above Solution works perfectly when we comment the following code and add above code in jquery.table2excel.js -->>

// $(o).find("tr").not(e.settings.exclude).each(function (i,o) {
    // tempRows += "<tr>" + $(o).html() + "</tr>";
// });

Thank you once again

Kalemstorm94 commented 7 years ago

Can you explain me please what have you done? I've added nshah31's code and i've commented the one you mentioned, but when i try to add the noExl class to a or element, it's still not working...

jaydeepgiri commented 7 years ago

@Kalemstorm94 on line #54 or near by you would find following code

$(o).find("tr").not(e.settings.exclude).each(function (i,o) {
     tempRows += "<tr>" + $(o).html() + "</tr>";
}); //comment this code

and just after this add this following code

//To Exclude the columns
$(o).find("tr").not(e.settings.exclude).each(function (i, o) { var cloneRow = $(o).clone(); $(cloneRow).find(e.settings.exclude).remove(); var html = $(cloneRow).html(); tempRows += "<tr>" + html + "</tr>"; });
e.tableRows.push(tempRows);

That's it it will work fine. Hope this helps