KoolReport's Forum

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

DataGrid sorting negative values #1706

Closed ankit raj opened this topic on on Nov 10, 2020 - 1 comments

ankit raj commented on Nov 10, 2020

Hi , i am using a datatable with progress bar but while sorting , the negative values mess up, is there any workaround for this:

-2 is coming before -6 in ascending order , this is the code:

"columns"=>[

            $name=>[
              "footerText"=>"Total"
            ],
            "Serial Count"=>[
                'formatValue'=>function($value,$row){
            $neg_pos = abs($value);
            $text_label = '<span>'.$value.'&nbsp;</span>';
            if($value < 0) {
                return $text_label . '<div class="progress" style="display:inline-flex;height:6px;width:90%;flex-direction: row-reverse">
   <div class="progress-bar" style="width:' . $neg_pos . '%;background-color:red;"></div>

</div>';

            }
        else{
            return $text_label.'<div class="progress" style="display:inline-flex;height:6px;width:90%;">
<div class="progress-bar" style="width:'.$value.'%"></div>

</div>';

        }
        }

Sebastian Morales commented on Nov 11, 2020

You formatted your column "Serial Count" to a string so of course it's sorted by that string, not by number values -2, -6, etc. Try this code:

    "columns" => [
        "Serial Count Progress Bar" => [
            'formatValue' => ..., //use the code for your previous "Serial Count" setting here, remember to change $value to $row["Serial Count"]
            "data-order" => "Serial Count", //order this column by "Serial Count" value
        ]
    ],

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

DataGrid