PHPEveryday.com PHP and Web Development Tutorial
What are you looking for?


PHP Error Message

Warning: Invalid argument supplied for foreach() in /home/a3178292/public_html/article.php on line 213

Free Web Hosting

Joomla - Component: Creating Advance List Screen


Now, we will make up list and give more power. We will add function like paginating, search box, and ordering.

Joomla: Advance list table

Replace showHello() in "admin.hello.html.php" file with following code:

	function showHello(&$rows, &$pageNav, &$lists){

		JHTML::_('behavior.tooltip');	
	?>
	<form action="index.php?
option=com_hello" method="post" name="adminForm">
    
		<table>
		<tr>
			<td align="left" width="100%">
				<?php echo JText::_( 'Filter' ); ?>:
				<input type="text" name="search" id="search" 
value="<?php echo $lists['search'];?>" 
class="text_area" onchange="document.adminForm.submit();" />
				<button onclick="this.form.submit();">
<?php echo JText::_( 'Go' ); ?></button>
				<button onclick="document.getElementById('search').value='';this.form.submit();">
<?php echo JText::_( 'Reset' ); ?></button>
			</td>
		</tr>
		</table>    
    
        
    <table class="adminlist">
    <thead>
    	<tr>
        	<th width="20">
            <input type="checkbox" name="toggle"
 value="" onclick="checkAll(<?php echo count($rows)?>)">
            </th>
            <th width="50" class="title">
<?php echo JHTML::_('grid.sort',   'ID', 'id', @$lists['order_Dir'], @$lists['order'] ); ?></td>
            <th><?php echo JHTML::_('grid.sort',   
'Message', 'message', 
@$lists['order_Dir'], @$lists['order'] ); ?></th>
            <th nowrap="nowrap"><?php echo JHTML::_('grid.sort',   'Published', 'published', 
@$lists['order_Dir'], @$lists['order'] ); ?></th>
        </tr>
    </thead>
	<tfoot>
		<tr>
			<td colspan="11">
			 <?php echo $pageNav->getListFooter(); ?>
			</td>
		</tr>
	</tfoot>
                
    <?php
    $k = 0;
	for($i=0, $n=count($rows); $i < $n ; $i++)
	{
		$row = &$rows[$i];
		$checked 	= JHTML::_('grid.id', $i, $row->id);
		$published 	= JHTML::_('grid.published', $row, $i); 
		?>
        <tr class="<?php echo "row$k"; ?>">
        	<td><?php echo $checked?></td>
        	<td><?php echo $row->id?></td>
        	<td><?php echo $row->message?></td>            
        	<td><?php echo $published?></td>            
        </tr>
        <?
		$k = 1 - $k;
	}
	?>
    </table>
    <input type="hidden" name="option" value="com_hello">
    <input type="hidden" name="task" value="">    
    <input type="hidden" name="boxchecked" value="0"> 
	<input type="hidden" name="filter_order" 
value="<?php echo $lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="" />       
    </form>
    <?php
}

Then, replace showHello() in "admin.hello.php" file with following code:

function showHello(){
	global $mainframe;
	
    $db =& JFactory::getDBO();
	
	$filter_order= $mainframe->
        getUserStateFromRequest( $option.'filter_order',
            'filter_order','id','cmd' );
	$filter_order_Dir= $mainframe->
        getUserStateFromRequest( $option.'filter_order_Dir',	
       'filter_order_Dir','','word' );
	$filter_state = $mainframe->
       getUserStateFromRequest( $option.'filter_state', 	'filter_state', '','word' );
	$search = $mainframe->
        getUserStateFromRequest( $option.'search',
        'search','','string' );
	$search = JString::strtolower( $search );

	$limit= $mainframe->
        getUserStateFromRequest('global.list.limit', 
        'limit', $mainframe->getCfg('list_limit'), 'int');
	$limitstart= $mainframe->
        getUserStateFromRequest($option.'.limitstart', 
'limitstart', 0, 'int');

	$where = array();

	if ( $search ) {
		$where[] = 'message LIKE "%'.$db->getEscaped($search).'%"';
	}	
	
	$where 		= ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
	if ($filter_order == 'id'){
		$orderby 	= ' ORDER BY id';
	} else {
		$orderby 	= ' ORDER BY '. 
         $filter_order .' '. $filter_order_Dir .', id';
	}	
	
	// get the total number of records
	$query = 'SELECT COUNT(*)'
	. ' FROM #__hello'
	. $where
	;
	$db->setQuery( $query );
	$total = $db->loadResult();

	jimport('joomla.html.pagination');
	$pageNav = new JPagination( $total, $limitstart, $limit );	
	
	
	$query = "SELECT * FROM #__hello". $where. $orderby;
	$db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
	$rows = $db->loadObjectList();
	if($db->getErrorNum()){
		echo $db->stderr();
		return false;
	}
	
	// table ordering
	$lists['order_Dir']	= $filter_order_Dir;
	$lists['order']		= $filter_order;	

	// search filter	
        $lists['search']= $search;	
	
    // display function
	HTML_contact::showHello(&$rows, &$pageNav, &$lists);
}


Series this article:
Joomla - Component: Create Hello World Component on Front End
Joomla - Component: Create Hello World Component on Back End
Joomla - Component: Registering Your Component in database
Joomla - Component: Create Component Link for Front End
Joomla - Component: Creating Toolbars
Joomla - Component: Available Toolbar Buttons
Joomla - Component: Creating the Database Table
Joomla - Component: Creating Form Input Data at Back End
Joomla - Component: Saving Data to Database
Joomla - Component: Creating a List Screen
Joomla - Component: Creating Advance List Screen
Joomla - Component: Editing Data
Joomla - Component: Deleting Data
Joomla - Component: Updating publish state
Joomla - Component: Hello From Database at Front End
Joomla - Component: a Hello page
Joomla - Component: Generating Friendly Links
Joomla - Component: Adding Comment ( Create Table )
Joomla - Component: Adding Comment (Create Form)
Joomla - Component: Adding Comment ( Insert Data )
Joomla - Component: Adding Comment ( Displaying Comments )
Joomla: Fast Road to Understand Component Programming


Tag: joomla, cms, Joomla Component Category: PHP Framework Post : November 05th 2007 Read: 14,745 Bookmark and Share

blog comments powered by Disqus


Database Tutorial
  • Learn PHP MySQL
  • Learn PHP ADOdb
  • Learn PHP Data Object/PDO
  • Learn PHP XML
  • Learn PHP SimpleXML
Security Tutorial
  • Learn PHP Security
  • Learn HTTP Authentication
  • Learn PHPSecureSite
Framework Tutorial
  • Learn CodeIgniter
  • Learn Joomla
  • Learn Smarty
  • Learn Zend Framework
Template Tutorial
  • Learn Joomla Template
  • Learn WordPress Template
API Tutorial
  • Learn Facebook
JS Framework Tutorial
  • Learn MooTools
  • Learn JQuery
AJAX Tutorial
  • Learn AJAX in 10 Minutes
  • Learn AJAX Client Side
  • Learn AJAX PHP
  • Learn AJAX Remote Server
  • Learn AJAX Repetitive
  • Learn AJAX MySQL
  • Learn AJAX Grid
Web Services Tutorial
  • Learn Web Services NuSOAP
  • Learn Web Services WSDL
  • Learn Web Services WSDL Array
  • Learn Web Services .NET Grid
  • Learn Web Services WDDX
Package Post
  • Joomla Intro
  • Joomla Component
  • Joomla Module
  • Joomla MVC
  • Joomla MVC Backend
  • PostNuke Intro
  • Zend Framework Intro
  • Zend Framework Action
  • Zend Framework Database
  • Zend Framework Registry
  • Zend Framework Config
  • Zend Framework Login
  • Zend Framework Session
  • PHP Array Tips
  • PHP File Tips
  • PHP Email
  • PHP Ms Excel
  • PHP Pattern
  • PHP SMS
  • Flash Database
  • PHP Multitier
  • jQuery Introduction
  • jQuery Selectors
  • Portable Web Server
  • Web Mobile Intro
  • Drupal Installation
  • Drupal Configuration