javascriptlaravelyajra-datatablelaravel-datatables

Yajara DataTable Filtration


Hey There Developers ,

I Am using Yajara Data Table Package for handling My Data .Now I am trying to add a filter that should give me the data based on the date Selected (I don't want the date Range Filtration) Suppose I had selected 7 October It should give me all the data that is being entered on 7th only That"s All

Thanks In advance Guys

I want only the data of a particular date which is being selected


Solution

  • in your controller

    $selectedDate = $request->input('selected_date'); //selected date '2023-10-07'
        
            $query = YourModel::query();
        
            if (!empty($selectedDate)) {
                $query->whereDate('created_at', $selectedDate
    
    );
     return DataTables::of($query)
    

    in your view

    <div class="form-group">
        <label for="selected_date">Select Date:</label>
        <input type="date" class="form-control" id="selected_date" name="selected_date">
    </div>
    

    Ajax request

    $('#datatable').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: '/url',
            data: function (d) {
                d.selected_date = $('#selected_date').val();
            }
        },
        columns: [columns]
    });