StateSave with serverside restores wrong date value SearchBuilder and ColumnControl

StateSave with serverside restores wrong date value SearchBuilder and ColumnControl

lbermudezlbermudez Posts: 9Questions: 0Answers: 0

Link to test case: https://intranet2.cimne.com/ws/demo_datatables

With ColumnControl and stateSave: true, a date entered as 06/10/1984 filters correctly. However, after reloading the page, the saved state restores it as 06-10-1984, and Editor PHP sends that value to MySQL, causing an Incorrect DATETIME value error.

SearchBuilder, when input 06/10/1984 doesnt work serverside.
SearchBuilder will also restore the state as 1984-10-06 00:00:00 and the search doesnt work.

I'm using the nigtly build as discussed here:
https://datatables.net/forums/discussion/81852/problem-with-date-type-on-3-0-update#latest

Replies

  • lbermudezlbermudez Posts: 9Questions: 0Answers: 0

    did a couple tests:

    the working value sent when searching for 06/10/1984 is:
    columns[2][columnControl][search][value] 1984-10-06T00:00:00.000Z

    but after refreshing, state save reloads the value as:
    columns[2][columnControl][search][value] 06-10-1984

    the column is declared simply as:

     {
                data: 'fecha',
                title: 'Date',
                columnControl: ['order', 'searchDropdown'],
            },
    

    and on the server side:

    Field::inst('demo.fecha_hora', 'fecha')
        ->getFormatter(Format::dateSqlToFormat('d/m/Y' ))
        ->setFormatter(Format::dateFormatToSql('d/m/Y')),
    
  • allanallan Posts: 65,887Questions: 1Answers: 10,960 Site admin

    Many thanks for the test case. I'll take a look next week and get back to you.

    Allan

  • lbermudezlbermudez Posts: 9Questions: 0Answers: 0

    Mi second issue, with SearchBuilder, seems to be related to: https://datatables.net/forums/discussion/81851

    So my problem is only with column control and statesave at the moment.

  • allanallan Posts: 65,887Questions: 1Answers: 10,960 Site admin

    In your example JS could you change:

                    columnControl: [
                        'order',
                        {
                            extend: 'searchDropdown',
                            content: [
                                {
                                    extend: 'search',
                                    format: 'DD/MM/YYYY',
                                    mask: 'YYYY-MM-DD'
                                }
                            ]
                        }
                    ]
    

    To be:

                    columnControl: [
                        'order',
                        {
                            extend: 'searchDropdown',
                            format: 'DD/MM/YYYY',
                            mask: 'YYYY-MM-DD'
                        }
                    ]
    

    please? That is how it is meant to work - I think there is a documentation error in the searchDropdown docs!

    With that change it seems to work okay for me, but if you could try it and let me know, that would be super.

    Allan

  • lbermudezlbermudez Posts: 9Questions: 0Answers: 0

    Wow, yes, that did fix it! Somehow at some point I got in my head that the searchDropDown was supposed to work as a container.

    Thanks Allan, sorry if this was a bit of a waste of time.

  • allanallan Posts: 65,887Questions: 1Answers: 10,960 Site admin
    edited August 10

    searchDropdown's docs are a bit misleading in that regard. I've committed this change which I hope will correct that, and included an example of how options can be used for it.

    Glad to hear that fixed the issue you were having :)

    Allan

Sign In or Register to comment.