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

TOPIC:

Filters again - nested table 20 May 2013 10:15 #7212

Hi,

Again about filters. I have a nested table (backend collection view) and I want to filter it by parent_id, in the sense that I want to retrive the tree that has parent_id as root.

I have already used the query to filter the data in the front-end, using a custom function, (where parent_id is a menu parameter) but now, trying to obtain that as filter results from prepareQuery, I'm having troubles.

Basically, I need to compare (NOT TO JOIN) the "elements" table with itself, then I have to use this code (inside elements model, prepareQuery function):
//WHERE - FILTER : Parent id
if($this->getState('filter.parent_id') != null){			
$this->addWhere('a.lft between b.lft and b.rgt');
$this->addWhere('b.id = '. (int)$this->getState('filter.parent_id'));}

So, I have added this line before the select:
$query->from('#__manta_elements AS b');

Now, the filter works as expected -> I select the value from the drop-down, the query is correctly called and the values shown correctly.
BUT now the default view does not work anymore: any element appears in the grid 12 times (!) and if I check the executed queries I find a lot of select a.* repeated.
If I comment the additional "$query->from" then everything goes back to normality but obviously the filter does not work anymore...

I think I can workaround this by filtering-modifying the array of values inside default_grid.php before it's used...but still...this is not how this is supposed to go...

How can I add a "$query->from" to prepareQuery withouth messing up all the results ?!?!

Thanks

Elena

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

  • Page:
  • 1
Time to create page: 0.053 seconds

The j-cook project is one of the best of its kind and it is nice that we all try to contribute in little ways to make life easy for each other.

vlemos (Forum)  

Get Started