Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter not working #974

Closed
vipin733 opened this issue Feb 4, 2017 · 3 comments
Closed

Filter not working #974

vipin733 opened this issue Feb 4, 2017 · 3 comments
Labels

Comments

@vipin733
Copy link

vipin733 commented Feb 4, 2017

  public function getincome_ajax(Request $request)
		{
			$starts = $request->start;
			$ende = $request->end;
			$course = $request->course;

				$start = date('Y-d-m', strtotime($starts));
				$end = date('Y-d-m', strtotime($ende));


			if (($starts) && ($ende) && ($course))
			 {
                             //here is problem when i want search with $starts and $end its not working
				$query = Subscription::whereDate('created_at','>=',$start)
												->whereDate('created_at','<=',$end)
												->where('course_id',$course)
												->with('courses');
	    	}
			 elseif(($starts) && ($ende))
			 {
                                  //here is problem when i want search with $starts and $end its not working
				$query = Subscription::whereDate('created_at','>=',$start)
												->whereDate('created_at','<=',$end)
												->with('courses');

		 }

			 elseif($course)
			 {
                                    //here if I search with only $course its working fine
				$query = Subscription::where('course_id',$course)->with('courses');
																	
			 }

			else
			{
						 $query = Subscription::with('courses');
			}

			$dataTable = Datatables::of($query)
      ->addColumn('total', function ($s) {
                 return $s->tution_fee + $s->development_fee + $s->late_fee + $s->other_fee ;
               })
							 ->editColumn('created_at', function ($user) {
							 return $user->created_at->format('d/m/Y');
					 });
       $columns = ['created_at', 'tution_fee', 'development_fee','late_fee', 'other_fee','total','courses.name'];
      $base = new DataTableBase($query, $dataTable, $columns);
      return $base->render(null);
		}

script

   <script src="/vendor/datatables/buttons.server-side.js"></script>
      <script src="/js/bootstrap-datepicker.min.js"></script>

       <script type="text/javascript">
          var oTable = $('#userstable').DataTable({
            processing: true,
            serverSide: true,
            dom: 'Bfrtip',
                 buttons: [
                     'copy', 'csv', 'excel', 'pdf', 'print'
                 ],
               processing: true,
               serverSide: true,
               ajax: {
                   url: '/acadmic/income/search_ajax',
                   data: function (d) {

                       d.course = $('select[name=course]').val();
                       d.start = $('input[name=start]').val();
                       d.end = $('input[name=end]').val();

                   }
               },
               columns: [
                            { data: 'id', name: 'id' },
                             { data: 'created_at', name: 'created_at' },
                             { data: 'tution_fee', name: 'tution_fee' },
                             {data: 'development_fee', name: 'development_fee'},
                             { data: 'late_fee', name: 'late_fee' },
                             { data: 'other_fee', name: 'other_fee' },
                             {data: 'total', name: 'total', orderable: false, searchable: false},
                             { data: 'courses.name', name: 'courses.name' },
               ]
           });

           $('#search-form').on('submit', function(e) {
               oTable.draw();
               e.preventDefault();
           });
       </script>

   <script type="text/javascript">

      $(document).ready(function(){
      	$('#sandbox-container .input-daterange').datepicker({
    format: "dd/mm/yyyy",
    forceParse: false,
    autoclose: true
});
      })
  </script>
@yajra
Copy link
Owner

yajra commented Feb 5, 2017

You should not use start as a field name on your request because it is being used by dataTables when paging the results.

@yajra yajra added the question label Feb 5, 2017
@vipin733
Copy link
Author

vipin733 commented Feb 6, 2017

yes i changed that and its working and also my if statement date format problem i changed and it's working

@yajra yajra closed this as completed Jul 6, 2017
@atefBB
Copy link

atefBB commented Jan 22, 2018

@yajra You save my day! Thx!

@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants