Accio
Accio

Reputation: 86

getting value from Material UI pagination

I need to get the number of the selected page so I can show the user certain data. I've got this pagination element:

<Pagination count={5} variant="outlined" shape="rounded" onChange={handlePagination} />

And it looks like this: Pagination

So I added onChange action with function "handlepagination" which looks like this:

function handlePagination (event) {
console.log(event.currentTarget)
}

And when I for example click button number 4, I get this output: output

Can anybody help me get the number of the page, in this case, the "4" string? I tried event.currentTarget.value but that does not work...

Upvotes: 0

Views: 3956

Answers (2)

Vasudha Nayak
Vasudha Nayak

Reputation: 71

You can use second parameter returned by the onChange event on the Pagination component(React Material) to get the current page number like below

onChange={(event, pageNumber) => pageChangeHandler(event, pageNumber)}


pageChangeHandler(event, pageNumber = 1) {
    // Your code 
}

Upvotes: 7

Null
Null

Reputation: 119

I believe you can access it this way.

console.log(event.target.textContent)
//or
console.log(event.currentTarget.textContent)

Here are other solutions.

Upvotes: 2

Related Questions