Regex for processing headers for export sometimes not working as expected

Regex for processing headers for export sometimes not working as expected

TraderToolsTraderTools Posts: 6Questions: 2Answers: 0

Hi,
You have in your code regex that cleans up headers for export purposes.

var _exportData = function ( dt, inOpts )
...
var strip = function ( str )
...
if ( config.stripHtml ) {
    str = str.replace( /<[^>]*>/g, '' );
}

In one case it does not work well:
Input:
Active<div id="yadcf-filter-wrapper--data_table-11" class="yadcf-filter-wrapper" style="display: none;"><select id="yadcf-filter--data_table-11" class="yadcf-filter form-control" onchange="yadcf.doFilter(this, '-data_table', 11, 'contains');" onkeydown="yadcf.preventDefaultForEnter(event);" onmousedown="yadcf.stopPropagation(event);" onclick="yadcf.stopPropagation(event);"><option value="-1">Select value</option><option value="false">false</option><option value="true">true</option></select><button type="button" id="yadcf-filter--data_table-11-reset" onmousedown="yadcf.stopPropagation(event);" onclick="yadcf.stopPropagation(event);yadcf.doFilter('clear', '-data_table', 11); return false;" class="yadcf-filter-reset-button form-control"></button></div>

Output:

ActiveSelect valuefalsetrue

I would like to have only 'Active'

Thanks.

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    You have in your code....

    In what code?

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Unfortunately yes, this is a bit of a limitation in the export and simple stripping of HTML that Buttons does. As you will see it just removes the tags, leaving the tag from the option tags.

    I presume that is in the footer? If so, you would need to use the format.footer option in Buttons' export data (buttons.exportData()) to get just the text. Something like:

            exportOptions: {
                format: {
                    footer: function ( text, index, node) {
                        return $(node).text();
                    }
                }
            }
    

    Regards,
    Allan

  • TraderToolsTraderTools Posts: 6Questions: 2Answers: 0

    Thanks.
    In my case it was header, also $(node).text(); gave me the same wrong result including the text of the inner nodes, but you pointed me to the right direction. Correct answer would be:

    exportOptions: { 
        format: {
            header: function ( text, index, node) {
                return $(node).clone().children().remove().end().text();
            }
        }
    }
    
This discussion has been closed.