[SOLVED] Can I sort extra fields groups?

  • lcp298
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 years 10 months ago #1511 by lcp298
Can I sort extra fields groups? was created by lcp298
Is it possible to sort the groups by anything other than alphabetical?

I created them in the order I need them, but they have been assigned IDs in alphabetical order, and therefore they are displayed in that order.

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

More
11 years 10 months ago #1512 by mmmaug1977
Replied by mmmaug1977 on topic Can I sort extra fields groups?
Hi Laura,

Unfortunately, groups does not have ordering.

If you want to order them as you created, then the code can be modified to order them by the database id.

Please, let me know how do you want to order them.

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

  • lcp298
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 years 10 months ago - 11 years 10 months ago #1513 by lcp298
Replied by lcp298 on topic Can I sort extra fields groups?
Hi,

Yes, I'd like them in the order they were created.

Is it also possible to change the code in the item.php override to call each group individually? I saw on another thread that you can call each field separately:
<?php echo $this->item->extraFields->Field1Alias->name; ?>
<?php echo $this->item->extraFields->Field1Alias->value; ?> etc..

I don't really want to have to put each field in manually (I may have to add more in the future), and I want to be able to style the groups.

Thanks
Last edit: 11 years 10 months ago by lcp298.

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

More
11 years 10 months ago #1514 by mmmaug1977
Replied by mmmaug1977 on topic Can I sort extra fields groups?
Hi Laura,

To sort the groups, please find this line:
Code:
$db->setQuery("SELECT * FROM #__k2_extra_fields_groups WHERE id IN(" . implode(",", $efg) . ")");
and replace it with this line:
Code:
$db->setQuery("SELECT * FROM #__k2_extra_fields_groups WHERE id IN(" . implode(",", $efg) . ") ORDER BY id");

Find this line in both the files: mefgfork2.php and ajax.php, inside the folder plugins/k2/mefgfork2

For displaying fields by group, I will find out how this can be done.

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

  • lcp298
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 years 10 months ago #1517 by lcp298
Replied by lcp298 on topic Can I sort extra fields groups?
Thanks, being able to style and position the groups individually will be extremely helpful.

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

  • lcp298
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 years 9 months ago #1525 by lcp298
Replied by lcp298 on topic Can I sort extra fields groups?
Have you been able to find out how to call the groups individually?

Thanks

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

More
11 years 9 months ago #1526 by mmmaug1977
Replied by mmmaug1977 on topic Can I sort extra fields groups?
Not yet, I will try to have this done next week.

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

More
11 years 9 months ago #1532 by mmmaug1977
Replied by mmmaug1977 on topic Can I sort extra fields groups?
Hi Laura,

You can try the following code in the item.php template override, to replace the extra fields display section:
Code:
<div class="itemExtraFields"> <?php $extraFieldsByGroup = JArrayHelper::pivot($this->item->extra_fields, 'group'); $db = JFactory::getDbo(); $query = "SELECT * FROM #__k2_extra_fields_groups"; $db->setQuery($query); $groups = $db->loadAssocList('id'); foreach ($extraFieldsByGroup as $key=>$extrafields){ $defaultGroup = ''; if($key == $this->item->category->extraFieldsGroup) $defaultGroup = "class='mefg_default'"; ?> <div <?php echo $defaultGroup;?> > <h3><?php echo JText::_($groups[$key]['name']); ?></h3> <ul> <?php foreach ($extrafields as $key=>$extraField): ?> <?php if($extraField->value != ''): ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <?php if($extraField->type == 'header'): ?> <h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4> <?php else: ?> <span class="itemExtraFieldsLabel"><?php echo JText::_($extraField->name); ?>:</span> <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php endif; ?> </li> <?php endif; ?> <?php endforeach; ?> </ul> </div> <?php } ?> <div class="clr"></div> </div>

It modifies the display of extra fields such that each group fields will be displayed in a separate DIV element, and the DIV element of the main group, which is assigned to the category by K2 normal way, will have a CSS class="mefg_default"

This code can be a good starting point to customize the extra fields display by group.

Please let me know if you need more help

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

  • lcp298
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 years 9 months ago #1535 by lcp298
Replied by lcp298 on topic Can I sort extra fields groups?
Sorry for the long delay. The code to display each group works perfectly, thanks.

I'm afraid changing the order of the groups to ORDER BY id has not worked.

I only need to change the order on itemform.php as they already appear correctly on item.php

Any ideas?
Thanks

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

  • lcp298
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 years 9 months ago - 11 years 9 months ago #1556 by lcp298
Replied by lcp298 on topic Can I sort extra fields groups?
I still cannot get the extra field groups to appear in the correct order on itemform.php. I changed that SQL query in the 2 files you suggested but it has had no effect.

Is there anywhere else I need to change it?
Last edit: 11 years 9 months ago by lcp298.

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

Powered by Kunena Forum