3

I've got a view (D7, Views3) that is grouped by a relationship-based title field (set in Format: settings), and I'm using a Global: View result counter to give each item a number. This is how output currently looks:


Some group

1...An item

2...Another item

Another group

3...More items

4...Still more items

5...Even more items


It's counting rows regardless of position in groups. I want it to reset the counter with each group, to look like this:


Some group

1...An item

2...Another item

Another group

1...More items

2...Still more items

3...Even more items


Seems like a simple enough task - but I can't find any options relevant to this. I don't mind writing some code to achieve this, but Views is so dense I have no idea where to start.

Can this be done without coding up some hooks? If so how?

If not, where and how in the thicket of data that is a views object could I identify where within a grouping each Global: View result counter field row is?

EDIT: looking at the very simplistic code in views/handlers/views_handler_field_counter.inc, it looks like a custom module based on this code would be the best option, creating a new global field that uses groups instead of the pager. This would need to find data about each group (probably in $this->view somewhere?), and would identify its own row's position in the appropriate group. Is this possible? Again, not really sure where to start.

EDIT 2: No sign of useful grouping data in the view object that I can see, but this thread suggests that maybe it's sorting data that should be used for this?

4

Have you try using the format "HTML List" and in the settings of this format you can set the grouping field and then set the list to an ordered list.

Note: by doing this way you will not need the global counter.

Note 2 I tested on my site an it does work see image

Thank you.

Note 2:

  • Ha, I can't believe I didn't think of that! There I was, about to re-write a Views plugin, and I'd completely overlooked something as simple as this... Thanks, I might have wasted a lot of time there :) – user568458 Aug 7 '12 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.