Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pagination label for all rows

I have a pagination as below:-
enter image description here

Now right now it has options 10,25,50 and I added one more for all rows as I have total of 1000 rows which I want to see without going to multiple pages 20 times. So i included data.length which gives me output as below now:-
enter image description here

My code is:-

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

            <select value={pageSize} onChange={e => setPageSize(Number(e.target.value))}>
              {[10, 25, 50, data.length].map(pageSize =>(
                <option key ={pageSize} value={pageSize}>
                  Show {pageSize}
                </option>
              ))}

I need to choose a label for data.length and not a number as shown in screenshot above. Can anyone help.

>Solution :

You can write condition, if data.length equal pageSize you show text All else pageSize.

Example:

{[10, 25, 50, data.length].map((pageSize) => (
          <option key={pageSize} value={pageSize}>
            Show {data.length === pageSize ? "All" : pageSize}
          </option>
        ))}

codesandbox

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading