Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- paginate: function(){
- let self = {
- currentPage: this.oldCourtDispatches.current_page,
- totalPages: this.oldCourtDispatches.last_page,
- pageArray: [],
- nextPage: (this.oldCourtDispatches.current_page == this.oldCourtDispatches.last_page ? '': this.oldCourtDispatches.current_page+1),
- prevPage: (this.oldCourtDispatches.current_page == 1 ? '' : this.oldCourtDispatches.current_page-1),
- buttonStart: '',
- buttonEnd: '',
- type: 'total',
- steps: 2,
- totalButtons: 4,
- }
- if(self.type === 'steps'){
- let steps = 2
- self.buttonStart = (parseInt(self.currentPage)-steps > 1 ? parseInt(self.currentPage-steps) : 1 )
- self.buttonEnd = (parseInt(self.totalPages)-parseInt(self.currentPage)-steps > 0 ? parseInt(self.currentPage) + steps : self.totalPages )
- }
- if(self.type === 'total'){
- let steps = Math.ceil(self.totalButtons/2)
- self.buttonStart = (parseInt(self.currentPage)-steps > 1 ? parseInt(self.currentPage-steps) : 1 )
- self.buttonEnd = (parseInt(self.totalPages)-parseInt(self.currentPage)-steps > 0 ? parseInt(self.currentPage) + steps : self.totalPages )
- if(self.buttonStart < steps){
- let remainder = steps - self.currentPage
- self.buttonEnd = self.buttonEnd + remainder +1
- }
- if(self.totalPages - self.currentPage < steps){
- let remainder = steps - (self.totalPages - self.currentPage)
- self.buttonStart = (parseInt(self.buttonStart)- remainder > 1 ? parseInt(self.buttonStart)- remainder : 1 )
- }
- }
- for(let i=self.buttonStart; i < parseInt(self.buttonEnd+1); i++){
- self.pageArray.push(i)
- }
- return self
- }
Add Comment
Please, Sign In to add comment