Author Topic: column summary for date 'max' is undefined when there is only one row in group  (Read 120 times)

jim@solver.com

  • Pro OEM
  • Newbie
  • *
  • Posts: 5
    • View Profile
I am currently using version 8.3.0.

I am using the max function for a column that is dataType: 'date' and a groupModel that results in some groups with a single row. In those groups the max date is not displayed in the group summary for that group.

I investigated and found that the max function initializes the max variable using the arr[0] element. It then compares that in the while loop with valDate which in this case is also the arr[0] element value. Because valDate is not greater than max the val variable remains undefined. The max variable is assigned the val value after the while loop exits so the returned max value is undefined.

Note: max would also probably be undefined in a multi-row group when the arr[0] element happens to be the maximum date.

The code for the max function starts on line 14928 in pqgrid.dev.js and is shown below:

Code: [Select]
max: function(arr, column) {
var len, max, temp, val, valDate, dataType = pq.getDataType(column);
arr = this.flatten(arr);
len = arr.length;
if (len) {
if (dataType == "number") {
max = arr[0] * 1;
while (len--) {
temp = arr[len];
max = temp > max || isNaN(max) ? temp : max
}
} else if (dataType == "date") {
max = Date.parse(arr[0]);
while (len--) {
valDate = Date.parse(arr[len]);
if (valDate > max || isNaN(max)) {
max = valDate;
val = arr[len]
}
}
max = val
} else {
arr.sort();
max = arr[len - 1]
}
return max
}
},

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5564
    • View Profile
Thanks for reporting the issue, it would be fixed in upcoming version.

Please let me know if you need a patch.

jim@solver.com

  • Pro OEM
  • Newbie
  • *
  • Posts: 5
    • View Profile
If it will be a long time before it is fixed in a release and you have a patch I will use it. Otherwise I will temporarily fix it myself.

Thanks,
Jim