Web Data Rocks - pivot table column order by month

70 Views Asked by At

i have created bellow table using Web data Rocks

enter image description here

bellow is my code

 const pivot = new WebDataRocks({
container: "#wdr-component",
beforetoolbarcreated: customizeToolbar,
toolbar: true,
global: {
  options: {
    grid: {
      showFilter: true,
      showReportFiltersArea: true,
    },
    configuratorButton: true,
    drillThrough: true,
    sorting: "on", 
  },
}
});



const report1 = {
dataSource: {
  type: "json",
  filename: "assets/grid/datatest.json"
},
slice: {
  "rows": [{
    "uniqueName": "Year"
          }],
  "columns": [
    {
      "uniqueName": "Quater"
  },
  {
    "uniqueName": "Month"
 }
 ],
  "measures": [{
      "uniqueName": "Price",
      "aggregation": "sum"
  }]
}
};


pivot.setReport(report1)

my datatest.json data file as follows

[
{
  "Year": "2023",
  "Quater": "Q1",
  "Month": "January",
  "Mode": "Sea",
  "Destination": "Germany",
  "Price": 100
},
{
    "Year": "2023",
    "Quater": "Q1",
    "Month": "February",
    "Mode": "Sea",
    "Destination": "Germany",
    "Price": 200
  }
]

what i want is to arrange to columns by correct month order like jan, feb ... dec

i look for many resources but not able to find anyone here came cross such issue ?

1

There are 1 best solutions below

0
On

i was able to archive by doing bellow, after doing more research

you need to specify the type of each property in jsondata set. so i added bellow to json array

  [
  {
  Month: { type: "month" },
  Year: { type: "year" },
  Price: { type: "number" },
  Quater: { type: "string" },
  Mode: { type: "string" },
  Destination: { type: "string" }
 },
 {
 "Year": "2023",
 "Quater": "Q1",
 "Month": "January",
 "Mode": "Sea",
  "Destination": "Germany",
  "Price": 100
 },
 {
 "Year": "2023",
 "Quater": "Q1",
 "Month": "February",
 "Mode": "Sea",
 "Destination": "Germany",
 "Price": 200
 }
 ]

by doing so month gets arrange by correct order.