please help me, I'm making a simple component to display a query from a table in the database. on these components I add a dropdown list that serves as a filter query on the table to be displayed and use the pagination. The problem is when the table show the pagination, and we choose the pagination numbers "1,2,3" characterized by "limitstart = 5 or 10 or more" followed by the selection of dropdownlist filter on the query results are not as expected because of problems in the variable "limitstart = 5/10 / other" can not be reset to "limitstart = 0". for more details please see my website at:
http://lamandaukab.bps.go.id/index.php/publikasi/advance-release-calendar-arc-betaI show the following Class Arc Model, View, and tpl
Code:
class ArcsModelArcs extends JModel
{
/**
* Hellos data array
*
* @var array
*/
var $_data;
/**
* Items total
* @var integer
*/
var $_total = null;
/**
* Pagination object
* @var object
*/
var $_pagination = null;
function __construct()
{
global $mainframe;
parent::__construct();
$config = JFactory::getConfig();
// Get the pagination request variables
$this->setState('limit', $mainframe->getUserStateFromRequest('com_arc.limit', 'limit', $config->getValue('config.list_limit'), 'int'));
$this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int'));
//$this->setState('years', JRequest::getWord('years'));
//$this->setState('terbitan', JRequest::getWord('terbitan'));
}
/**
* Returns the query
* @return string The query to be used to retrieve the rows from the database
*/
function _buildQuery()
{
// Get the WHERE and ORDER BY clauses for the query
$where = $this->_buildContentWhere();
$query = ' SELECT a.* FROM #__arc AS a '
.$where
.' ORDER BY a.terbit_tanggal'
;
return $query;
}
function _buildContentWhere()
{
global $mainframe, $option;
$db =& JFactory::getDBO();
$years = $mainframe->getUserStateFromRequest( 'com_arc.years', 'years', '', 'string' );
$terbitan = $mainframe->getUserStateFromRequest( 'com_arc.terbitan', 'terbitan', '', 'string' );
$where = array();
if ($years) {
$where[] = 'LOWER(a.terbit_tanggal) LIKE '.$db->Quote( '%'.$db->getEscaped( $years, true ).'%', false );
}
if ($terbitan) {
$where[] = 'LOWER(a.periode) LIKE '.$db->Quote( '%'.$db->getEscaped( $terbitan, true ).'%', false );
}
$where = ( count( $where ) ? ' WHERE '. implode( ' AND ', $where ) : '' );
return $where;
}
/*
return total rows..
*/
function getTotal()
{
// Load the content if it doesn't already exist
if (empty($this->_total)) {
$query = $this->_buildQuery();
$this->_total = $this->_getListCount($query);
}
return $this->_total;
}
function getPagination()
{
// Lets load the content if it doesn't already exist
if (empty($this->_pagination))
{
jimport('joomla.html.pagination');
$this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
}
return $this->_pagination;
}
/**
* Retrieves the data
* @return array Array of objects containing the data from the database
*/
function getData()
{
// Lets load the data if it doesn't already exist
if (empty( $this->_data ))
{
$query = $this->_buildQuery();
$this->_data = $this->_getList( $query, $this->getState('limitstart'), $this->getState('limit') );
}
return $this->_data;
}
}
View Class
Code:
class ArcsViewArcs extends JView
{
/**
* Hellos view display method
* @return void
**/
function display()
{
global $mainframe, $option;
$lists = array();
// Get data from the model n throw it to template (default.php)
$items = & $this->get('Data');
// get pagination from the model
$pagination = & $this->get('Pagination');
$filter_years = $mainframe->getUserStateFromRequest( $option.'years', 'years');
$filter_terbitan = $mainframe->getUserStateFromRequest( $option.'terbitan','terbitan');
$years[] = JHTML::_('select.option','',JText::_('---pilih tahun--'));
for ($i=2011; $i<= date('Y'); $i++) {
$years[] = JHTML::_('select.option',$i,JText::_($i));
}
$terbitan[] = JHTML::_('select.option','',JText::_('---pilih periode---'));
$terbitan[] = JHTML::_('select.option','Tahunan',JText::_('Tahunan'));
$terbitan[] = JHTML::_('select.option','Bulanan',JText::_('Bulanan'));
$terbitan[] = JHTML::_('select.option','Mingguan',JText::_('Mingguan'));
$lists['years'] = JHTML::_('select.genericlist', $years, 'years', 'class="inputbox"', 'value', 'text',$filter_years);
$lists['terbitan'] = JHTML::_('select.genericlist', $terbitan, 'terbitan','class="inputbox"','value','text',$filter_terbitan);
$this->assignRef('pagination', $pagination);
$this->assignRef('items', $items);
$this->assignRef('lists', $lists);
parent::display();
}
}
template default.php
Code:
<?php defined('_JEXEC') or die('Restricted access'); ?>
<form action="<?php echo JRoute::_( 'index.php?option=com_arc' );?>" method="get" name="userForm">
<div id="editcell">
<table >
<tr>
<th align="left"><?php echo JText::_( 'Pilih Tahun' ); ?>:
<?php echo $this->lists['years']; ?></th>
<th align="left"><?php echo JText::_( 'Pilih Periode Terbit' ); ?>:
<?php echo $this->lists['terbitan']; ?></th>
<th> <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button></th>
</tr>
</table>
<table class="userlist" width="100%">
<thead>
<tr>
<th width="5">
<?php echo JText::_( 'No' ); ?>
</th>
<th>
<?php echo JText::_( 'Judul' ); ?>
</th>
<th>
<?php echo JText::_( 'Periode Terbit' ); ?>
</th>
<th>
<?php echo JText::_( 'Tanggal Terbit' ); ?>
</th>
<th>
<?php echo JText::_( 'Status' ); ?>
</th>
</tr>
</thead>
<?php
$k = 0;
for ($i=0, $n=count( $this->items ); $i < $n; $i++) {
$row = &$this->items[$i];
?>
<tr class="<?php echo "row$k"; ?>">
<td>
<?php echo $this->pagination->getRowOffset( $i ); ?>
</td>
<td>
<?php echo JHTML::_('link',$row->link_judul, $row->judul); ?> </a>
</td>
<td>
<?php echo $row->periode; ?>
</td>
<td>
<?php echo $row->terbit_tanggal; ?>
</td>
<td>
<?php echo $row->status; ?>
</td>
</tr>
<?php
$k = 1 - $k;
}
?>
<tfoot>
<tr>
<td colspan="13">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
</table>
</div>
<input type="hidden" name="task" value="arc" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
I've tried to imitate the weblinks component and search but to no avail. please for the joomla master to help me how to make limitstart to "0" when making the request a new page so that the query can be generated accordingly.
thanks,. sory if my english is bad.. i'm from indonesia.. tks..