我对 ColdFusion 很陌生,我想问一下我的代码。我正在尝试在 ColdFusion 中创建一个带有过滤和分页的页面。我已经取得了一些进展,但不幸的是,当我的页面刷新时,使用文本字段进行的所有过滤都不会延续到下一页。
这是我的过滤代码:
<cfparam name = "site_name" default = ""/>
<cfparam name = "site_cat" default = ""/>
<cfparam name = "site_region" default = ""/>
<cfparam name = "site_area" default = ""/>
<cfparam name = "query_condition" default = ""/>
<cfset flcr = StructNew()/>
<cfset flcr.site_name = "#site_name#"/>
<cfset flcr.site_cat = "#site_cat#"/>
<cfset flcr.site_region = "#site_region#"/>
<cfset flcr.site_area = "#site_area#"/>
<cfif StructKeyExists(Form,"btn_search")>
<cfloop collection = "#flcr#" item = "key">
<cfif #len(trim(flcr[key]))# gt 0>
<cfset queryCases = ["SITE_NAME","SITE_CAT","SITE_REGION","SITE_AREA"]/>
<cfif #arraycontains(queryCases,key)# eq "yes">
<cfif #len(trim(query_condition))# gt 0>
<cfset query_condition &= " AND "/>
<cfelse>
<cfset query_condition &= " WHERE "/>
</cfif>
</cfif>
<cfswitch expression = #key#>
<cfcase value = "SITE_NAME">
<cfset site_name = "#flcr[key]#"/>
<cfset query_condition &= "site_name LIKE '#flcr[key]#%'" />
</cfcase>
<cfcase value = "SITE_CAT">
<cfset site_cat = "#flcr[key]#"/>
<cfset query_condition &= "site_type LIKE '#flcr[key]#%'"/>
</cfcase>
<cfcase value = "SITE_REGION">
<cfset site_region = "#flcr[key]#"/>
<cfset query_condition &= "region = '#flcr[key]#'"/>
</cfcase>
<cfcase value = "SITE_AREA">
<cfset site_area = "#flcr[key]#"/>
<cfset query_condition &= "area = '#flcr[key]#'"/>
</cfcase>
</cfswitch>
</cfif>
</cfloop>
</cfif>
<cfset viewAll = "SELECT * FROM tblcellsites" & #query_condition#/>
<cfset orderBy = " ORDER BY site_count"/>
<cfset final_sql = #viewAll# & #orderBy#/>
<cfset final_final_sql = #replace(final_sql,"'","''","all")#/>
<cfset filterQuery = #site.filterQuery(final_sql)#/>
分页
<table class="table">
<thead class="thead-light">
<tr>
<th scope="col">Site Count</th>
<th scope="col">Site Name</th>
<th scope="col">Region</th>
<th scope="col">Area</th>
<th scope="col">Site Type</th>
</tr>
</thead>
<tbody>
<cfparam name = "pageNum" default = "1"/>
<cfset viewAllSite = #filterQuery#/>
<cfset maxRows = 10/>
<cfset startRow = min( ( pageNum-1 ) * maxRows+1, max( viewAllSite.recordCount,1 ) )/>
<cfset endRow = min( startRow + maxRows-1, viewAllSite.recordCount )/>
<cfset totalPages = ceiling( viewAllSite.recordCount/maxRows )/>
<cfset loopercount = round( viewAllSite.recordCount/10 )/>
<cfoutput query="viewAllSite" startrow="#startRow#" maxrows="#maxRows#">
<tr>
<td>#site_count#</td>
<td>#site_name#</td>
<td>#region#</td>
<td>#area#</td>
<td>#site_type#</td>
</tr>
</cfoutput>
</tbody>
</table>
<!-- Table Content -->
</div>
<!-- Pagination -->
<div class = "row" align = "center">
<div class = "col-md-12">
<cfoutput>
<cfloop from="1" to="#looperCount#" index="i">
<span id="#i#" class="current-page"><input type ="submit" name = "btn_page" value ="#i#"></span>
</cfloop>
</cfoutput>
</form>
</div>
</div>
<!-- Pagination -->
我希望过滤器能够转移到下一页,但是当我将过滤器和查询条件附加pageNum
到我的 URL 时,过滤器和查询条件的变量似乎被清除了。
先感谢您。