KoolReport's Forum

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

Sort and group by #1018

Open paulo opened this topic on on Jul 30, 2019 - 4 comments

paulo commented on Jul 30, 2019

Hi,

I am trying to sort by and group after.

I added to my query the ORDER BY and then a pipe to sort (neither worked).

from tours as T

                left join tour_costing AS TC on TC.tour_id = T.id
                left join staff as S on S.id = T.Planner
                left join staff as S2 on S2.id = T.manager_id
                left join statuses as ST on ST.id = T.status_id
                WHERE T.tour_status !=\"0\" AND T.Planner=$staff_id
                ORDER BY ST.row_number ASC
    ")
        ->pipe(new Sort(array(
            "ST.row_number"=>"asc"
        )))
        ->pipe($this->dataStore("toursGroupedByPlanner"));

As part of the display/report:

Table::create(array(

    "dataStore" => $this->dataStore('toursGroupedByPlanner'),
    "grouping" => array(
        "status" => array(
            "calculate" => array(
                "{sumComm}" => array("sum", "comm"),
                "{sumEst}" => array("sum", "estimated_sale"),
                "{sumAgent}" => array("sum", "agent")

            ),
            "top" => "<b>{status}</b>",
            "bottom" => "<td><b>Total {status}</b></td><td></td><td></td><td>{sumEst}</td><td>{sumAgent}</td><td><b>{sumComm}</b></td><td></td><td></td>"
        ),
    ),

What am I doing wrong? Thank you

KoolReport commented on Jul 31, 2019

Do you mean the end grouping result is not following the sorting order?

paulo commented on Jul 31, 2019

yes! It is perfectly grouping by "status" field which contains a description such as 'Lead' , 'Proposal set', but they are in random order. I was trying to define an order using a numeric field "row_number' which sets all 14 status in order .

thank you

KoolReport commented on Jul 31, 2019

Since the "grouping" settings of table will mess up the pre sorting of data. So you should set the sorting in the Table widget. Please read here.

paulo commented on Aug 1, 2019

thanks. I've tried that and it is still showing out of order: Also note there is a misspell "Source" in the example link provided Table::create(array(

  //  "dataStore" => $this->dataStore('toursGroupedByPlanner'),
    "dataSource"=>$this->dataStore("toursGroupedByPlanner"),
    "sorting"=>array(
         "row_number"=>"asc",
        "status"=>"asc"
    ),
    "grouping" => array(
        "status" => array(
            "calculate" => array(

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

None