Use data attribute for export possible?

Use data attribute for export possible?

kevlin79kevlin79 Posts: 3Questions: 1Answers: 0

Hi! Gave gone through the different ways to change the format of the data in a table before exporting to for instance excel. I apply datable to a generated table and use the data-order and data-search for ordering/searching. Is there a way to use the data-search data as exported data instead of the data <td> tag?

Thanks Kevin

This question has an accepted answers - jump to answer

Answers

  • kevlin79kevlin79 Posts: 3Questions: 1Answers: 0

    Found an old thread and built the code below. However can't get it to work, any ideas? It is called correctly by the buttons

        var buttonCommonFormatcol34 = {
            exportOptions: {
                format: {
                    body: function ( data, row, column, node ) {
                        var sel = "#" + row + column; 
                        if( typeof $(sel).data('search') !== 'undefined'){ 
                            data = $(sel).data('search'); 
                        }                   
                        return data;
                    }                
                }
            }
        }
    

    When I change skip the if and always set data as "data = $(sel).data('search');" the excel is empty ... is the var sel correctly built?

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓
                {
                    extend: 'copyHtml5',
                    exportOptions: { orthogonal: 'search' }
                },
    

    will use the search data for all columns - which might or might not be what you want.

    Or if you want more control, using a formatting function:

    var buttonCommonFormatcol34 = {
        exportOptions: {
            format: {
                body: function ( data, row, column, node ) {
                    if( typeof $(node).data('search') !== 'undefined'){
                        data = $(node).data('search');
                    }                  
                    return data;
                }               
            }
        }
    }
    

    Allan

  • kevlin79kevlin79 Posts: 3Questions: 1Answers: 0

    Aa wonderful, thanks!

This discussion has been closed.