KoolReport's Forum

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

Sorting / ordering column on DataTables #2494

Closed paulo opened this topic on on Dec 15, 2021 - 2 comments

paulo commented on Dec 15, 2021

Hi there, I am struggling on sorting a column desc on Data Table - I hope someone can help me please I tried on the sql itself, on a Sort, and on the view.... nothing seems to be working. Thank you very much

Sql:

SELECT PASSENGERNAME, sum(TOTALFARE/100) as TOTAL
                FROM INVOICE
                join BOOKING on BOOKING.INVOICE_LINKNO = INVOICE.INVOICENO
                where CLIENT_LINKNO=:customerNames AND (EXTRACT (YEAR FROM ISSUEDATE)=:years)
               group by PASSENGERNAME
               order by TOTAL DESC
  ->pipe(new Map(array(
                '{meta}' => function($metaData) {
                    $metaData['columns']['TOTAL'] = array(
                        'className' => 'text-right',
                        'footer' => 'sum',
                        'footerText' => 'Total: @value',
                        "type"=>"number",
                        "decimals"=>2,
                    );
                    return $metaData;
                },
            )))
            ->pipe(new Sort(array(
                "TOTAL"=>"DESC"
            )))
            ->pipe($this->dataStore("queryCorporateClients"));


     "options" => array(
            "order"=>array(
                 array(1,"desc")
             ),
Sebastian Morales commented on Dec 15, 2021

With DataTables pls try to use column meta type "num-fmt" for ordering:

    DataTables::create(array(
        ...
        "options" => array(
            "columnDefs" => array(
                array( "type" => "num-fmt", "targets" => array(1) ), // set type for the 2nd column (index 1)
            )
    ));

Let us know how this works for you. Tks,

paulo commented on Dec 15, 2021

thank you very much. Added the columnDefs and it worked combined with order: "columnDefs" => array(

            array( "type" => "num-fmt", "targets" => array(1) ), // set type for the 2nd column (index 1)
        ),
        "order"=>array(
            array(1,"desc")
        ),

thanks

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
help needed

Laravel