Fixed javascript pagination issue