realize function of pagination