2

I am trying sort specific row in the table. But i stuck middle of it. I m using Kyslik\ColumnSortable\Sortable; in the model file. But no actual effect. Any idea for this?

class estates extends Model
{
use Sortable;

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

protected $table="estates";

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

My Controller;

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

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

}

and in 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

Any idea for how to solve(how to sort) specific data? Thank you

4 Answers 4

1

You should write this. Hopefully this will solve your problem

<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>

Also add use Kyslik\ColumnSortable\Sortable; at the top of our model

In your controller modify this

public function sumos()
{
  $este= estates::sortable(['Price' => 'desc'])->get();
  return view('pages.sumo', compact('este'));
}
Sign up to request clarification or add additional context in comments.

9 Comments

@KubilayTurgut I have updated my answer. Plz check this
I can click the price th but no effects under the row. also url changing when I click the th like this Price&direction=desc
Plz write the full url after clicking the price th
http://localhost/sumo?sort=Price&direction=asc when I clicked it changes "desc" or "asc"
I have updated my answer. I am currently merging your two table into one. Plz take a look.
|
1

One of the easiest solutions is to use datatables

2 Comments

I want to agree with this one, but it only works until a certain point. When sorting with datatables, you'll need all rows, so backend pagination would mess it up.
You can find everything in the documentation. You can use ajax uploading and redo the controller with the received request.
1

use laravel built in method for sorting by using two ways to do..

by query and by collection

try this one

estates::orderBy('Entry')->orderBy('Price')->get()

1 Comment

no effect, I changed <th width="100px">@sortablelink('価格')</th> like this. do i need to change in for each column too? Also I update my controller up inside the question
1

I took a quick look at the documentation of the package you're using.

https://github.com/Kyslik/column-sortable

You have to add @sortablelink('field', 'Field') to the table headers.

Also, looking at the controller method, your sorting will never be reached.

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

Hope this helps

3 Comments

no effects, just clicking the th and nothing changes
<tr><th>@sortablelink('Price', 'Price')</td></tr>
yep, done that but nothing changes.I just can click the th only. Update the codes up in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.