pranjal-goswami / multifact-pivottable

A JavaScript plugin for PivotTable.js. It renders multiple aggregations simultaneously with added configurations for rendering beautiful tables http://pranjalgoswami.in/multifact-pivottable/examples/index.html
MIT License
18 stars 13 forks source link

pivottable.js column sort order #15

Open BBBhatt opened 3 years ago

BBBhatt commented 3 years ago

In my Data Set, I've populated month names with year as follows... "Apr-2021", "May-2021", "June-2021"... and so on based on two dates.

the default sort order goes alphabetically... :(

Now I want to sort these based on month number & year wise...

How to do this?

-Thanks, BBBhatt.

codythegreat commented 3 years ago

Is changing the format possible? You could do something like 2020-12, 2021-01, 2021-02, . . .

Now if changing the data set isn't possible, you might be able to edit $.pivotUtilities.sortAs object like so:

                    rows: ["day name"],
                    cols: ["month name"],

                    sorters: {
                        "month name": sortAs(["Jan","Feb","Mar","Apr", "May",
                                "Jun","Jul","Aug","Sep","Oct","Nov","Dec"]),
                        "day name": sortAs(["Mon","Tue","Wed", "Thu","Fri",
                                "Sat","Sun"])
                    },

This is all part of the standard pivottable library, and this example can be referenced here

BBBhatt commented 3 years ago

Is changing the format possible? You could do something like 2020-12, 2021-01, 2021-02, . . .

Now if changing the data set isn't possible, you might be able to edit $.pivotUtilities.sortAs object like so:

                    rows: ["day name"],
                    cols: ["month name"],

                    sorters: {
                        "month name": sortAs(["Jan","Feb","Mar","Apr", "May",
                                "Jun","Jul","Aug","Sep","Oct","Nov","Dec"]),
                        "day name": sortAs(["Mon","Tue","Wed", "Thu","Fri",
                                "Sat","Sun"])
                    },

This is all part of the standard pivottable library, and this example can be referenced here

thanks codythegreat, But we cannot change format as of now. We might develop a customized function which will consider sorter column like substr(0,3), then use sortAS by fixed month names.. what you think??

-Thanks,

codythegreat commented 3 years ago

@BBBhatt does your data source encompass multiple years? If so the sorting may end up with something like this:

Jan-2020 | Jan-2021 | Feb-2020 | Feb-2021 | . . .

I doubt that is what you want, so if you do have multiple years of data you may want to check the year and month as well.

Otherwise yes I think your best bet is to use sortAs to accomplish this.

Hope this helps. Without seeing your data source it is tough to say what you should do.

BBBhatt commented 3 years ago

In my deta set (JSON). I've included Month and Years. say.. 5 and 2021. the entire dataset populates by giving two date ranges.

so we have array of objects which can be sorted and then use it in sort functions...

do you have any idea to achive this?

-Thanks, BBBhatt.