KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

DataTables, "data-order" with dates no longer works #3323

Open Philippe Moser opened this topic on on Aug 8 - 4 comments

Philippe Moser commented on Aug 8

I can no longer arrange my date values in the correct order. I'm sure this code worked in a previous version, but now it seems that "data-order" no longer works.

In JobList.php

 $this->src("warehouse_datasource")
            ->query("
            ...
            //my query
            ....
                            ")
            ->pipe(new CopyColumn(array(
                "copy_of_DateValue"=>"DateValue",
                "copy_of_JobID"=>"JobID"
            )))
            ->pipe($this->dataStore("jobs_list"))
        ;

In JobList.view.php

DataTables::create(array(
                            "name" => "JobsListTable",
                            "dataSource" => $this->dataStore('jobs_list'),
                            "columns" => array(
                                "DateValue" => array(
                                    "label" => $this->translator->trans('data-column--dossier-date-value', domain: 'OdmNext_Reporting'),
                                    "type" => "datetime",
                                    "format" => "Y-m-d",
                                    "displayFormat" => "d.m.Y",
                                    "data-order" => 'copy_of_DateValue',
                                ),

                                "copy_of_DateValue" => array(
                                    "type" => "string",
                                ),
                                ...

Sebastian Morales commented on Aug 12

Would you pls right mouse click the first column cells and choose Inspect to see if there is a "data-order" html attribute in the cells? Pls post a screenshot of the cell's html element if possible.

Philippe Moser commented on Aug 13

There is no "data-order" attribute, but an "aria-sort" attribute, it changes from ascending to descending by clicking on the row cell.

Sebastian Morales commented on Aug 15

I guessed you used DataTables' fastRender property, which made data-order attribute not rendered. To solve this you can either disable fastRender or use the following client side "render" option:

    DataTables::create(array(
        ...
        "options"=>array(
            "columnDefs" => [
                [
                    "targets" => [0], // assuming the first column (index 0) is your formatted date column
                    "render" => "function ( data, type, row, meta ) {
                        return type == 'sort' ? row[1] : data; // assuming the second column (index 1) is your real date column
                    }"
                ]
            ]
        ),
        "fastRender" => true, 
Philippe Moser commented on Aug 16

yes, I used DataTables fastRender property.

It worked by removing the fastRender property. I also tested your solution. It also works for me.

Thank you very much!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
bug
help needed
solved

DataGrid