Sorting Date in PivotTable

I have a pivotTable on screen where Date field is in the column. I want the columns (Date) to be in ascending order and using the following query for loading the datasource.

select e from erp$ProductionPlanContinuousProdPivot e order by e.prodDate asc

But no change columns are displayed with sorting of first two digits of Date i.e. day only. Any suggestion would be appreciated.

According to the documentation, FS function needs to be used. There are some example given in the user guide but it will be more helpful if there is any guidance given on how to use the specific field(s) for sorting in this example “prodDate”.

Hi,

Indeed you need to use the sorterFunction attribute and provide a JavaScript function to sort dates. sorterFunction returns a function for a certain attribute, witch accepts two parameters (i.e. a comparator function). For instance:

function (attr) {
    if (attr === "Prod Date") { // compare the attribute 
                                // with a localized value
        return function(date1, date2) { 
            // compare dates
        }
    }
}

Regards,
Gleb

Hi Gleb,
Thanks. in your example, you wanted to compare date1, date2 etc. how can i compare when i do not have those date value I only have datasource? Thanks for more specific hints…

Hi,
You can acces every property of a given datasource used in a screen, via injecting them.

Have a look (here) [https://doc.cuba-platform.com/manual-6.5/datasources.html]

sorterFunction is applied in the client-side after the data is converted to the way the PivotTable accept it. So, this function has nothing in common with the data source as well as PivotTable doesn’t care about the original data sorting. If you find the cuba docs helpless, I would recommend checking this sample from the original pivottable.js doc.