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?

1 Answer 1

5

You can use the HTML List format. In the settings of this format, you can set the grouping field and then set the list to an ordered list.
By doing this, you won't need any global counter.

See in the following screenshot how the list would be rendered.

screenshot

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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