我正在尝试对表中的特定行排序。但我把它夹在中间。我正在模型文件中使用kyslik\columnsortable\sortable;。但没有实际效果。有这个主意吗?

class estates extends Model
{
use Sortable;

protected $fillable = [ 'Entry', 'Price' ];

protected $table="estates";

public $Sortable = ['Entry', 'Price'];
}

我的控制器;
public function sumos()
{
  $data['este'] = estates::all();
  return view('pages.sumo', $data);

  return view('pages.sumo',['este' => estates::sortable()->get()]);

}

在html中;
<table align="center">
<tr>
    <td colspan="11" id="header"><h1>物件概要<h1></td>
</tr>
    <tr>
        <th width="340px">会社名</th>
        <th width="80px">物件名</th>
        <th width="135px">所在地</th>
        <th width="135px">総戸数</th>
        <th width="80px">間取り</th>
        <th width="100px">専有面積</th>
        <th width="80px">バルコニー面積</th>
        <th width="100px">竣工年月日</th>
        <th width="100px">@sortablelink('Entry', '入居年月日')</th>
        <th width="100px">@sortablelink('Price', '価格')</th>
        <th width="100px">販売会社名</th>
    </tr>
<table>


@foreach($este as $row)
<table align="center">
    <tr>
        <td width="340px">Company Name</td>
        <td width="80px">{{ $row->Building_Names }}</td>
        <td width="135px">{{ $row->Addresses }}</td>
        <td width="135px">{{ $row->HouseHolds }}</td>
        <td width="80px">{{ $row->Rooms }}</td>
        <td width="100px">{{ $row->Balconys }}</td>
        <td width="80px">{{ $row->Extents }}</td>
        <td width="100px">{{ $row->Constrution }}</td>
        <td width="100px">{{ $row->Entry }}</td>
        <td width="100px">{{ $row->Price }}</td>
        <td width="100px">{{ $row->Company }}</td>
    </tr>
</table>
@endforeach

对如何解决(如何排序)特定数据有什么想法吗?
谢谢你

最佳答案

你应该写这个。希望这能解决你的问题

<table align="center">
    <tr>
        <td colspan="11" id="header"><h1>物件概要<h1></td>
    </tr>
        <tr>
            <th width="340px">会社名</th>
            <th width="80px">物件名</th>
            <th width="135px">所在地</th>
            <th width="135px">総戸数</th>
            <th width="80px">間取り</th>
            <th width="100px">専有面積</th>
            <th width="80px">バルコニー面積</th>
            <th width="100px">竣工年月日</th>
            <th width="100px">@sortablelink('Entry', '入居年月日')</th>
            <th width="100px">@sortablelink('Price', '価格')</th>
            <th width="100px">販売会社名</th>
        </tr>

@foreach($este as $row)
        <tr>
            <td width="340px">Company Name</td>
            <td width="80px">{{ $row->Building_Names }}</td>
            <td width="135px">{{ $row->Addresses }}</td>
            <td width="135px">{{ $row->HouseHolds }}</td>
            <td width="80px">{{ $row->Rooms }}</td>
            <td width="100px">{{ $row->Balconys }}</td>
            <td width="80px">{{ $row->Extents }}</td>
            <td width="100px">{{ $row->Constrution }}</td>
            <td width="100px">{{ $row->Entry }}</td>
            <td width="100px">{{ $row->Price }}</td>
            <td width="100px">{{ $row->Company }}</td>
        </tr>
 @endforeach
 </table>

同时在模型顶部添加use Kyslik\ColumnSortable\Sortable;
在你的控制器中修改这个
public function sumos()
{
  $este= estates::sortable(['Price' => 'desc'])->get();
  return view('pages.sumo', compact('este'));
}

关于database - 如何在Laravel HTML中对数据库中的数据进行排序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52512426/

10-11 03:26
查看更多