質問

I'm using dopefly's Pagination.cfc to create Pagination on a site I'm building, however I can't get it to react specifically how I want it to.

I'm trying to get it so it starts like this

*1* 2 3 4 ... x        
1 *2* 3 4 ... x        
1 2 *3* 4 ... x         
1 2 3 *4* ... x         
1 ... 4 *5* 6 7 ... x  

So it will always display 4 in the middle, with the first and last pages showing at the end when appropriate.

However, at the moment it is going

*1* 2 3 4 ... x
1 *2* 3 4 5 ... x
1 2 *3* 4 5 6 ... x
1 2 3 4 *5* 6 7 ... x
1 2 3 4 5 *6* 7 8 ... x
1 ... 3 4 5 6 *7* 8 9 ... x
1 ... 4 5 6 7 *8* 9 10 ... x

So it keeps going until there is 8 that are displayed, then it will start keeping 7 in the middle, rather than staying with 4, then when we hit the 5th page displaying 4 in the middle at all times with the first/last at the end.

e: I've tried playing about with the setNumericEndBufferCount() and setNumericDistanceFromCurrentPageVisible() variables defined in the documentation, however my knowledge of cfc's and how they behave isn't expansive enough to modify the actual cfc (like duncan suggested below).

役に立ちましたか?

解決

Joshua, Thanks for using my Pagination library! Sorry it's not acting exactly as you had hoped. Your issue looks similar to a feature request posted recently, requesting a setFixedMaximumNumbersShown option but with some sort of bouncy counting and some elasticity somewhat like Amazon's pagination, but as you noticed, it only grows as you page through your records. You can fix this yourself, but you will have to stretch your limits of CFC use a bit.

The solution is to create a component (let's call it bouncyPagination.cfc) that extends my component, Pagination.cfc. You will need to override at least one method to accomplish your task. You can read the documentation on Extending Pagination.cfc first, it may help. Your code will look something like this.

<cfcomponent extends="Pagination">
    <cffunction name="renderNumericLinksHTML">
        <!--- Your improved bouncy numeric links HTML generation here --->
        <!--- Start by copying & pasting code from the matching --->
        <!--- renderNumericLinksHTML method in Pagination.cfc --->
    </cffunction>
</cfcomponent>

Take a look at the code in Pagination.cfc, in the renderNumericLinksHTML function. Start yourself off by copying and pasting, then rewrite the way BouncyPagination.cfc writes those numeric links based on whatever logic you want. You can even add some methods to get and set the boundaries of your numbers, in your example, 4 was the magic number. I would imagine you would add something like this to your component.

<!--- Set your new parameter's default by overriding the init method --->
<cffunction name="init">
    <cfset variables.my.BouncyBounds = 4 />
    <return super.init() />
</cffunction>

<!--- Create getter/setter. Note the rendered=false is a flag to force HTML recomposition when a UI option changes. --->
<cffunction name="getBouncyBounds">
    <cfreturn variables.my.bouncyBounds />
</cffunction>
<cffunction name="setBouncyBounds">
    <cfargument name="_BouncyBounds" type="string" />
    <cfset variables.my.BouncyBounds = arguments._BouncyBounds/>
    <cfset variables.my.rendered = false />
</cffunction>

Your new renderNumericLinksHTML method would call getBouncyBounds() to programmatically change the boundaries of your newer bouncy pagination method.

I hope that helps you -- this is as far as I go without doing your homework for you. If you write something that works well for you, and you can share with a BSD license, send me the code and I will include it in the next release.

他のヒント

From the documentation it sounds like you could achieve this by using NumericDistanceFromCurrentPageVisible. The problem is that indicated how many links to use either side of the current link. So you could set it to 2 and it would display 2 links either side of the current, i.e. groups of 5. To achieve a group of 4 you'd have to display 1 link before and 2 links after (or vice versa)... or 3 links after or before if you're at the start or end of the list of links.

Suggest you delve into the CFC itself, see how it handles NumericDistanceFromCurrentPageVisible, and see if you could extend this to take 2 parameters for number of links to display before/after. Or alternatively, modify it to use that parameter as a basis for how many links to display in total in a group.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top