Flask : redirect clickable link in datatable row to another page using Flask and Jinja Framework

Flask : redirect clickable link in datatable row to another page using Flask and Jinja Framework

galaxysailorgalaxysailor Posts: 2Questions: 1Answers: 0
edited September 2 in DataTables

The html code renders a table with two columns that its rows are clickable , my current problem is hot to set a destination new page to these links .
so take for example col1 = rows of differ nets names
how do I let these links direct me to a dynamic page for each name !
my confusion is how to handle the js script down there to talk to my flask app.route()
this is the page flask route I have created for it

FLASK;

app.route("/<member>")
def profile(member):
      return render_template('member.html' )

HTML:

<table id="member_table" class=" table responsive table-secondary table-bordered table-hover " style="width: 100%" >

        <thead>
          <tr>
            {% for item in columns %}
            <th> {{ item }}</th>
            {% endfor %}
          </tr>
        </thead>
        <tbody>

          {% for row in rows %}
          <tr class="table-active">
            {% for cell in row %}
            <td style="word-wrap: break-word"> {{ cell }}</td>
            {% endfor %}
          </tr>
          {% endfor %}
        </tbody>

      </table>


    </div>


  </section>
<script type="text/javascript">
  $('#member_table').DataTable({
    dom: 'Blfrtip',
    buttons: [
      'copy','csv','excel','print','pdf','colvis'
    ],

        "bDestroy": true,

       "columnDefs": [
          {
             targets: [0,6],
             render : function(data, type, row, meta){
                if(type === 'display'){
                   return $('<a>')
                      .attr('href', data)
                      .text(data)
                      .wrap('<div></div>')
                      .parent()
                      .html();

                } else {
                   return data;
                }
             }
          }
       ]
    });
    </script>

Answers

  • allanallan Posts: 54,680Questions: 1Answers: 8,552 Site admin

    I'm afraid we haven't used Flask here at SpryMedia, so we can't really help with that aspect. You'd be better asking on SO or a Flask specific community for help with Flask. If you had the data you need to render into the link, I can help with that, but how to get the link and then handle it in Flask - I've no idea I'm afraid!

    Allan

Sign In or Register to comment.