jqGrid组摘要不显示分页的总和

时间:2021-11-06 07:38:38

This is my first post in this forum, so please, be patient with me.

这是我在这个论坛上的第一个帖子,所以请耐心等待。

I need to set my summary to show the sum of all rows in my grid, even the rows that are inside other pages - the absolute sum of values.

我需要设置我的摘要来显示网格中所有行的总和,甚至是其他页面中的行——值的绝对总和。

I was searching for it, and I saw a lot of people with this problem, so I don't think it is a problem with my code. It sounds more like a design in the grouping mechanism itself, otherwise I don't know.

我在找它,我看到很多人都有这个问题,所以我不认为这是我的代码的问题。这听起来更像是分组机制本身的设计,否则我不知道。

But, to be clear, I think I need to make a call to server side to get the sum from there, is this possible? If so, how should I do it with json?

但是,需要澄清的是,我想我需要打个电话给服务器端,从那里得到总数,这可能吗?如果是,我应该如何使用json?

I was thinking about using the formatter option, but then it is triggered line by line, and I don't think this is the idea because the sum will come entire in the first call.

我在考虑使用formatter选项,但它是逐行触发的,我不认为这是我的想法,因为在第一次调用中,和将是完整的。

Any suggestions?

有什么建议吗?

Thanks !!!

谢谢! ! !

1 个解决方案

#1


1  

You can define a custom summaryType function to display your sum. According to the documentation for summaryType:

您可以定义一个自定义的summary类型函数来显示您的和。根据summary类型文件:

The option can be defined as function. If defined we pass three parameters to it - the current value, the name and the record object. The function should return value. Note that this value will be used again for the group value until it changes.

该选项可以定义为函数。如果定义了,我们将向它传递三个参数——当前值、名称和记录对象。函数应该返回值。注意,该值将再次用于组值,直到它发生变化。

For example, you could retrieve a totalSumRecord when the page is loaded - it would be a bad idea to make an AJAX call directly from the formatter - and then just display the appropriate value in the formatter:

例如,您可以在加载页面时检索totalSumRecord—直接从formatter中调用AJAX是个坏主意—然后在formatter中显示适当的值:

function myCustomSummary(val, name, record) {
    return totalSumRecord[name];
}

jQuery("#grid").jqGrid({ 
  ...
  colModel : [
     {..},
     {name:'myColumn',
      index:'myColumn', 
      width:80, 
      align:"right", 
      sorttype:'number',
      formatter:'number',
      summaryType:myCustomSummary},
     ...
  ],
  ...
});


Update

There is a bug in jqGrid 4.4 where functions are not allowed as a summary type. If this affects you, here is the fix.

jqGrid 4.4中有一个错误,其中不允许函数作为汇总类型。如果这影响到你,这就是解决办法。

#1


1  

You can define a custom summaryType function to display your sum. According to the documentation for summaryType:

您可以定义一个自定义的summary类型函数来显示您的和。根据summary类型文件:

The option can be defined as function. If defined we pass three parameters to it - the current value, the name and the record object. The function should return value. Note that this value will be used again for the group value until it changes.

该选项可以定义为函数。如果定义了,我们将向它传递三个参数——当前值、名称和记录对象。函数应该返回值。注意,该值将再次用于组值,直到它发生变化。

For example, you could retrieve a totalSumRecord when the page is loaded - it would be a bad idea to make an AJAX call directly from the formatter - and then just display the appropriate value in the formatter:

例如,您可以在加载页面时检索totalSumRecord—直接从formatter中调用AJAX是个坏主意—然后在formatter中显示适当的值:

function myCustomSummary(val, name, record) {
    return totalSumRecord[name];
}

jQuery("#grid").jqGrid({ 
  ...
  colModel : [
     {..},
     {name:'myColumn',
      index:'myColumn', 
      width:80, 
      align:"right", 
      sorttype:'number',
      formatter:'number',
      summaryType:myCustomSummary},
     ...
  ],
  ...
});


Update

There is a bug in jqGrid 4.4 where functions are not allowed as a summary type. If this affects you, here is the fix.

jqGrid 4.4中有一个错误,其中不允许函数作为汇总类型。如果这影响到你,这就是解决办法。