columnDefs return url_for with parameter errors 'data' is undefined

columnDefs return url_for with parameter errors 'data' is undefined

CorbDJCorbDJ Posts: 6Questions: 2Answers: 2

I cannot seem to figure out what it is I'm doing wrong here. I'm not able to pass 'data' as a parameter in the url_for. If I directly assign a value to 'data' it works but it won't pull from the function. I'm assuming that I am making a formatting mistake but I honestly don't know.

    $(document).ready(function() {
            $('#table_data').DataTable(
                {order: [[1, 'DESC']],
                "columnDefs": [ {"targets": 0,
                    "data": "download_link",
                    "render": function ( data, type, row, meta ) {
                    return '<a src="{{ url_for('confirmation_page', data='+data+' ) }}">'+data+'</a>';}
                } ] } );
        });

This question has an accepted answers - jump to answer

Answers

  • CorbDJCorbDJ Posts: 6Questions: 2Answers: 2
    Answer ✓

    This is one way to resolve the issue:

    <script>
    
    $(document).ready(function() {
    $('#table_data').dataTable({
        "order": [[1, "desc"]],
        "columnDefs": [{
            "targets": 0,
            "data": "download_link",
            "render": function (data, type, row, meta) {
                let url = "{{ url_for('confirmation_page', data='DATA') }}".replace('DATA', data);
                return '<a href="' + url + '">'+data+'</a>';
            }
        }]
    })});
    
    </script>
    
This discussion has been closed.