Author Topic: how to add columns  (Read 2514 times)

徐雪峰

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 48
    • View Profile
how to add columns
« on: July 20, 2020, 11:25:52 pm »
how to add columns in pivotCM?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: how to add columns
« Reply #1 on: July 21, 2020, 07:34:52 am »
pivotCM is an event which is used to add, modify or delete columns in colModel of pivot grid.

These 2 examples demonstrate with code how to customize colModel in pivotCM event:

https://paramquery.com/pro/demos/pivot_custom

https://paramquery.com/pro/demos/pivot_total

Also read and understand the Columns() API which is used in above examples:

https://paramquery.com/pro/api#method-Columns
« Last Edit: July 21, 2020, 07:38:15 am by paramvir »

徐雪峰

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: how to add columns
« Reply #2 on: July 21, 2020, 10:30:11 am »
i have some special request. i want to add some column after pivod summary column,
for example ;
goods1             goods2         goods3               total(goods1+goods2+goods3)
2019  2020    2019  2020    2019  2020     2019  2020
but i can't do that by pivot grid
data:goods1,2019
       goods1,2020
       goods2,2019
       goods2,2020
      goods3,2019
      goods3,2020

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: how to add columns
« Reply #3 on: July 21, 2020, 11:53:38 am »
Please share your attempt so far via jsfiddle or stackblitz.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: how to add columns
« Reply #4 on: July 21, 2020, 10:11:11 pm »
I've added this new example on add new column in pivot view for you.

https://paramquery.com/pro/demos/pivot_add_col

徐雪峰

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: how to add columns
« Reply #5 on: July 22, 2020, 12:21:13 pm »
thank you for your help very much.
if i can get the group data after pivot group ,and plus or minus them,
i think all my project request will be satisfied.
about the sample code,i have a question:
1, is one() a api function? 2,can the new row have a summay?
this.one('groupData', function () {
                    this.pageData().forEach(function (rd, indx) {
                        rd.new_col = indx;
                    })
                });

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: how to add columns
« Reply #6 on: July 22, 2020, 09:27:24 pm »
1. yes though one('groupData') not required if summary is to be used in the column.

2. yes, please see the updated example.