MRF
MRF

Reputation: 377

Datatables no value for date should return "No date", laravel 5

I have a datatable which takes a date, in my mysql no date is supplied so I would like "No date" to appear in the table instead of 01-01-1970. I have read around and found the following code to try and fix my column 0 with date in. My JQuery looks like:

 <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $('#new_table').DataTable({
 "aoColumns":[
              null,
                {
                'mRender': function(data, type, full){
                    if (full[0] != ''){
                     // display date
                     return full[0];
                        }else{
                        return "No Date";
                        }    
                       }
                  }    
               ]
         });
    } );
        </script>

Table is as:

 <table id="new_table" class="table table-striped table-bordered table-hover responsive resourceTable">
                            <thead>
                                <tr>
                                <th>Date Received</th>
                               </tr>
                            </thead>
                            <tbody>
                       @foreach($inventory_items as $item)
                            <tr>
                            <td>{{date('d-M-Y', strtotime($item->date_received))}}</td>
                            </tr>
                       @endforeach
            </tbody>
   </table>

I can't seem to work out why it wont return the string as described in the Jquery, any help would be awesome. Thanks MRF

Upvotes: 0

Views: 370

Answers (1)

annoyingmouse
annoyingmouse

Reputation: 5699

From discussion:

If this is available:

function IsNullOrEmptyString($question){
    return (!isset($question) || trim($question)==='');
}

You could use this:

{{(IsNullOrEmptyString($item->date_received)) ? "No date" : date('d-M-Y', strtotime($item->date_received))}}

Upvotes: 1

Related Questions