我有带有分组的网格,我按一列进行分组,然后在另一列上进行小时总结,如下所示:
name: "GroupBy",
type: "local",
columnSettings: [
{
columnKey: "codeName",
isGroupBy: true,
},
{
columnKey: "hour",
isGroupBy: false,
summaries: [
{
summaryFunction: "custom",
text: "Hours :",
customSummary: function (valuesList) {
var sumOfHours = 0.0;
var sumOfMinutes = 0.0;
for (i = 0; i < valuesList.length; i++) {
var split = valuesList[i].split(':');
sumOfHours += parseInt(split[0]);
sumOfMinutes += parseInt(split[1]);
}
sumOfHours += parseInt(sumOfMinutes / 60);
var minutesLeft = sumOfMinutes % 60;
return sumOfHours + ":" + minutesLeft;
}
}
]
}
],
summarySettings: {
//summaryFormat: "HH:MM" // What should I write here to get proper formatiing?
}
现在的问题是,每当我得到:
- 36 小时显示 360.00,而不是 36:00
- 165 小时后显示 1,650.00,而不是 165:00
- 8 小时 15 分钟后显示 815.00,而不是 8:15
- 34 小时 15 分钟显示为 3,415.00,而不是 34:15
我在文档中找不到如何正确显示它的任何地方。有人可以帮忙吗?
最佳答案
igGridGroupBy 摘要函数应始终返回数字类型,但这不是您的情况。这就是您看到此行为的原因。 您可以做的是覆盖 $.ig.formatter 函数(在初始化 igGrid 之前),该函数在 Ignite UI 和 GroupBy 功能中用于格式化值并注入(inject)逻辑。 这是一个例子:
var origFormatter = $.ig.formatter;
$.ig.formatter = function (val, type, format) {
if (format === "myFormat") {
return val;
}
return origFormatter.apply(arguments);
}
// Initialize igGrid here
然后设置 summarySettings.summaryFormat = "myFormat"以便您的逻辑启动。
关于infragistics - 如何在 igGrid 2013.2 中格式化分组汇总结果中的小时数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32563039/