【发布时间】:2017-08-19 07:38:42
【问题描述】:
我目前有以下:
<table class="table table-striped">
<tr>
<th> Artikelbild </th>
<th> Artikelnummer </th>
<th> Name des Artikels </th>
<th> Beschreibung </th>
<th> Preis </th>
<th> Kategorie </th>
</tr> @foreach($products as $product)
<tr class='clickable-row' <?php if($product->stockCount === 0) echo "style='color:red;'";?>data-href="{{url('/product')}}
<?php echo '/'.$product->id;?>">
<td> <img src="/images/{{$product->imageUrl}}" class="productImageSmall" /> </td>
<td> {{$product->id}} </td>
<td> {{$product->name}} </td>
<td>
<?php if (strlen($product->description) > 30) { $productShortened = substr($product->description, 0, 30) . "[...]"; } else { $productShortened = $product->description; } echo $productShortened; ?> </td>
<td>
<?php echo number_format($product->price, 2, ',', '.');?>€ </td>
<td> {{$product->categoryName}} </td>
</tr> @endforeach
</table>
$product 是从我的控制器使用 paginate() 选项传递的。
现在我希望这张表可以按一列排序。假设用户点击表格顶部的“价格”(或德语中的 Preis)列,然后所有结果都应按价格排序(从低到高或从高到低),类别相同, 用于名称和其他所有列。
我该怎么做?我是否必须重新加载页面并再次从数据库中获取数据,但以某种方式排序(如果是,如何?)。或者我可以以某种方式对其进行排序而不重新加载它吗?我该怎么做?
感谢您的帮助
【问题讨论】:
标签: javascript php jquery laravel sorting