KoolReport's Forum

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

Example for sorting datatables columns by date or number? (instead of alpha) #1948

Open Jeremy Gray opened this topic on on Mar 5, 2021 - 4 comments

Jeremy Gray commented on Mar 5, 2021

Hello,

Can someone please provide example of how to pass the information from koolreports to datatables to enable correct sorting on a column so it knows the column is date, or number/numeric, instead of default sort by text/alpha?

Thank you

KoolReport commented on Mar 8, 2021

May I know how do you sort data?

Jeremy Gray commented on Mar 8, 2021

I am using mysql, so I do not sort other than

ORDER BY table.value DESC

at end of the setup query for

->pipe($this->dataStore("result"));

I was expecting datatables would also me to sort by each column and column type, but I guess we must tell datatables what type of data each column is. That is what I am asking how to do.

Jeremy Gray commented on Mar 8, 2021

Got it. For reference to anyone who needs...

Example below declaring the the 3rd column as type date and 8th column as type number.



"columnDefs"=>array(
                array(
                "targets"=>array(2),
                "visible"=>true,
                "type"=>date,
                ),
                array(
                "targets"=>array(7),
                "visible"=>true,
                "type"=>num,
                ),


        ),

Sebastian Morales commented on Mar 9, 2021

Jeremy, pls try to set the types like these:

    "type"=>"date",
    ...
    "type"=>"num", //or "number"

Let us know the result. Tks,

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
None yet

None