Author Topic: NaN in summary cell  (Read 3185 times)

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
NaN in summary cell
« on: August 18, 2021, 04:12:47 pm »
After implementing the {style, text, attribute} for the cell, when I group on another column, the grouping row for this cell (the {text} of the render is a number) now shows NaN, rather than the sum. How can I get the sum to display, now that I'm implementing the render method for this column? This is how the column is defined: 

{ title: ap, editable: canEdit, dataIndx: key, datatype: "float", format: nbrFormat, summary: { type: "sum" }, align: "right" }

return {
          style: 'background-color:' + color,
          text: 111,
          attr: 'title="'+ hovertext + '"'
}

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: NaN in summary cell
« Reply #1 on: August 19, 2021, 02:11:44 am »
title row has pq_gtitle metadata and summary row has pq_gsummary metadata so they can be excluded using if condition.

https://paramquery.com/pro/tutorial#topic-metadata

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: NaN in summary cell
« Reply #2 on: August 19, 2021, 02:23:06 am »
I don't understand how to use the metadata of the row to get the grouped sum. Could you elaborate?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: NaN in summary cell
« Reply #3 on: August 19, 2021, 01:33:44 pm »
metadata of row is used to identify the type of row ( normal, title, summary row )

Code: [Select]
if ( rd.pq_gtitle || rd.pq_gsummary ){ //title row or summary row.
  //let the grid do its own rendering
}
else{
  return {
    text: xyz...
    style: xyz...
    attr: xyz...
  }
}

where rd is row data.
« Last Edit: August 19, 2021, 02:03:17 pm by paramvir »

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: NaN in summary cell
« Reply #4 on: August 19, 2021, 05:32:11 pm »
I think I'm close, but still getting NaN on grouping.

https://jsfiddle.net/dep4bsL8/2/

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: NaN in summary cell
« Reply #5 on: August 20, 2021, 06:55:08 pm »
I don't see colAP being used in your jsfiddle. Please check and correct logic of your jsfiddle.

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: NaN in summary cell
« Reply #6 on: August 20, 2021, 07:45:49 pm »
It's used. That's how the cells are getting colored red/orange/green. The only issue is the grouping column is NaN.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: NaN in summary cell
« Reply #7 on: August 20, 2021, 10:15:20 pm »
Please check this as a proof of concept: https://jsfiddle.net/2bvhnuaf/

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: NaN in summary cell
« Reply #8 on: August 24, 2021, 07:42:04 pm »
Thank you for that. Is there any way to get the group by column to sum, based on the parsed value that is used in the "text" attribute, rather than referencing another column for this? I don't want to return another column in the query for complexity reasons.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: NaN in summary cell
« Reply #9 on: August 25, 2021, 04:26:09 pm »
group by column and aggregate columns can't be same.

"text" value returned in render callback is used only while rendering of current cell.
« Last Edit: August 25, 2021, 04:33:45 pm by paramvir »

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: NaN in summary cell
« Reply #10 on: August 25, 2021, 05:49:51 pm »
thanks for clarification. So to re-state, is there any way to have the aggregate column sum based on the "text" value returned in render callback. Is there any other option, rather than returning another column with only the "text" value as the dataIndx

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: NaN in summary cell
« Reply #11 on: August 25, 2021, 11:24:57 pm »
Quote
is there any way to have the aggregate column sum based on the "text" value returned in render callback.

render callback is called for every cell including aggregate column sum, so yes "text" value can be used even in summary cells.

Quote
Is there any other option, rather than returning another column with only the "text" value as the dataIndx

Sorry your question is not clear. please share a simple use case scenario.
« Last Edit: August 25, 2021, 11:26:44 pm by paramvir »

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: NaN in summary cell
« Reply #12 on: August 26, 2021, 12:16:37 am »
Here's my JS fiddle from before. The proof of concept you sent was using another column to create the sum in the aggregate column. I want to sum the column based on the text value I parsed, rather than see NaN in Month1.

https://jsfiddle.net/dep4bsL8/2/

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: NaN in summary cell
« Reply #13 on: August 26, 2021, 06:40:09 pm »
can you please share a smaller jsfiddle by keeping the code pertaining to issue only and removing all other irrelevant code so that I can better understand the issue faced by you.

Appreciate your understanding.

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: NaN in summary cell
« Reply #14 on: August 27, 2021, 12:42:29 am »