jquery-tabledit icon indicating copy to clipboard operation
jquery-tabledit copied to clipboard

Url in Table, connected to Database

Open Domods opened this issue 7 years ago • 4 comments

I am trying to make a clickable link in a Tabledit cell, but cannot get it to work. It seems to be sanitized or something.

The code works in a standard formatted table, but not with Tabledit.

How can I make this work?

Simple version: <td><a>Cell text</a></td>

In my Code:

$stmt = $dbh->prepare("SELECT * FROM `Table` ORDER BY `Name` ASC");
if($stmt->execute())
{
  echo '<table id="example" class="table table-striped table-bordered" width="100%" cellspacing="0">
    <thead><tr>
      <th style="display:none;">ID</th>
      <th>Name</th>
      <th>Link</th>
      <th>Email</th>
    </tr></thead><tbody>
  ';
  while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
  {
    echo '<tr><td style="display:none;">'.$row['ID'].'</td>';
    echo '<td>'.$row['Name'].'</td>';
    echo '<td><a href="?key='.$_GET['key'].'&link='.$row['Link'].'">'.$row['Link'].'</a></td>';
    echo '<td>'.$row['Email'].'</td></tr>';
  }
}
echo '
</tbody>
<script>
  $("#example").Tabledit({
    url: "test.php",
    columns: {
      identifier: [0, "ID"],
      editable: [[1, "Name"],[2, "Link"],[3, "Email"]]
    },
    buttons: {
      edit: {
          class: "btn btn-sm btn-success"
      },
      delete: {
        class: "btn btn-sm btn-danger"
      }
    }
  });
</script>
';

Domods avatar Jul 21 '17 13:07 Domods

@Domods , Did u find any solution to this?

iampapagray avatar Apr 15 '18 18:04 iampapagray

@iampapagray not yet unfortunately

Domods avatar Apr 28 '18 08:04 Domods

You can set the url in plain text and add a class on the td element echo '<td><a href="?key='.$_GET['key'].'&link='.$row['Link'].'">'.$row['Link'].'</a></td>'; becomes echo '<td class="linkurl">'.$row['Link'].'</td>'; then using an event handler (onDraw), you can dynamicaly wrap each td's content with an <a> element with the href that you want $('.linkurl').each(function(){ var value = $(this).text(); $(this).html('<a href="?key='+urlParam+'&link='+value+'">' + value + '</a>'); });

To grab the url parameter (urlParam) with javascript you can use this method

var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } };

and use it as var urlParam= getUrlParameter('key');

I hope this works if anybody needs it :)

mikapa21 avatar Mar 06 '19 17:03 mikapa21

@mikapa21 can you please explain it more clearly ...I'm a newbie and tried your suggestion but it didn't work ...maybe i didn't apply it well

steverosky avatar Sep 12 '21 03:09 steverosky