免费的jqGrid 4.8.0-设置分页发布网格重新加载的总数 [英] Free jqGrid 4.8.0 - Setting the total number of paging post grid reload
问题描述
由于数据库的count(*)性能不佳(当我们处理5000万条记录时),我们不想返回到检索到的每个记录切片中的记录总数.相反,我们想要没有它的工作.我可以在jsonReader:{records:MAX_INT}中将此记录的总数设置为MAX_INT,但是我想做得更好.
due to the bad performance on count(*) with our DB (when we deal with 50M records), we don't want to return back to total number of records in each slice of records we retrieve. Instead we want to work without it. I could set the total number of records to be MAX_INT for that matter within jsonReader:{records: MAX_INT}, but I want to make this better.
我想做的是在网格加载时设置MAX_INT的记录(我知道该部分),但是同时在后台发起对count(*)的调用,最终当真正的计数器成为检索后,我想用真实计数器覆盖MAX_INT,真实计数器是记录的真实数量.
What I would like to do is to set the records for MAX_INT when the grid loads (that part I know how), but in parallel initiate a call for count(*) at the background, eventually when the real counter will be retrieved, I would like to override the MAX_INT with the real counter which is the real number of records.
如何覆盖记录数计数器?
How do I override the number of records counter?
谢谢
推荐答案
首先,它是COUNT(*)
的众所周知的问题.如果只需要某个特定表的行数,那么一个人可以非常容易,非常快速地获取信息
First of all the it's well-known problem with COUNT(*)
. If one need to get just the number of rows of some specific table of the database then one can get the information very easy and very quickly
SELECT rows
FROM sys.partitions
WHERE index_id IN (0, 1)
AND object_id = OBJECT_ID('dbo.Tablename')
在更常见的情况下(如果数据不仅在一个分区中),应该使用SUM(rows)
而不是rows
.参见
In more common case (if the data are not only in one partition) one should use SUM(rows)
instead of rows
. See
我想人们可以以相同的方式使用sys.dm_db_partition_stats
I suppose that one could use in the same way sys.dm_db_partition_stats
SELECT row_count
FROM sys.dm_db_partition_stats
WHERE index_id IN (0, 1) AND object_id = OBJECT_ID('dbo.Tablename')
您可以检查数据库并测试COUNT(*)
是否返回上述SQL语句中相同的值或某些其他接近的变体.
You can examine your database and test whether COUNT(*)
returns the same values line the above SQL statements or some other close variants.
独立于COUNT(*)
的问题,您可以使用定义为函数的records
或total
,而不会从服务器返回任何records
或total
. records
在大多数情况下根本不重要.如果使用viewrecords: true
选项,它将显示在寻呼机上.您可以使用默认的viewrecords: false
,并且在服务器响应中设置records
字段没有问题.
Independent from the problem with COUNT(*)
you can use records
or total
defined as functions and don't return any records
or total
from the server. The records
is not important in the most cases at all. It will be displayed on the pager if viewrecords: true
option is used. You can use default viewrecords: false
and to have no problem with setting the records
field in the server response.
服务器响应的total
属性将在另一侧用于设置jqGrid的lastpage
参数,该参数将用于验证是否将分页器的下一页"和最后一页"按钮是否启用.您可以做的是
The total
property of the server response will be used on the other side to set lastpage
parameter of jqGrid, which will be used to verify whether "Next Page" and "Last Page" buttons of the pager will be enabled or not. What you can do is
jsonReader: {
total: function (response) {
return parseInt(response.page) + 1;
}
}
或者,您可以返回任何其他值,例如Number.MAX_VALUE
或最大整数9007199254740992
(2 53 ,请参见
alternatively you can return any other value like Number.MAX_VALUE
for example or max integer 9007199254740992
(253, see the answer).
这篇关于免费的jqGrid 4.8.0-设置分页发布网格重新加载的总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!