Фильтрация по статусу с помощью ajax и laravel - PullRequest
0 голосов
/ 25 апреля 2018

У меня есть данные в базе данных с 2 таблицами, которые называются регистрации, ssi_tracks. Мне нужно показать данные таблицы регистрации, основанные на track_first_status, и мне нужно отфильтровать данные по состоянию. На самом деле сценарий и работает, но я не получаю никаких правильный ответ

  1. Первый статус = 0 (не вызывается)
  2. Первый статус = 1 (частично вызывается)
  3. Первый статус = 2 (Ожидание)
  4. Первый статус = 3 (в черном списке)
  5. Первый статус = 4 (полностью закрыт) * ​​1012 *

Это я использовал для фильтрации, но он работает неправильно, если я выбираю статус 2 он возвращает результат статуса 1, но если я выбрал статус 1, ничего не происходит

Код Ajax

 $(function () {
        $("#dropcallstatus").change(function () {

          let $value;

            if (($(this).val() === "0") || $(this).val() === "1" || $(this).val() ==="2" || $(this).val() ==="3" || $(this).val() ==="4") {
                $value = $(this).val();
                $.ajax({
                    type: 'GET',
                    url: "{{url("callstatus")}}",
                    data: {'dropcallstatus': $value},
                    dataType: 'json',
                    success: function (data) {
                       $('#listdetails').html(data);
//               console.log(data);
                    }
                });

            }
            else {
                alert('Select Any Status');
            }
        });
    });

Индексный файл

<div class="content-page">
    <!-- Start content -->
    <div class="content">
        <div class="container-fluid">

            <div class="row">
                <div class="col-12">
                    <div class="page-title-box">
                        <h4 class="page-title float-left">SSI TRACK</h4>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
            <!-- end row -->
            <div class="row">
                <div class="col-12">
                    <div class="card-box table-responsive">
                        <h4 class="m-t-0 header-title"><b>SSI TRACKS</b></h4>

                        <div id="datatable_wrapper" class="dataTables_wrapper container-fluid dt-bootstrap4 no-footer">
                            <div class="row">

                                <div class="col-sm-6">

                                    <select class="form-control" style="width: 130px" id="dropselect" name="dropselect">

                                        <option>Select Status</option>
                                        <option value="24Hours">24 Hours</option>
                                        <option value="15Days">15 Days</option>
                                        {{--<option value="3">All</option>--}}

                                    </select>
                                    <br>

                                    <select class="form-control" style="width: 130px" id="dropcallstatus"
                                            name="dropselectstatus">

                                        <option>Select Calls</option>
                                        <option value="0">Not Called</option>
                                        <option value="1">Partially Called</option>
                                        <option value="2">Waiting Calls</option>
                                        <option value="3">Black Listed Calls</option>
                                        <option value="4">Fully Closed Calls</option>

                                    </select>

                                </div>


                            </div>


                            <div class="row">
                                <div class="col-md-12">
                                    <label>From
                                    </label> <input type="date" name="start_date" id="start_date" class="form-control"
                                                    style="width:150px;">
                                    <label>To</label> <input type="date" name="end_date" id="end_date"
                                                             class="form-control"
                                                             style="width:150px;">
                                    <button class="btn btn-info" id="filter" name="filter">Filter</button>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12">
                                    <table id="datatable" class="table table-bordered dataTable table-responsive-lg">
                                        <thead>
                                        <tr>
                                            <th>slno</th>
                                            <th>Address</th>
                                            <th>Model</th>
                                            <th>Chassis</th>
                                            <th>Delivery Date</th>
                                            <th>Call</th>

                                        </tr>
                                        </thead>
                                        <tbody id="listdetails" name="listdetails">

</tbody>
</div>
</div>
</div>
</div>
</div>

Функция контроллера для фильтрации

 public function callstatus(Request $request)
    {

        $dropselect = $request->input('dropcallstatus');


        if ($dropselect === '1') {
            $call = DB::table('registrations')
                ->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
                ->select('address', 'model', 'chassis', 'delivery_date')
                ->where([["ssi_tracks.track_first_status", "=", 0]])
                ->get();


            $output = "";
            $count = 1;
            foreach ($call as $calls) {

                $output .= '<tr>' .
                    '<td>' . $count++ . '</td>' .
                    '<td>' . $calls->address . '</td>' .
                    '<td>' . $calls->model . '</td>' .
                    '<td>' . $calls->chassis . '</td>' .
                    '<td>' . $calls->delivery_date . '</td>' .
                    '<td>' . '<button class="btn btn-primary btn-rounded button">Call Customer
                                                    </button>' . '</td>' .

                    '</tr>';


            }
            return response()->json($output);
        } elseif ($dropselect === '2') {

            $call = DB::table('registrations')
                ->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
                ->select('address', 'model', 'chassis', 'delivery_date')
                ->where([["ssi_tracks.track_first_status", "=", 1]])
                ->get();


            $output = "";
            $count = 1;
            foreach ($call as $calls) {

                $output .= '<tr>' .
                    '<td>' . $count++ . '</td>' .
                    '<td>' . $calls->address . '</td>' .
                    '<td>' . $calls->model . '</td>' .
                    '<td>' . $calls->chassis . '</td>' .
                    '<td>' . $calls->delivery_date . '</td>' .
                    '<td>' . '<button class="btn btn-primary btn-rounded button">Call Customer
                                                    </button>' . '</td>' .
                    '</tr>';


            }
            return response()->json($output);

        } elseif ($dropselect === '3') {
            $call = DB::table('registrations')
                ->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
                ->select('address', 'model', 'chassis', 'delivery_date')
                ->where([["ssi_tracks.track_first_status", "=", 2]])
                ->get();


            $output = "";
            $count = 1;
            foreach ($call as $calls) {

                $output .= '<tr>' .
                    '<td>' . $count++ . '</td>' .
                    '<td>' . $calls->address . '</td>' .
                    '<td>' . $calls->model . '</td>' .
                    '<td>' . $calls->chassis . '</td>' .
                    '<td>' . $calls->delivery_date . '</td>' .
                    '<td>' . '<button class="btn btn-primary btn-rounded button">Call Customer
                                                    </button>' . '</td>' .
                    '</tr>';


            }
            return response()->json($output);

        }
        elseif ($dropselect === '4') {

            $call = DB::table('registrations')
                ->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
                ->select('address', 'model', 'chassis', 'delivery_date')
                ->where([["ssi_tracks.track_first_status", "=", 3]])
                ->get();


            $output = "";
            $count = 1;
            foreach ($call as $calls) {

                $output .= '<tr>' .
                    '<td>' . $count++ . '</td>' .
                    '<td>' . $calls->address . '</td>' .
                    '<td>' . $calls->model . '</td>' .
                    '<td>' . $calls->chassis . '</td>' .
                    '<td>' . $calls->delivery_date . '</td>' .
                    '<td>' . '<button class="btn btn-primary btn-rounded button">Call Customer
                                                    </button>' . '</td>' .
                    '</tr>';


            }
            return response()->json($output);

        }
        elseif ($dropselect === '5') {
            $call = DB::table('registrations')
                ->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
                ->select('address', 'model', 'chassis', 'delivery_date')
                ->where([["ssi_tracks.track_first_status", "=", 4]])
                ->get();


            $output = "";
            $count = 1;
            foreach ($call as $calls) {

                $output .= '<tr>' .
                    '<td>' . $count++ . '</td>' .
                    '<td>' . $calls->address . '</td>' .
                    '<td>' . $calls->model . '</td>' .
                    '<td>' . $calls->chassis . '</td>' .
                    '<td>' . $calls->delivery_date . '</td>' .
                    '<td>' . '<button class="btn btn-primary btn-rounded button">Call Customer
                                                    </button>' . '</td>' .
                    '</tr>';


            }
            return response()->json($output);
        }
        else {
            return back()->with('warning', 'Please select a status');
        }
    }

1 Ответ

0 голосов
/ 25 апреля 2018
public function callstatus(Request $request)
{

    $dropselect = $request->input('dropcallstatus');
//    if ($dropselect === '1') {
        $call = DB::table('registrations')
            ->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
            ->select('address', 'model', 'chassis', 'delivery_date')
            ->where([["ssi_tracks.track_first_status", "=", $dropselect]])
            ->get();

        if($call){
            $output = "";
            $count = 1;
            foreach ($call as $calls) {

                $output .= '<tr>' .
                    '<td>' . $count++ . '</td>' .
                    '<td>' . $calls->address . '</td>' .
                    '<td>' . $calls->model . '</td>' .
                    '<td>' . $calls->chassis . '</td>' .
                    '<td>' . $calls->delivery_date . '</td>' .
                    '<td>' . '<button class="btn btn-primary btn-rounded button">Call Customer
                                                    </button>' . '</td>' .

                    '</tr>';
            }
            return response()->json($output);
        }
        else
        {
            return back()->with('warning', 'Please select a status');       
        }    
//    }
}
...