convert row data (including hidden columns) to html

convert row data (including hidden columns) to html

datahandlerdatahandler Posts: 26Questions: 2Answers: 1

Title pretty much says it:

Does the DataTables api expose a method for converting row data (including hidden column data) to html?

e.g. row.data().toHtml()

Replies

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @datahandler ,

    If you use row().node(), then it will show the original HTML for that row.

    Cheers,

    Colin

  • datahandlerdatahandler Posts: 26Questions: 2Answers: 1

    Hi @colin,

    Thanks for replying. Forgive if I'm wrong, but row().node() does not include html for hidden columns. I need a way to convert all row data to html. I can do this myself ( in a hacky way) but wondered if DataTables offered a better option?

    Cheers,
    Nick

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Ah, sorry, Nick, somehow I missed your bit in parenthesis. You're right, row().node() only shows what's currently displayed on the page. There isn't a way to get the HTML of all that data, I'm afraid. Out of interest, what would you use it for (asking in case there's another way to achieve it)?

    Cheers,

    Colin

  • datahandlerdatahandler Posts: 26Questions: 2Answers: 1
    edited August 2018

    TL;DR What I’m already doing works, I just wondered if DT had a better function built in.

    I’ve created a forecasting web app with real-time updates. To minimise screen space, the user can select which quarter of the year to view (defaults to the current quarter on first load) hence some data is hidden. When any user updates a forecast value (via an input within a cell), all other users are notified of the change. If the notification is for a quarter not currently displayed, I still need to retrieve the row data and update it with the new value. This works fine except my algorithm for matching the correct input to update seems like a hack, to me. I was hoping there might be a function to convert row data (including hidden values) to HTML to make it easier to search and update.

    Cheers,
    Nick

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi Nick,

    Thanks for that. I can't think of any tidy way of doing it, so suspect whatever is working now is probably as good as it gets! :)

    Cheers,

    Colin

  • datahandlerdatahandler Posts: 26Questions: 2Answers: 1

    In case this is of use to anyone, if you know the row and column index for a hidden cell, then calling cell(rowIndex, colIndex).node() does return the td element.

This discussion has been closed.