Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Setting default sort order 30 Jan 2012 15:39 #1131

  • giori
  • giori's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 73
  • Thank you received: 14
Users are asking me to have tables fixed sorted by newest date. So the date field does not need to be sortable, but simply sorted by newest date.

I see that we can make a column either fixed or sortable, but we cannot define a default sort order!

I tried to fiddle around in the code in the models folder and in the views, but without success. In the views I can set the field header fixed, but in the models files I do not know which functions need to be changed to add an "Order by a.date asc/desc" clause.

Please Log in or Create an account to join the conversation.

Last edit: by admin.

Re: Setting default sort order 30 Jan 2012 16:50 #1133

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
Interested in the answer too ;-)

Please Log in or Create an account to join the conversation.

Re: Setting default sort order 31 Jan 2012 00:12 #1137

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
After a bit of search, here it is (i think :whistle:)

First, you have to set a field that will be ordered by default. To do this, in the Builder, go into your Collection View, click just right of the Grid section (on the icon to get the propreties) and select a field in GROUP BY. Do the same for both collection views (backend and frontend).

Then

In Administrator/models/NAME_OF_YOUR_MODEL.php, search for
function _buildQueryOrderBy()
	{
		$order = array();
		$pre_order = 'a.field_to_order';

		return parent::_buildQueryOrderBy($order, $pre_order);
	}

and change this with :
function _buildQueryOrderBy()
	{
		$order = array();
		$pre_order = 'a.field_to_order DESC';

		return parent::_buildQueryOrderBy($order, $pre_order);
	}
The following user(s) said Thank You: admin, giori

Please Log in or Create an account to join the conversation.

Last edit: by admin.

Re: Setting default sort order 31 Jan 2012 06:53 #1140

I was doing it another way, but I see this is better. Thanks

Please Log in or Create an account to join the conversation.

Last edit: by mossss.

Re: Setting default sort order 11 Feb 2012 10:29 #1234

  • giori
  • giori's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 73
  • Thank you received: 14
VeCrea,

thank you for the solution. Obviously I checked the wrong function.

Jocelyn,

Is it possible to add the "Default sort order: Asc/Desc" next to the field attribute "Sortable Yes/No"?
Shouldn't it be an a easy change? Thank you!

Please Log in or Create an account to join the conversation.

Re: Setting default sort order 11 Feb 2012 11:40 #1235

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
One other sorting question that i couldn't solve is :
how can you sort "DESC" the values of a combo box listing values from a FK ?
Giori, happy i could help

Please Log in or Create an account to join the conversation.

Re: Setting default sort order 12 Feb 2012 14:03 #1245

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Values from a FK comes from the model as exactly the same way than a list.

In the view.php.html file, find the declaration of this list (edit input or filter, or else...)

Exemple : here a FK combo initialization in $lists:
$model_attribut =& JModel::getInstance('attributs', 'Demo120Model');
$model_attribut->addOrder('a.title');   //ADD THIS
$lists['fk']['attribut'] = $model_attribut->getData();


You can also create a PREDEFINED reusable query in your model (collection)
function _buildQuery_my_predefined_query()
{
	$this->addOrder('a.title');    //POSSIBLE HERE

	$query = ' SELECT a.*'
	
		. $this->_buildQuerySelect()
		. $this->_buildQueryJoin() . ' '
		. $this->_buildQueryWhere()

		. $this->_buildQueryOrderBy()
		. $this->_buildQueryExtra()
	;

	return $query;
}


and call it in the VIEW file :
$model_attribut =& JModel::getInstance('attributs', 'Demo120Model');
$model_attribut->active('predefined', 'my_predefined_query');   //CALL IT HERE
$lists['fk']['attribut'] = $model_attribut->getData();
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

Last edit: by admin.
  • Page:
  • 1
Time to create page: 0.149 seconds

Real time saver and great Component Builder tool ! I have been developing with J-Cook Pro Component Builder for several months now and can say with all honesty that this product/service is second to none. The product is feature rich and is being improved and added to all the time. Do yourself a favor if you need to build a Joomla! Component then you can do no wrong in trying the product. You will save on time and effort while being able to deliver your project on time. J-Cook pro does the hard work for you you then have the freedom to fully customise the end result for your own needs. 

One word: Awesome.
Edwardcox (JED)
         

Get Started