Front end pagination with search box

266 views
Skip to first unread message

Erik Jorgensen

unread,
Jan 14, 2014, 4:45:28 PM1/14/14
to joomla-de...@googlegroups.com
Hi,

I'm developing a publications component that needs a front end list view with pagination and search ability. I'm using code that works in the back end based on the Folio example from the "Learning Joomla! 3 Extension Development 3rd Ed." book which has those features in the back end list view. It almost works except there seems to be a conflict between the search box and pagination. If I don't enter anything in the search box pagination works fine. If I do a search, I get the results back ok, but then pagination does not work. It will not move off page 1. This happens even if I remove the search portion from the SQL query in the model. The query does not seem to be the problem. I've done a dump of the state object and I see that the "list.start" is not picking up the value from the request when there's search term in the search box. It stays at ["list.start"]=> float(0). I've tried assigning the value in the model class's populateState method with this code but it has no effect even if I put a number directly into the setState function.

                // THIS DOESN'T HAVE ANY EFFECT EVEN IF SET LITERALLY
                $limitstart = $this->getUserStateFromRequest($this->context.'list.start', 'list_start');
                $this->setState('list.start', $limitstart);

I think somewhere in Joomla's core classes (JModelList, JModelLegacy or JOject) things are breaking down. Has anyone run into this problem before or have a clue where I should look? Something about having an input box with a search term in it breaks pagination.

Thanks.

Erik

Erik Jorgensen

unread,
Jan 14, 2014, 6:27:32 PM1/14/14
to joomla-de...@googlegroups.com
Update:

I discovered that statements in the parent class JModelList's method populateState shold handle getting the list.start value from the request and set it in the state. This was overriding what I had in my populateState method in my own model class. Here's the relevant code from JModelList:

            $app = JFactory::getApplication();

            $value = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'uint');
            $limit = $value;
            $this->setState('list.limit', $limit);

            $value = $app->getUserStateFromRequest($this->context . '.limitstart', 'limitstart', 0);
            $limitstart = ($limit != 0 ? (floor($value / $limit) * $limit) : 0);

            $this->setState('list.start', $limitstart);

Where things still fail is in the getUserStateFromRequest method. It should be finding the limitstart value in the $app data. It does not get set when there is a "search" value present. I'm not sure how the limitstart value gets from "?start=20" in the URL to "["limitstart"]=> int(20) in the $app data returned from JFactory::getApplication();

Getting closer I think. Any help would be appreciated.

Erik

Erik Jorgensen

unread,
Jan 14, 2014, 7:02:46 PM1/14/14
to joomla-de...@googlegroups.com
Another clue:

I discovered that the navigation links are rendered quite differenly in the front end vs the back end:

Front end:
<li><a href="/pubs/pubs.html?start=20" class="pagenav">2</a></li>

Back end:
<li><a href="#" onclick="document.adminForm.limitstart.value=5; Joomla.submitform();return false;">2</a></li>

Erik

Erik Jorgensen

unread,
Jan 21, 2014, 5:47:13 PM1/21/14
to joomla-de...@googlegroups.com
A friend of mine finally helped me figure out the solution. In my populateState function in my model class I had a parent::populateState function call at the end of my code. This needed to be called at the beginning so my statements would override the ones in the parent class. I moved that call to the top of my populateState fuction and included these statements after.

                $this->limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'uint');
                $this->limitstart = JRequest::getVar('start', 0, '', 'int');
                $this->setState('list.start', $this->limitstart);

Now pagination is working correctly with my search box.

Erik


Reply all
Reply to author
Forward
0 new messages