phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Joomla - Component: Creating Advance List Screen

Tag: joomla, cms, Joomla Component   Category: PHP Framework
post: 05 Nov 2007 read: 6,390


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

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Joomla: Fast Road to Understand Component Programming
Chart: How to Build Cool Animation Real Time Chart
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

3 Responses to Joomla - Component: Creating Advance List Screen:

Excellent overview. I found every thing I need to know about creating a table and populating it!

Your tutorials are very good.

However there a problem in the showHello() - Joomla! does not allow to pass values by reference.

Any idea how to work arround this problem?

Thanks for your tutorials!

Regards

CM

Your blog is interesting!

Keep up the good work!

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting