使用SQL Server和JQgrid的分页问题,

时间:2018-12-28 15:40:14

标签: sql sql-server coldfusion jqgrid

我有以下代码,在查询中,我尝试获取前500条记录,然后获取下500条,依此类推。

这是我的代码,我无法确定应在什么地方进行更改以使其起作用

<cffunction name="queryConvertForJQGRID" access="package" returntype="struct" output="no"> 
    <cfargument name="q" type="query" required="yes"> 
    <cfargument name="page" type="numeric" required="no" default="1"> 
    <cfargument name="rows" type="numeric" required="no" default="10"> 
    <cfset var result = structnew()> 
    <cfset var rowStruct = structnew()> 
    <cfset var col = ""> 
    <cfset result["page"] = arguments.page> 
    <cfset result["total"] = ceiling(arguments.q.recordcount/arguments.rows)> 
    <cfset result["records"] = arguments.q.recordcount> 
    <cfset result["rows"] = arraynew(1)> 
    <cfoutput query="arguments.q" startrow="#(arguments.page-1)*arguments.rows+1#" maxrows="#arguments.rows#"> 
      <cfset rowStruct = structnew()> 
      <cfset rowStruct['viewed'] = viewed>
      <cfset rowStruct['id'] = q['id'][currentrow]> 
      <cfset rowStruct['status'] = q['status'][currentrow]> 
      <cfset rowStruct['template'] = q['template'][currentrow]> 
      <cfset rowStruct['line'] = q['line'][currentrow]>
      <cfset rowStruct['error_message'] = q['error_message'][currentrow]>
      <cfset rowStruct['error_type'] = q['error_type'][currentrow]>
      <cfset rowStruct['datein'] = q['datein'][currentrow]> 
      <cfset arrayappend(result.rows, rowStruct)> 
    </cfoutput>
    <cfreturn result /> 
  </cffunction>

  <cffunction name="getgrouped" returntype="any" access="remote" output="false">
    <cfargument name="table" required="true" default="errors">
    <cfargument name="usedsn" default="" required="true">
    <cfargument name="callback" default="" required="false">
    <cfargument name="page" required="no" default="1">
    <cfargument name="rows" required="no" default="500">
    <cfargument name="sidx" required="no" default="">
    <cfargument name="sord" required="no" default="ASC">
    <cfargument name="acelem" required="no" type="any">
    <cfset var dsn = dsnSettings(arguments.usedsn)>
    <cfset var groupedget = "">
    <cfset var result = structnew()> 
    <cfset var rowStruct = structnew()> 
    <cfset var col = ""> 
    <cfset result["rows"] = arraynew(1)> 
    <cfquery name="groupedget" datasource="#dsn#">
        WITH List AS (
            SELECT row_number() over(ORDER BY mi.id) AS rowNum 
                , viewed
                , status
                , mi.errorid
                , FORMAT(datein, 'MMMM d, yyyy h:mm:ss tt PST', 'en-US') AS datein
                , mi.error_message
                , upper(mi.error_type) AS error_type
                , mi.line
                , mi.template
                , mi.id
            FROM #arguments.table# mi
        )
        , ListRecordCount AS (
            SELECT *
            FROM List , ( SELECT MAX(rowNum) AS recordCount FROM List ) recordCount
        )
        SELECT *
        FROM ListRecordCount
        WHERE rowNum BETWEEN #page# AND #rows#
    </cfquery>
    <cfset q = groupedget>
    <cfreturn queryConvertForJQGRID(q, arguments.page, arguments.rows)>
  </cffunction>

但是它只查询500行,仅此而已,JQgrid中不再发生分页。

0 个答案:

没有答案