0

如果您想查看在给定日期到期的圆顶,我有一个下拉选项可供选择。 选择在给定日期到期

但是一旦我选择了日期,我将得到具有正确结果的纯 json 代码。这是我在表格上方的表格

<form method="post" action="{{ action('DomenController@tabela') }}" id="klijent_rok" onchange="document.getElementById('klijent_rok').submit()">
    @csrf
    <div class="form-group row">
        <label for="istice_za" class="ml-md-auto col-form-label text-md-left" style="padding-right: 10px;">Ističu u roku od:</label>
            <select  name="istice_za" id="istice_za" class="form-control" style="width: 140px" size="1">
                <option value="99" @if($istice_za == '99') selected='selected' @endif>-neodređeno-</option>
                <option value="7" @if($istice_za == '7') selected='selected' @endif>za 7 dana</option>
                <option value="30" @if($istice_za == '30') selected='selected' @endif>za 30 dana</option>
                <option value="60" @if($istice_za == '60') selected='selected' @endif>za 60 dana</option>
                <option value="istekli" @if($istice_za == 'istekli') selected='selected' @endif>istekli</option>
            </select> 
        <a href="/lista-domena" class="btn btn-info" style="height: 37px; margin-left: 10px; margin-right: 15px">Poništite filtere</a>
    </div>
</form>

这是服务器端数据表的矿井控制器

if(!empty($request->istice_za) && $request->istice_za != 99) {
    $date = Carbon::now();
    $new_date = Carbon::now();
    if($request->istice_za != 'istekli') {
        if($request->istice_za == 7) {
            $istice_za = 7;
            $new_date->addDays(7);
        }
        if($request->istice_za == 30) {
            $istice_za = 30;
            $new_date->addDays(30);
        }
        if($request->istice_za == 60) {
            $istice_za = 60;
            $new_date->addDays(60);
        }
        $domen = Domen::where('datum_end', '<', $new_date)
            ->Where('datum_end', '>', $date)
            ->with('klijent');
        }
        else {
            $domen = Domen::where('datum_end', '<', $date)->with('klijent');
            $istice_za = 'istekli';
        }
    }
    else {
        $domen = Domen::with('klijent');
        $istice_za = 99;
    }
    return datatables()->of($domen)->make(true);

这些是我的路线

Route::get('/lista-domena/tabela', 'DomenController@tabela');
Route::post('/lista-domena/tabela', 'DomenController@tabela');

我做错了什么并且没有在我的表中获取该数据?

4

3 回答 3

0

html:

<table id="affected-requirement-table" class="table table-hover table-sm table-bordered">
                                    <!--Table head-->
                                    <thead>
                                    <tr>
                                        <th>Requirements</th>
                                        <th>Effect Type</th>
                                    </tr>
                                    </thead>
                                    <!--Table head-->
                                    <!--Table body-->
                                    <tbody>
                                    <!-- Ajax Load -->
                                    </tbody>
                                    <!--Table body-->
                                </table>

jQuery

    $(document).ready(function () {




        var affectedRequirementsTable = $('#affected-requirement-table').DataTable({
            "scrollY":        "200px",
            "scrollCollapse": true,
            "paging":         false,
            processing: true,
            serverSide: true,
            bFilter: false,
            "bInfo": false,
            "bPaginate": true,
            "ordering": false,
            "bLengthChange": false,

            ajax: {
                url: '{!! \Illuminate\Support\Facades\URL::to("cr/requirements-datatables") !!}'
            },
            columns: [

                {data: 'number'},
                {data: 'effect-type'}
            ],
            // "fnCreatedRow" : function (row, data, dataIndex) {
            //     var div = document.createElement("div");
            //     $(div).html('<select  name= "changeRequest[]" class="form-control effect-type-select" id="mySelect"> <option  selected="selected" value="None">None</option> <option  value="Addition">Addition</option> <option  value="Deletion">Deletion</option> </select>');
            //     $(row).children("td:last-child").append(div);
            // }


        });

        // draw the table
        affectedRequirementsTable.draw();


        $("#affected-requirement-table").on('change',".effect-type-select",function (e) {
            var optionSelected = $("option:selected", this);
            var valueSelected = this.value;
            console.log(valueSelected);

        });





    })

路线:

      Route::get('cr/requirements-datatables', "ChangeRequestController@requirementsAndEffectTypesDatatables");

控制器:

       public function requirementsAndEffectTypesDatatables(ChangeRequests $request)
{

    $changeRequest = DB::table('requirement')->select(['number','id']);

    return DataTables::of($changeRequest)->addColumn('effect-type', function ($changeRequest) {


        return '
                <select  name= "changeRequest[]" class="form-control effect-type-select" id="mySelect">
                   <option  selected="selected" value="None">None</option>
                    <option  value="Addition">Addition</option>

                     <option  value="Deletion">Deletion</option>
                </select>';
    })->rawColumns(['effect-type'])->make(true);


     }
于 2019-04-17T08:48:08.277 回答
0

首先,您的代码没有运行查询,您需要添加->get()first()获取数据。

$domen = Domen::where('datum_end', '<', $date)->with('klijent')->get();

或者,

$domen = Domen::with('klijent')->get();
于 2018-10-15T13:41:23.043 回答
0

我设法解决了它。问题是我没有将数据从选择发送到我的控制器。我将我的表格编辑成这样:

<form method="post" action="{{ action('DomenController@tabela') }}" id="klijent_rok">

然后在脚本中添加这个:

 $('#klijent_rok').on('change', function(e) {
    table.draw();
});

并将 Ajax 更改为:

ajax: {
    url: '/lista-domena/tabela',
    data: function ( d ) {
        d.istice_za = $('#istice_za').val();
    },
}...
于 2018-10-16T07:03:08.883 回答