0
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
var data = {{data|tojson}};
$(function() {
  $('#table').bootstrapTable({
    data: data
  });

});
});//]]>
</script>

</head>
<body>

<div class="container" style="padding: 10px; ">
  <br>
  <table id="table" data-toggle="true" data-show-columns="true" data-pagination="true" data-height="500">
    <thead>
      <tr>
        <th data-field="name" data-sortable="true">Repo</th>
        <th data-field="commits" data-sortable="true" >commits</th>
        <th data-field="attention" data-sortable="true">attention</th>
        <th data-field="uneven" data-sortable="true">uneven</th>
        <th 
      </tr>
    </thead>
  </table>
</div>

This code renders json data and put it in a bootstrap table. I want to add a button in each row so that when it is clicked I can send the user to a new page.

How do I do this?

Alireza
  • 83,698
  • 19
  • 241
  • 152
  • You could add a new column with your JSON that gives some data as to where you want it to redirect. Then loop through the data for that column and transform those cells in to buttons by overwriting the data that's already there. Use this link to see how to iterate over a table. https://stackoverflow.com/questions/3065342/how-do-i-iterate-through-table-rows-and-cells-in-javascript – Difster Jul 09 '17 at 03:44
  • There are a lot of ways one could do this. First a few questions. Does your button rely on other data in that row? Like does the button need to know the name of the repo for that row for it's link, etc? If so, explain what it needs. Are you able to modify the json at all? What exact library is `bootstrapTable` coming from, (it likely has a feature for this)? – Wesley Smith Jul 09 '17 at 04:30
  • Hi thanks! I am using flask and returning json from my database. All I need to do is make a "View button" which once clicked generates to a new page and fetch data from the database providing the id which is mentioned in the already given table. – mitaanshu agarwal Jul 09 '17 at 09:19
  • I think you need this: https://stackoverflow.com/questions/46516001/bootstrap-table-dynamic-button-in-row – nliu71 May 15 '18 at 19:48

0 Answers0