How to get row data in export function?
How to get row data in export function?
 altracka            
            
                Posts: 9Questions: 6Answers: 0
altracka            
            
                Posts: 9Questions: 6Answers: 0            
            I want to modify the exported value for column 1 based on the value of column 2 in the same row. How can I get the row data? Here is what I've tried, but it gets the wrong row.
  exportOptions: {
    columns: [':visible'],
    format: {
      body: function (data, row, column, node) {
        if (column==1) {
    // This gets the wrong row, presumably because it doesn't take sorting into account:
            const rowData = table.row(row).data()
            if (rowData.foo==null) {
                return ''
            }
        }
        return data
      }
    },
    modifier: {
      selected: null
    },
  },
This discussion has been closed.
            
Answers
Yes, something doesn't seem right. It seems its a loop counter not the actual
row().index()which thebuttons.exportData()state that it is. You can pass in thetdas arow-selector. Use thenodeparameter for this. Here is an example:https://live.datatables.net/wulihena/1/edit
@allan will need to look at why the
rowparameter is not the row index.Kevin
@kthorngren, the workaround seems to work for me. Thanks.
Apologies - that is a bug! I've committed a fix here.
Thanks for letting me know about that!
Allan