export the same filtered data with colors

export the same filtered data with colors

54696d2054696d20 Posts: 75Questions: 18Answers: 0

In my example. I have some values that are red. I'd like to make them red on the excel export
http://live.datatables.net/fihubuzi/2/edit

As always, thanks for the help

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0

    @colin Thanks. Unfortunately, it's not the same. The example is showing logic if the row contains London. I already have the logic done and that's why cells are Red with "<span style="color: red">1234</span>". Would you have an idea to target Span?

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0
    edited December 2019

    Doesn't seem to provide the <span> to filter off of. Only the value

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited December 2019 Answer ✓

    One option is to iterate the rows using rows().every(). In the loop check the columns for the span color and set the corresponding Excel cell attribute to the format you want using one of the builtin styles. Here is a simple example processing Excel columns B and C:
    http://live.datatables.net/xehiroqo/1/edit

    @colin may have a better suggestion.

    Kevin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0
    edited December 2019

    @kthorngren Thanks! I think that might work. I'll check in the morning to see if @colin has another idea.

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    I was expecting that span to be in the exported data, so in my link, you could check for that span instead of London. But yep, Kevin's solution is a good one, so go with that :)

    Colin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0
    edited December 2019

    @colin I was hoping the same thing, but then I looked at the xml. Then it made since why it's not in the xml. Thanks again guys

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0

    @colin @kthorngren It appears we have an issue. So Customize goes through each row regardless of selection. I understand that table.rows({ order: 'applied' }).every(function (rowIdx, tableLoop, rowLoop) is only what's filtered. This is where it's causing the issue. You have a 1000 rows. You have say 500 filtered. it's going to loop through those 500 filters, 1000 x. On top of that, it doesn't return the correct data in the excel file

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0
    edited December 2019

    I misspoke. table rows are going through each row not Customize

    $('row', sheet).each(function (x) does not

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0
    edited December 2019

    Ok... Sorry for the confusion (wish I could have deleted the last two lol). I see what's going on. So if I have 1000 row in my table, but filter out 500. I'm marking all the 1000 rows, but not the right row number.

    So I'm working on using table.rows({ order: 'index', search: 'applied' }).each(function (d) at the moment because it's giving me the rows to look at

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited December 2019 Answer ✓

    Good point. You can add the selector-modifier of {search: 'applied'} to rows().every() to handle this. Here is the updated example:
    http://live.datatables.net/meducaba/1/edit

    Resulting in table.rows({order: 'applied', search: 'applied'}).every( ... ).

    Search for ed then export.

    Kevin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0

    @kthorngren Nice. I was going to post
    table.rows({ order: 'index', search: 'applied' }).each(function (rowIDs) {
    $(rowIDs).each(function (rowID) {

This discussion has been closed.