Forums

More sortable table help?

ClearSky 03 Aug, 2010
Hi,

I've been working my way through the thread on sortable tables, and I've almost got it to work. πŸ™‚

I just need a little help getting it to actually sort.

Here is a link to the table I'm working on:
http://www.clearskydomains.com/joomlatest/index.php?option=com_chronoconnectivity&connectionname=domain_names

You can click on the column headings links, but nothing happens. When I look at the bottom navigation link it says the column heading links point to:

javascript:tableOrdering('domain_name','desc',"); - for the column heading "Domain", and etc for the other headings. It looks correct, but no sort occurs.

Please help!

Best Regards,
Jonathan

PS Bob's (GreyHead) help throughout this Forum and the thread I mentioned above has been invaluable to helping me understand how ChronoConnectivity and ChronoForms work. Thanks a lot!! You are much appreciated on this Forum!!
GreyHead 03 Aug, 2010
Hi Jonathan,

YOu need to have includes/js/joomla.javascript.js loaded on the page as that contains the script that does the sorting. Usually I think it's loaded more or less automatically but I don't see it on your page.

Bob
ClearSky 03 Aug, 2010
Hi Bob,

Thanks for replying so quickly!

How do I get the javascript to load? Is there a setting in the global config or somewhere? Or, do I need to add a some code into the head manually? It's Joomla 1.5.20

I mean if is supposed to be on automatically, ??

Best Regards,
Jonathan
ClearSky 03 Aug, 2010
I added this code to the head section:

<script language="javascript" type="text/javascript">
function tableOrdering( order, dir, task )
{
        var form = document.adminForm;

        form.filter_order.value = order;
        form.filter_order_Dir.value = dir;
        document.adminForm.submit( task );
}
</script>


And, the links started working (activating/doing something), but the columns still don't sort. If I click once a triangle icon appears, and if I click a second time the icon flips over. But, still no change in the data.

Do I need to add an "id" to the <td> tags in the body?

Thanks in advance!!

Best Regards,
Jonathan
GreyHead 03 Aug, 2010
Hi Jonathan,

I think you only have a part of the code there. Try this in the Header box
<?php
$doc =& JFactory::getDocument();
$doc->addScript( "includes/js/joomla.javascript.js" );
?>


Bob
ClearSky 03 Aug, 2010
Hi Bob,

It still doesn't sort. I wasn't sure where to put the code you provided, so I tried it above and below the original <?php $filter_order, but it still didn't sort.😟

Here is the code I'm using for each section:

Header:
<hr>
<br />
<?php
$doc =& JFactory::getDocument();
$doc->addScript( "includes/js/joomla.javascript.js" );
?>
<?php
$filter_order =& JRequest::getString('filter_order', '', 'post');
$filter_order_Dir =& JRequest::getString('filter_order_Dir', '', 'post');
?>
<form name="adminForm" id="adminForm" method="post" action="index.php?option=com_chronoconnectivity&connectionname=domain_names">
<input type='hidden' name='filter_order' id='filter_order' value='<?=$filter_order?>' />
<input type='hidden' name='filter_order_Dir' id='filter_order_Dir' value='<?=$filter_order_Dir?>' />

<table style='width:100%; border-collapse:collapse;' cellpadding='2;'>
<thead class='domains'>
<tr style="height: 40px; text-align: center; background: #8EC2EA;" valign="middle">
<th style='width: 42px;'><?=JHTML::_('grid.sort', 'Site ', 'site', @$filter_order_Dir, @$filter_order )?></th>
<th style='width: 160px;'><?=JHTML::_('grid.sort', 'Domain ', 'domain_name', @$filter_order_Dir, @$filter_order )?></th>
<th style='width: 42px;'><?=JHTML::_('grid.sort', '.tld ', 'tld', @$filter_order_Dir, @$filter_order )?></th>
<th style='width: 120px;'><?=JHTML::_('grid.sort', 'Category ', 'category', @$filter_order_Dir, @$filter_order )?></th>
<th style='width: 80px;'><?=JHTML::_('grid.sort', 'Registrar ', 'registrar', @$filter_order_Dir, @$filter_order )?></th>
<th style='width: 80px;'><?=JHTML::_('grid.sort', 'Expires ', 'expire', @$filter_order_Dir, @$filter_order )?></th>
<th style='width: 70px;'><?=JHTML::_('grid.sort', 'Contact ', 'contact_form', @$filter_order_Dir, @$filter_order )?></th>
<th style='width: 70px;'><?=JHTML::_('grid.sort', 'Buy Now! ', 'buy_now', @$filter_order_Dir, @$filter_order )?></th>
</tr>
</thead>


Body:
<tbody class="body">
        <tr style="text-align: center;">
            <td>
                <a href="{site_url}"><img src="images/portfolio/{site}_but.png"></a>
            </td>
            <td>
                <a href="{details}">{domain_name}</a>
            </td>
            <td>
                {tld}
            </td>
            <td>
                <a href="{category_url}">{category}</a>
            </td>
            <td>
                {registrar}
            </td>
            <td>
                {expire}
            </td>
            <td>
                <a href="{contact_form}"><img src="images/portfolio/contact_but.png"></a>
            </td>
            <td>
                <a href="{buy_now}"><img src="images/portfolio/buynow_but.png"></a>
            </td>
        </tr>
</tbody>


Footer:
</table>
</form>
<br />
{new_record}
<br />
{pagination}
<br />
ClearSky 04 Aug, 2010
A little bump.πŸ™‚

Do I need to add something in the footer section? <tfoot> Column classes, or something like that? It seems like it should be working, but I just can't figure it out from here.

Thanks for all you're help. Have a great day!!

- Jonathan
ClearSky 09 Aug, 2010
Can anyone else tell me why this table won't sort?

It looks like it's supposed to, doesn't it?
GreyHead 22 Aug, 2010
Hi ClearSky,

Sorry for the delay. I finally got back to look at this today and there's a core code hack needed that I had completely forgotten about.

Using a suitable editor open the file components/com_chronoconnectivity/libraries/connection.php and look for the buildQuery() function around line 190. Add the lines shown here between the // hack and // end hack comments.

function buildQuery($connectionname)
{
	global $mainframe;
	$session =& JFactory::getSession();
	$MyConnection =& CFChronoConnection::getInstance($connectionname);
	$WHERE = $MyConnection->buildWhere($connectionname);
	$query = "SELECT * FROM ".$MyConnection->connectionrow->tablenames;
	if($MyConnection->connectionrow->SQL){
		$query = $query." ".trim($WHERE);
	}
	// hack
	$filter_order = JRequest::getString('filter_order', 
		$MyConnection->connectionparams('ordersql'), 'post');
	$filter_order_Dir  = JRequest::getString('filter_order_Dir', 'ASC', 'post');
	if ( $filter_order ) {
		$query .= " ORDER BY $filter_order $filter_order_Dir ";
	}
	// end hack
	$pageNav = $MyConnection->buildPageNav($MyConnection->connectionrow->name);
	$query .= " LIMIT $pageNav->limitstart,$pageNav->limit";	
	return $query;
}

This code uses the filter order from the column headings if they are set, or if not it will use the setting from the ChronoConnectivity β€˜Order by’ box



Bob

PS I have written this up in a 'How-to' document that you can buy here. The How-to document includes all of the steps and code you need to create sortable headers in a convenient pdf. I'm offering the first 20 people to purchase it a 25% discount by using the coupon 5i2LdyujP3.
ClearSky 22 Aug, 2010
Hi Bob,

I placed the hack in the connection.php file, and tried to test the form display and got this error:

Warning: Invalid argument supplied for foreach() in /home/jazzg2/public_html/clearskydomains/components/com_chronoconnectivity/libraries/connection.php on line 308

I'll go back and check everything to see if I can see what's going on. :p

Thanks again!!
GreyHead 22 Aug, 2010
Hi ClearSky,

I just pasted the function code back into my CC listing and it apears to be working OK for me. Maybe I missed something else.

Please insert this debug message just before the end of the function and post the resulting message here:
  $mainframe->enqueuemessage('Final query: '.$query);
  return $query;
}
You should get a message like this

Final query: SELECT * FROM jos_et_language_schools ORDER BY cLsVille desc LIMIT 0, 25


Bob
ClearSky 22 Aug, 2010
This is the response I got:

Final query: SELECT * FROM jos_chronoforms_portfolio ORDER BY domain_name asc

I pasted the code just before the "/// End Hack" comment in connection.php. There needs to be a "{" at the beginning of the debug code snippet.

And, the table is sorting now. Go figure!? Except for the red message at the top of the page that's great! For some reason the small bit of code made it start working, but when I take it out the parse error comes back, and the table disappears. (The headers are still there, but the data doesn't show.)

Here is a link to the page I've been working with:

http://www.clearskydomains.com/buy-domains

Thanks!!
GreyHead 23 Aug, 2010
Hi ClearSky,

There needs to be a "{" at the beginning of the debug code snippet.


I don't think so, but if it fixes the problem maybe there is a { missing somewhere else in the code.

There is only one line to insert; the whole function should look like:
function buildQuery($connectionname)
{
   global $mainframe;
   $session =& JFactory::getSession();
   $MyConnection =& CFChronoConnection::getInstance($connectionname);
   $WHERE = $MyConnection->buildWhere($connectionname);
   $query = "SELECT * FROM ".$MyConnection->connectionrow->tablenames;
   if($MyConnection->connectionrow->SQL){
      $query = $query." ".trim($WHERE);
   }
   // hack
   $filter_order = JRequest::getString('filter_order',
      $MyConnection->connectionparams('ordersql'), 'post');
   $filter_order_Dir  = JRequest::getString('filter_order_Dir', 'ASC', 'post');
   if ( $filter_order ) {
      $query .= " ORDER BY $filter_order $filter_order_Dir ";
   }
   // end hack
   $pageNav = $MyConnection->buildPageNav($MyConnection->connectionrow->name);
   $query .= " LIMIT $pageNav->limitstart, $pageNav->limit";   
   $mainframe->enqueuemessage('Final query: '.$query); // <-- add this line
   return $query;
}

Bob
ClearSky 23 Aug, 2010
I copied the whole function into my connection.php file and it started working. I was even able to remove the debug code, and it still works.πŸ™‚

Here is the code from my original connection.php; I think it may be different somehow from the one you gave me here.

function buildQuery($connectionname)
	{
		global $mainframe;
		$session =& JFactory::getSession();
		$MyConnection =& CFChronoConnection::getInstance($connectionname);
		$WHERE = $MyConnection->buildWhere($connectionname);
		
		//todo: get appropriate connection from connections table to get its data!
		$query = "SELECT * FROM ".$MyConnection->connectionrow->tablenames;
		if($MyConnection->connectionrow->SQL){
			$query = $query." ".trim($WHERE);
		}
            // hack
            $filter_order = JRequest::getString('filter_order',
            $MyConnection->connectionparams('ordersql'), 'post');
            $filter_order_Dir = JRequest::getString('filter_order_Dir', 'ASC', 'post');
            if ( $filter_order ) {
            $query .= " ORDER BY $filter_order $filter_order_Dir ";
            }
            // end hack
		if(trim($MyConnection->connectionparams('ordersql'))){
			$query = $query." ORDER BY ".trim($MyConnection->connectionparams('ordersql'));
		}
		
		$pageNav = $MyConnection->buildPageNav($MyConnection->connectionrow->name);
		
		$query .= " LIMIT $pageNav->limitstart,$pageNav->limit";	
		return $query;
	}


I had been only pasting the code between the hack comments.

Anyway, it's working beautifully now!! Thank you so much!!!

Best Regards,
Jonathan
bangtom 25 Aug, 2010
sort table only works for one page only, how to sort the table for more than one page?
GreyHead 25 Aug, 2010
Hi bangtom,

You need to save the values of the filter-order parameters so that they are passed on to the next page. I'm fairly certain that is in this thread somewhere.

Bob

There is a 'How-to' document for this process if you prefer to have all the info in one place.
This topic is locked and no more replies can be posted.