Welcome, Guest
Username: Password: Remember me

TOPIC: Ordering Grid

Ordering Grid 03 Nov 2016 09:20 #14674

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 133
  • Thank you received: 21
  • Karma: 4
Hi,I'm having difficulty trying to order a grid.

I have tried j-cook.pro/index.php/forum/7-design-your...efault-order-in-grid and www.j-cook.pro/index.php/forum/9-coding-...t-boxes-going-insane but these methods don't seem to work.

In fork/views/devices/tmpl I am editing default_grid.php. There is this line
$model		= $this->model;
$user		= JFactory::getUser();
$userId		= $user->get('id');
$listOrder	= $this->escape($this->state->get('list.ordering'));
$listDirn	= $this->escape($this->state->get('list.direction'));
$saveOrder	= $listOrder == 'a.ordering' && $listDirn != 'desc';
JDom::_('framework.sortablelist', array(
	'domId' => 'grid-devices',
	'listOrder' => $listOrder,
	'listDirn' => $listDirn,
	'formId' => 'adminForm',
	'ctrl' => 'devices',
	'proceedSaveOrderButton' => true,
));
Is there something here I can edit?
I'm trying to sort a.validation desending.

(For now I've had to modify the model function populateState - but cann't I do it here somewhere?)
Just call me Chris :)
Last Edit: 03 Nov 2016 09:52 by organicwebs.
The administrator has disabled public write access.

Ordering Grid 05 Nov 2016 17:22 #14675

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Normaly, you can manage this with the Builder :
  1. Add an 'Ordering' field in your Table with the wizard.
  2. Add this field into your Grid Layout and configure it as Ordering Box option.
  3. Then you can sort your datas by ID or use the Drag&Drop Ordering

It works like a charm for me :)
Last Edit: 06 Nov 2016 15:34 by liubov.
The administrator has disabled public write access.

Ordering Grid 09 Nov 2016 14:01 #14679

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 133
  • Thank you received: 21
  • Karma: 4
Thanks,

What I should have said is...
I am having difficulty tring to set the default order of a grid.

So that when the grid is shown, it will be ordered by a column of my choosing.

To do this basic task I have needed to fork the model. I have so many hacks to both the views and models, it is becoming difficult to make any changes in the builder.
Just call me Chris :)
The administrator has disabled public write access.

Ordering Grid 09 Nov 2016 18:06 #14681

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Ok, just to anderstand the context :

You want to set an order Column of your choice in the Backend grid to display the datas in a Frontend Grid ordered by your Column & Direction ?
The administrator has disabled public write access.

Ordering Grid 10 Nov 2016 08:33 #14682

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 133
  • Thank you received: 21
  • Karma: 4
Hi Liuov,

I am writing a component so that users (equipment vendors) can add data into an equipment catalogue database.
Other users (buyers) will search the database - looking for the equipment that need - scrolling through all the euipment listings.

The equipment list to these buyers need to be ordered a certain way - in my case - so that a column labeld "validation rating" is ordered decending - so equipment with a higher "validation rating" is shown on top of the list.

It needs to do this by default. I realise the user can sort the list themselves - but that is not what I have been scoped to do.


So I need to display the frontend collection with speciifc column ordered as a default.


As with this post j-cook.pro/index.php/forum/7-design-your...efault-order-in-grid there are values in the forked view - but changing these does not seem to work for me.

Looks like Morgan was having the same problem here.... www.j-cook.pro/index.php/forum/9-coding-...t-boxes-going-insane

For now, I have forked the model - but that is not a good solution - I have multiple collection views for the same table - they all seem to share the same model code.

If there isn't a feature in the wysiwyg builder, then the fork needs to be in the view. Ie: In the forked view this needs to work (but it doesn't for me)...
$model->setState('list.ordering', 'a.yourfield');
$model->setState('list.direction', 'desc');
Just call me Chris :)
The administrator has disabled public write access.

Ordering Grid 10 Nov 2016 09:56 #14683

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Hi, OK it's clearer for me.
"For now, I have forked the model - but that is not a good solution - I have multiple collection views for the same table - they all seem to share the same model code".

If you have multiple collections views from a Table, don't you manage them with different Context (Views/Models)? I manage that with my component.
Jocelyn wrote something about the way to do here:
http://www.j-cook.pro/index.php/support/9-coding-inside-your-component/11270-context-state-overrides

For each context, you can refine the query to set some specific features...
Last Edit: 10 Nov 2016 12:54 by liubov.
The administrator has disabled public write access.
The following user(s) said Thank You: admin, organicwebs

Ordering Grid 10 Nov 2016 11:57 #14685

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 133
  • Thank you received: 21
  • Karma: 4
Thanks Marc,

I'll fork the model and test for the context views in there. I can then manipulate the SQL queries.

For others trying to do this, here is an example on how to manipulate the list/grid/collection from a forked model...
protected function populateState($ordering = null, $direction = null){
...
		//For mycollection - show only Drafts, only entries of the logged in user, ordered by myfield  
		if ($this->context == 'com_mycom.mytable.mycollection'){
			$this->setState('list.limit', 10);
			$this->setState('query.where', array("a.status = 'Draft'", "a.created_by = $userId"));
			$this->setState('list.ordering', 'a.myfield');
			$this->setState('list.direction', 'desc');
}
Just call me Chris :)
Last Edit: 10 Nov 2016 13:32 by organicwebs.
The administrator has disabled public write access.
Time to create page: 0.153 seconds

Get Started