JPagination->getLimitBox() custom limits

1,482 views
Skip to first unread message

Viper

unread,
May 2, 2013, 4:27:10 AM5/2/13
to joomla-...@googlegroups.com
Hi!
Some peoples(me too) needs to custom limits in their pagination, but we cannot override these limits 'cause it's hardcoded. See the topic https://groups.google.com/forum/#!topic/joomla-dev-general/nyZDKxeNLe4

My suggestion: add input parameters to the method and small changes in code.

$start - from that number we start
$total - max number
$step - increment by $step
$extra - additional values 50 and 100(basically these values do not needed for small lists)
$all - if set to true when the "show all" value will be added to the end of the list

public function getLimitBox($start=5, $total=30, $step=5, $extra=true, $all=true)
{
    $app = JFactory::getApplication();
    $limits = array();

    // Make the option list.
    for ($i = $start; $i <= $total; $i += $step)
    {
        $limits[] = JHtml::_('select.option', "$i");
    }

    if ($extra) {
        $limits[] = JHtml::_('select.option', '50', JText::_('J50'));
        $limits[] = JHtml::_('select.option', '100', JText::_('J100'));
    }

    if ($all) {
        $limits[] = JHtml::_('select.option', '0', JText::_('JALL'));
    }

    $selected = $this->viewall ? 0 : $this->limit;

    // Build the select list.
    if ($app->isAdmin())
    {
        $html = JHtml::_(
            'select.genericlist',
            $limits,
            $this->prefix . 'limit',
            'class="inputbox input-mini" size="1" onchange="Joomla.submitform();"',
            'value',
            'text',
            $selected
        );
    }
    else
    {
        $html = JHtml::_(
            'select.genericlist',
            $limits,
            $this->prefix . 'limit',
            'class="inputbox input-mini" size="1" onchange="this.form.submit()"',
            'value',
            'text',
            $selected
        );
    }
    return $html;
}

Is it possible to include these fixes in future releases of Joomla?

PS! And it maybe we need an array as $extra so we could build list of values via for() ?

Viper

unread,
May 2, 2013, 5:47:57 AM5/2/13
to joomla-...@googlegroups.com
Some small changes. Now we could pass the array of elements and build a list.

public function getLimitBox($list_values=array(), $all=true)

{
    $app = JFactory::getApplication();
    $limits = array();

    // Make the option list.
    for ($i=0, $n=count($list_values); $i<$n; $i++) {
        $limits[] = JHtml::_('select.option', $list_values[$i]);

Ove

unread,
May 3, 2013, 4:48:50 AM5/3/13
to joomla-...@googlegroups.com, Viper
+1
As is, with 10.000+ items I have two possibilities for the frontend .
*** Do not use use the Limit Box at all or *** use an override for the
JPagination method.
Not very wise to allow Show All for public users.

And sorry I'm not the best friend of overrides and plugins all over the
place.

Ove




Mathew Lenning

unread,
May 4, 2013, 2:13:25 AM5/4/13
to joomla-...@googlegroups.com
Hey Ove,

I ran into the same problem with a custom dictionary component that had 10k+ entries, but instead of messing with overrides, I was able to remove the show all with a small JS script.

I'm away from my desk at the moment, so I can't post the code, but it was all of 6 lines, so I'm sure you could figure it out with no problems.

Although for browsers with JS disabled you'll still have the all option, it beats having to maintain another class override.

Viper

unread,
May 4, 2013, 11:09:49 AM5/4/13
to joomla-...@googlegroups.com
The idea is to make the appropriate changes in JPagination class of Joomla CMS/Framework for future releases.
'Cause writing crutches for core classes is very bad idea. The developer of components(or something else) based on JCMS/FW doesn't have a time and the wish to make changes in core.

George Wilson

unread,
May 5, 2013, 4:05:46 AM5/5/13
to joomla-...@googlegroups.com
Sounds like a good idea to me. Make a pull request with you're code changes on GitHub and create a feature request here: http://joomlacode.org/gf/project/joomla/tracker/

Then people will review it and make suggestions as to where to improve it :) As I'm sure you know though as we're halfway through the 3.x cycle you need to make sure whatever code that you submit is backwards compatible with whatever is currently in the 3.x series! If possible without too much work backport it into the 2.5 series as well.

Kind Regards,
George

piotr_cz

unread,
May 8, 2013, 4:26:19 AM5/8/13
to Joomla! CMS Development
Hi.
Customer wants a button ('show all'/ 'show 8') instead of drop-down
box, designer doesn't understand what's so hard about it :)

Fortunately pagination is within custom component, so I resolved it
like so:

In model (extends JModelList), method getPagination checks for
JPagination override in template folder and if it exists, uses that
one. if not, calls parent method which uses native JPagination.

class JPaginationOverride extends JPagination,
function getLimitBox() has access to everything I need.


IMHO template should have an option to choose how to render pagination
limitbox, just like it has with page numbers.
Reply all
Reply to author
Forward
0 new messages