Date Display between Datables and Datable Editor

Date Display between Datables and Datable Editor

DanOshDanOsh Posts: 37Questions: 11Answers: 1

I have built two areas for the same table. One an admin area to edit the table and the other to simply display it. I have used the Editor to create the admin area and used DataTables to display it.

In the admin area http://www.skywateryachts.com/datatables_editor/boats.html all NULL date cells are displayed as empty. However,
in the display area http://www.skywateryachts.com/datatables/boats_full.html all NULL date cells are displayed 1969/12/31.

How can I format the DataTables - POST of 'formatter' (code below) as the DataTables Editor - POST does with 'formatter'?

DataTables Editor - Post
* Example PHP implementation
http://www.skywateryachts.com/datatables_editor/boats.html

    Field::inst( 'Date_Reduced')
        ->validator( 'Validate::dateFormat', array(
            "format"  => Format::DATE_ISO_8601,
            "message" => "Please enter a date in the format yyyy-mm-dd"
        ) )
        ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
        ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),

DataTables - Post
* DataTables example server-side processing script.
http://www.skywateryachts.com/datatables/boats_full.html

    array(
        'db' => 'Date_Reduced',
        'dt' => 'Date_Reduced',
        'formatter' => function( $d, $row ) {
            return date( 'Y-m-d', strtotime($d));
        }
    ),  

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Hi,

    I've just loaded your boats.html page and only the first row appears to have a "Date Reduced" value. The others are all empty.

    Has this started working since your post?

    Allan

  • DanOshDanOsh Posts: 37Questions: 11Answers: 1

    That is the 'DataTables Editors' table I created at
    http://www.skywateryachts.com/datatables_editor/boats.html

    The 'DataTables View' page is the one that is returning 1969/12/31 on NULL cells at
    http://www.skywateryachts.com/datatables/boats_full.html.

    They are calling the same table, but the DataTables View page is the one with the issue. It appears I need to format the date differently as it is in the Editable table but the formatter is different in DataTables than in the DataTables Editor example I used.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Oh I see. The return date( 'Y-m-d', strtotime($d)); code isn't taking account of null values. You should add a change there for null before trying to convert it.

    Allan

  • DanOshDanOsh Posts: 37Questions: 11Answers: 1

    Yes, I changed it back to the original and will work on that after priorities. Thanks Allan.

This discussion has been closed.