KoolReport's Forum

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

Case Insensitive Sort #1565

Open Frank DiGiandomenico opened this topic on on Aug 13, 2020 - 2 comments

Frank DiGiandomenico commented on Aug 13, 2020

Is there any way in Kool Reports to specify a "case insensitive" sort? For example, my data has matter names that for some reason were not all entered in the correct sentence case format. So when I run my sort in MySQL I see the following: 1. Cestone Estate-9 Hither lane 2. Charitable Gifts- Frank Lloyd Wright 3. Chazen CRUT 4. Closing Costs - Gift to Columbia 5. cy Press 6. Dollard, Elizabeth Charitable Trust

When I run my report in Kool Reports I see this: 1. Cestone Estate-9 Hither lane 2. Charitable Gifts- Frank Lloyd Wright 3. Chazen CRUT 4. Closing Costs - Gift to Columbia 5. Dollard, Elizabeth Charitable Trust

And the matter "cy Press" is at the bottom of the report. Is there anyway option available to ignore the case when sorting or to use: usort($topics, 'strnatcasecmp')

Thanks, Frank

David Winterburn commented on Aug 14, 2020

Hi Frank,

With the Sort process you could use your custom comparing function like this:

->pipe(new \koolreport\processes\Sort(array(
    "column1" => function($v1, $v2) {
        //... compute your comparing code here, e.g using php's strnatcasecmp function
        return $cmpResult; //-1, 0 or 1 
    }
)));

Hope this works out for you. Thanks!

KoolReport commented on Aug 14, 2020

Second way, you use the CopyColumn, StringCase and Sort processes in combination. The idea is to create another column with lower case to sort. After sorting, you can remove the column if you want.

...
->pipe(new CopyColumn(array(
    "lowerColumn"=>"yourColumn"
)))
->pipe(new StringCase(array(
    "lower"=>"lowerColumn"
)))
->pipe(new Sort(array(
    "lowerColumn"=>"desc"
)))
->pipe(new RemoveColumn(array(
    "lowerColumn"
)))
...

This way is easier although it can use a little more memory than the way David suggested.

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