I have a fairly straightforward front end List display with pagination and headings that can sort columns and navigate to a different page number and everything works as expected. The URL for the page is mysite/stock-request
and for any of the pagination or heading links the URL target is mysite/stock-request#
created by this JS being used under a heading link,
onclick="Joomla.tableOrdering('a.Description','asc','');return false;"
I mention the JS as I did find a thread somewhere mentioning that if JS was involved things happen a bit differently but now that I am looking for it I can find it.
My menu item link to get to the View is specified as this
index.php?option=com_inventory&view=stockrequests
I have added a couple of extra Input fields to each line on the list to allow the end-user to adjust a stock quantity inline and when I have these lines in the bottom of the <form>
and it is the addition of task field and in particular coming back from the 'process' method that the problems begins.
<input type="hidden" name="task" value="stockrequests.process"/>
<input type="hidden" name="view" value=""/>
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>"/>
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>
Each time the user navigates to a different page or changes the sort order the <form>
is submited and the subcontroller 'stockrequests' is called and task 'process' is run, all still working as expected. I am extending JControllerForm in 'stockrequests' and a check of the variable $_POST for limit and limistart show the updated values are there and getUserState shows the values for the selected ordering is available.
[filter_order] => a.OrderQty [filter_order_Dir] => asc
Now my problem begins, I think, with the way I am trying to go back to the View. I have tried various techniques I have found with no success but these are the two I keep coming back to.
//$this->setRedirect('index.php?option=com_inventory&view=stockrequests?&limitstart=' . $_POST['limitstart']);
$this->setRedirect('index.php?option=com_inventory&view=stockrequests');
When I get back the View the URL is no longer myste/stock-request
but mysite/index.php?option=com_inventory&view=stockrequests
and the limit setting values are what they were before the end-user caused the page to change if I don't supply them via the limistart parm that is commented out. While the ordering settings have gone back to the defaults specified in the model.
[list.limit] => 20
[list.start] => 0
[list.ordering] => a.ItemCode
[list.direction] =>
What I am hoping to achieve is to come back to the View with the values for list ordering or page navigation that were set when I left the View are used to display the next page or sort the list differently.
Initially I thought it was some issue with UserState or State but as I can see they are set correctly while still in the subController I am guessing it is some issue with the approach for getting back to the View that it is treating it as new View or is not correctly getting the updated values.
Keeping in mind that the limit and limitstart value are what they were before the task is called, not the new values in $_Post array when in the 'process' task, suggesting something is remembered or passed through. While the List ordering goes back to he default settings suggesting it is treating it as a new or different View display.
I have figured out some hack work arounds but I have spent more than a days worth of effort trying to make this work as I want to use the inline editing elsewhere in this extension so any suggestions or pointers in the right direction will be much appreciated.
Other related items might be this in the stockrequest model.
public function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$list = $app->getUserState($this->context . '.list');
echo "<pre> Ordering settings ..."; print_r($ordering);"</pre>";
$ordering = isset($list['filter_order']) ? $list['filter_order'] : null;
$direction = isset($list['filter_order_Dir']) ? $list['filter_order_Dir'] : null;
$list['limit'] = '0'; // (int) Factory::getConfig()->get('list_limit', 20);
$list['start'] = $app->input->getInt('start', 0);
$list['ordering'] = $ordering;
$list['direction'] = $direction;
echo "<pre> List settings 2..."; print_r($list);"</pre>";
$app->setUserState($this->context . '.list', $list);
$app->input->set('list', null);
// List state information.
parent::populateState('a.ItemCode', 'asc');
$context = $this->getUserStateFromRequest($this->context . '.context', 'context', 'com_inventory.stockrequests', 'CMD');
$this->setState('filter.context', $context);
echo "<pre> Context settings ..."; print_r($this->context);"</pre>";
// Split context into component and optional section
$parts = FieldsHelper::extract($context);
if ($parts)
{
$this->setState('filter.component', $parts[0]);
$this->setState('filter.section', $parts[1]);
}
And this from the top of my form
<!-- action="<?php // echo JRoute::_('index.php?option=com_inventory&task=stockrequests.process&view=stockrequests'); ?>" -->
<form action="<?php echo htmlspecialchars(JUri::getInstance()->toString()); ?>"
method="post"
name="adminForm"
id="adminForm">
<?php echo JLayoutHelper::render('default_filter', array('view' => $this), dirname(__FILE__)); ?>