Support

Account

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

Solved

Get data from previous and next rows

  • 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

  • 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?

  • 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

  • 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)

The topic ‘Get data from previous and next rows’ is closed to new replies.