Search code examples
pugbootstrap-table

Add hyperlink to text in a column generated by bootstrap-table


Using Node + Jade am creating a table that will display a large list of users, so I decided to use bootstrap-table and I found a great library with many possibilities.

I'm currently using the pagination to not display as much information in the table, the table at the moment only has two columns, the first column is a checkbox to select multiple users and the second column is just the username of the users. The table looks great, but I would add a link to take me to detail the user (example: /user/:id) and I add this link to my second column.

Currently my code looks like this:

table(data-toggle='table', data-url='users.json', data-pagination='true', data-search='true', data-striped='true')
  thead
    tr
      th(data-checkbox='true')
      th(data-field='username') Username

I just want to add a hyperlink to the text that contains the username


Solution

  • In your HTML table:

    <th data-field="user_name" data-formatter="LinkFormatter">Computer</th>
    

    in your javascript:

    function LinkFormatter(value, row, index) {
      return "<a href='/userid/id:"+row.id+"'>"+value+"</a>";
    }