react-paginate icon indicating copy to clipboard operation
react-paginate copied to clipboard

How to start with page number 1 instead of 0 ?

Open eromoe opened this issue 7 years ago • 20 comments

Hi,

I found this project use 0 as start page number, but I need 1. Looks like there is no such parameter to adjust this ? Now , have to use hrefBuilder.

eromoe avatar Sep 25 '17 06:09 eromoe

disableInitialCallback={ true }
initialPage={ 1 }

mundosk8 avatar Sep 25 '17 08:09 mundosk8

initialPage={1}

Just tell react-paginate current page is 1, but actually select 2

image

eromoe avatar Sep 25 '17 09:09 eromoe

By default the initial page selected is 1. Which version of react-paginate do you use?

AdeleD avatar Oct 06 '17 20:10 AdeleD

react-paginate is latest.

I think you misunderstand. I have said react-paginate use 0 as start page number , that may be confused , see below image

The key point is

tabindex="0"

react-paginate think api is start from 0, But my api is start from page 1 .

When it is in first page, I add page=1 to current url querystring, which make react-paginate show current page 2 .

eromoe avatar Oct 11 '17 01:10 eromoe

same issue here.. did u find a solution?

sergioviniciuss avatar Oct 19 '17 00:10 sergioviniciuss

@AdeleD actually, the behavior I see is the same reported by @eromoe .. the react-paginate thinks api start from 0

sergioviniciuss avatar Oct 19 '17 00:10 sergioviniciuss

I don't have much time to make a PR, so simply switch to another plugin .

eromoe avatar Oct 19 '17 00:10 eromoe

Running into the same issue. I assume it has something to do with mapping over an array of pages and using their index. I went into the module and +1d all the indexes to no avail. :(

joseph-engelmajer avatar Nov 09 '17 22:11 joseph-engelmajer

changed the pagination on my api lol

joseph-engelmajer avatar Nov 10 '17 00:11 joseph-engelmajer

I just came across the same issue, and worked it out as follows:

forcePage={pagination.currentPage - 1} on the ReactPaginate call. Did not include the initialPage prop.

requestData.page = selected + 1; in my onPageChange handler.

Seems to work fine now :)

oldtinroof avatar May 11 '18 14:05 oldtinroof

@AdeleD I think this is a very serious problem.

Could you please help us with this?

ikashifullah avatar Jun 03 '18 12:06 ikashifullah

@eromoe, could you please tell which plugin did you move to?

ikashifullah avatar Jun 04 '18 08:06 ikashifullah

I’m currently working on a solution. I’ll let you know when it’s done

AdeleD avatar Jun 04 '18 08:06 AdeleD

Hi @AdeleD,

Any progress so far? We really need this fix quickly.

Thank you.

ikashifullah avatar Jun 11 '18 06:06 ikashifullah

Hi guys ,

is this issue fixed now ?

It's urgent !!!

Thanks

mustapha-ghlissi avatar Dec 19 '18 06:12 mustapha-ghlissi

Hey @MustaphaGhlissi, not fixed per se, but I did find a workaround of sorts. Since they're assuming a zero index, you'll have to increment 'e.selected' by one on click to dispatch your paginated fetch properly.

Additionally, if you're having issues with the pagination tracking your current page, you can set the property forcePage={currentPage - 1} to re-align your state's currentPage with their zero index.

Tracking your current page in state.....

    state = {
        currentPage: 1
    }

In your onPageChangeHandler...

    _handlePageChange = (e) => {
        const nextPage = e.selected + 1

        dispatchAction( nextPage, pageSize,  /* ...any additional args */ )
        this.setState({ currentPage: nextPage })
    }

In your ReactPaginate component...

render() {
    return (
        
        /* whatever you're rendering */

        <ReactPaginate
            onPageChange={this._onPageChange}
            pageCount={totalPages}
            forcePage={currentPage -1} 
        />
    )
}

WarrenBuffering avatar Jan 24 '19 15:01 WarrenBuffering

+1 For this issue. I would appreciate a builtin support for zero index pagination

cacoze avatar Dec 22 '20 13:12 cacoze

Hi, Fixed as below : @observable page = 1; And when you call the API set : .list( this.axiosParams, LIMIT, this.page - 1 );

malbayoush avatar Feb 04 '21 02:02 malbayoush

initialPage={1}

Just tell react-paginate current page is 1, but actually select 2

image

sampahgit avatar Feb 06 '23 02:02 sampahgit

  • const [page, setPage] = useState(1);

    const changePage = ({ selected }) => { setPage(selected + 1); };

<ReactPaginate initialPage={0} onPageChange={changePage} />

sampahgit avatar Feb 06 '23 02:02 sampahgit