Disable next button in the last page

Disable next button in the last page

I'm fetching some data through JSON in a container(it is a table), which has previous & next buttons.

In each page, I'm displaying 20 records from the JSON. Now, I need to disable the 'next' button, based on the value of the property 'totalRecords' in the JSON.

Calculation:

So, let say, the value of totalRecords = 238. Which means I should have (238 /20 = 11 pages with 20 records and the last page with 18 records = 12 pages overall). So, how do I ensure that 'next' button is disabled on 12th page in this case? I mean how do I ensure that each time the next button is disabled on the last page based on the similar calculation above?

I tried this :

 
  1. if(data.totalRecords%20 > 1) {
  2. $('#next-btn').addClass('disabled');
  3. } else {
  4. $('#next-btn').removeClass('disabled');
  5. }