向数据表添加功能?
Add feature to datatable?
嘿伙计们,我只是在玩弄数据表,我想知道是否有人知道可以执行以下操作的新方法:
当您有描述的 TD 时,如果描述很长,有没有办法添加阅读更多内容 link 或 ... 而不是扭曲行高?
您在这方面的任何资源都会有用!
这是我当前的设置:
require_once('db_config.php');
$sql = "SELECT * FROM routes";
$stmt = $conn->prepare($sql);
$stmt->execute();
echo '<table class="table table-striped table-bordered" id="basic-datatable" border="0" cellpadding="10">';
echo '<thead><tr><th>Business ID</th><th>Business Type</th><th>Price</th><th>Down Payment</th><th>Weekly Net</th><th>City</th><th>State</th><th>Business Description</th></tr></thead>';
echo '<tbody>';
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo "<tr>";
echo '<td>' . $row['route_id'] . '</td>';
echo '<td><a href="detail.php?id=' . $row['id'] . '">' . $row['route_title'] . '</a></td>';
echo '<td>$' . $row['total_price'] . '</td>';
echo '<td>$' . $row['down_payment'] . '</td>';
echo '<td>$' . $row['weekly_net'] . '</td>';
echo '<td>' . $row['city'] . '</td>';
echo '<td>' . $row['state'] . '</td>';
echo '<td>' . $row['remarks'] . '</td>';
echo "</tr>";
}
echo '</tbody>';
echo '</table>';
谢谢
有两种方法可以解决这种行为。
一个是 CSS 使用 text-overflow: ellipsis;
,尽管它只处理省略号部分。 (既然你想要的不止这些,我就不在这里细说了,但是here are the MDN docs for that,如果你有兴趣的话。)
PHP 中的方法是确定有多少字符适合您的 table 单元格,包括 "Read More," 并相应地截断字符串。
因此,如果 $row['remarks']
是您要处理的字段,您可以这样做:
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
if(strlen($row['remarks']) >= 50) {
$row['remarks'] = substr($row['remarks'],50) . "... <a href="foo">Read More</a>";
}
echo '<tr>'...
}
嘿伙计们,我只是在玩弄数据表,我想知道是否有人知道可以执行以下操作的新方法:
当您有描述的 TD 时,如果描述很长,有没有办法添加阅读更多内容 link 或 ... 而不是扭曲行高?
您在这方面的任何资源都会有用!
这是我当前的设置:
require_once('db_config.php');
$sql = "SELECT * FROM routes";
$stmt = $conn->prepare($sql);
$stmt->execute();
echo '<table class="table table-striped table-bordered" id="basic-datatable" border="0" cellpadding="10">';
echo '<thead><tr><th>Business ID</th><th>Business Type</th><th>Price</th><th>Down Payment</th><th>Weekly Net</th><th>City</th><th>State</th><th>Business Description</th></tr></thead>';
echo '<tbody>';
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo "<tr>";
echo '<td>' . $row['route_id'] . '</td>';
echo '<td><a href="detail.php?id=' . $row['id'] . '">' . $row['route_title'] . '</a></td>';
echo '<td>$' . $row['total_price'] . '</td>';
echo '<td>$' . $row['down_payment'] . '</td>';
echo '<td>$' . $row['weekly_net'] . '</td>';
echo '<td>' . $row['city'] . '</td>';
echo '<td>' . $row['state'] . '</td>';
echo '<td>' . $row['remarks'] . '</td>';
echo "</tr>";
}
echo '</tbody>';
echo '</table>';
谢谢
有两种方法可以解决这种行为。
一个是 CSS 使用 text-overflow: ellipsis;
,尽管它只处理省略号部分。 (既然你想要的不止这些,我就不在这里细说了,但是here are the MDN docs for that,如果你有兴趣的话。)
PHP 中的方法是确定有多少字符适合您的 table 单元格,包括 "Read More," 并相应地截断字符串。
因此,如果 $row['remarks']
是您要处理的字段,您可以这样做:
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
if(strlen($row['remarks']) >= 50) {
$row['remarks'] = substr($row['remarks'],50) . "... <a href="foo">Read More</a>";
}
echo '<tr>'...
}