how search in filtered data from mysql(not raw data in sql)

how search in filtered data from mysql(not raw data in sql)

roytaroyta Posts: 6Questions: 3Answers: 0
edited October 2020 in Free community support

hello all
im using datatable for sometime and im pretty happy with it
only problem i have i use datatable Server-side processing
and for example i save date in mysql with timestamp not 2009/10/15
so when users use search in datatable its not work when they type 2009
and my php code is like this

        array(
            'db' => 'time_stamp',
            'dt' => 'time_stamp',
            'formatter' => function ( $d, $row ) {
                return date('Y/m/d G:i',$d);
                
            }
        )

there is anyway i can fix this? also there is way to do range search?

Answers

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    2009 should work as a search term, but 2009/10 will not. Unfortunately, this is the downside to using server-side processing.

    There are three ways to handle it:

    1. Transform the search term from the formatted date to ISO8601 for the SQL engine. This is virtually impossible if you allow free-form strings since you'd need to handle incomplete input as well.
    2. Do the render in the SQL server using DATE_FORMAT (or similar).
    3. Side step the issue and don't allow free form text for this column. Use a date picker widget instead.

    2 is probably the best option - but also the slowest since it needs the server to render all rows to then be able to apply the condition to them. It will also need a modification to the SSP script since it doesn't currently allow for function class like that.

    Sorry I don't have a better answer for you atm.

    Regards,
    Allan

This discussion has been closed.