Question

Doing a jQuery powered paginated list of view of records. the total number of records on the page can be 10,20,50,100. If 50 was selected as default and the user selects 20, then I simply want to remove the table rows beginning from 21 up to 50.

How can I do this ?

Was it helpful?

Solution

Perhaps using nextAll()? Like this:

JSFiddle:

http://jsfiddle.net/eLwPf/3/

OTHER TIPS

I think you're better off doing a proper refresh so that the pagination code doesn't get out of sync with what's actually displayed.

But to answer your question as asked:

$("#yourTableId tr").slice(20).remove();

That is, select all of the rows, then use the .slice() method to reduce the set to just the ones from row 20 (or whatever number, obviously you'd use a variable there), and then .remove() them.

Note that .slice() uses a zero-based index, so .slice(20) gets you the 21st row and up. You can specify an end index, e.g., .slice(20,50), but if you don't it just selects all items from the start index and up so .slice(20) does the job in this case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top