I have an application in which I have to filter data based on the item selected from the select box. Can I display data without form reload? I have included jquery.
Controller to initial page load.
public function listCampaign()
{
$list1s = List1::orderBy('id', 'desc')->get();
$this->layout->title = "Listing Campaigns";
$this->layout->main = View::make('dash')->nest('content', 'campaigns.list', compact('list1s'));
$campaigns = Campaign::orderBy('id', 'desc')->where('user_id','=',Auth::user()->id)->paginate(10);
Session::put('slist', $list1s);
View::share('campaigns', $campaigns);
}
Here I share list1s and campaigns to the view (it is working properly).
My Blade is list.blade.php
<h2 class="comment-listings">Campaign listings</h2><hr>
<script data-require="jquery@2.1.1" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<thead>
<tr>
<th>Select a List:</th>
<th>
<form method="post">
<select class="form-control input" name="list1s" id="list1s" onchange="postdata()" >
<option selected disabled>Please select one option</option>
@foreach($list1s as $list1)
<option value="{{$list1->id}}">{{$list1->name}}</option>
@endforeach
</select>
</form>
</th>
</tr>
</thead>
</table>
<table>
<thead>
<tr>
<th>Campaign title</th>
<th>Status</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<div id="campaign">
@foreach($campaigns as $campaign)
<tr>
<td>{{{$campaign->template->title}}}</td>
<td>
{{Form::open(['route'=>['campaign.update',$campaign->id]])}}
{{Form::select('status',['yes'=>'Running','no'=>'Stoped'],$campaign->running,['style'=>'margin-bottom:0','onchange'=>'submit()'])}}
{{Form::close()}}
</td>
<td>{{HTML::linkRoute('campaign.delete','Delete',$campaign->id)}} </td>
</tr>
@endforeach
</div>
</tbody>
</table>
<script>
function postdata(data) {
$.post("{{ URL::to('campaigns/get') }}", { input:data }, function(returned){
$('.campaign').html(returned);
});
}
</script>
{{$campaigns->links()}}
On select change, URL campaigns/get is invoked.
Controller for the URL is given below
public function getCampaigns()
{
$list1 = Input::get('input');
$campaigns = Campaign::where('list1_id','=', $list1)->paginate(10);
return View::make('campaigns.list', compact('campaigns'));
}
What ever we do no change in the VIEW
Am I completely wrong? Any solutions?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community