Support

Account

Home Forums Add-ons Repeater Field Get data from previous and next rows

Solved

Get data from previous and next rows

    • dougal

    • July 1, 2013 at 6:51 pm

    Hi, I have built a slider with the repeater field. Is it possible to get data from the previous and next rows and show them in the current row?
    In this case it is so that I can show a title when a user hovers over the next or previous buttons (to show them were they are headed).
    Many thanks

    • Elliot

    • July 1, 2013 at 6:59 pm

    Hi,

    You have 2 options:

    1. Use jQuery to find the prev / next data from the DOM and generate the HTML on page load

    or

    2. Don’t use the has_sub_field while loop, instead use a more basic PHP foreach of for loop so you can use the ‘index’ to find the prev (index-1) and next (index+1) rows

    Does that help?

    • dougal

    • July 1, 2013 at 7:05 pm

    Hi Elliot, thank you, yes it does, assuming you mean like the foreach($rows as $row) example on the docs page I think I can figure that out.
    Many thanks for your help, awesome stuff.
    Cheers

    • rmdev

    • July 6, 2013 at 12:46 am

    You’d be looking at a simple bit of jQuery like this (obviously you will have to change the selectors)

    
    currentSlide = $('.slider .active');
    nextSlide = currentSlide.next();
    prevSlide = currentSlide.prev();
    
    /** then to get for instance, a caption from inside the slides : *//
    nextSlideData = nextSlide.find('p.caption').html();
    prevSlideData = prevSlide.find('p.caption').html();
    
    alert('Next caption: '+nextSlideData+' & Previous caption: '+prevSlideData);
    
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.