Last active
April 13, 2016 04:42
-
-
Save lackneets/0de537eb51db651543166e999dc63cc1 to your computer and use it in GitHub Desktop.
Pagination of October CMS Backend List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-control="toolbar"> | |
<div class="form-group span-left"> | |
<select class="form-control custom-select pagination-select" style="width:200px"> | |
<option selected="selected" value="1">第 1 頁</option> | |
</select> | |
</div> | |
</div> | |
<script> | |
$(function(){ | |
var total; | |
var perPage; | |
var curPage; | |
var totalPage; | |
function updatePagination(){ | |
total = parseInt($('.page-iteration').text().match(/\d+\s*$/)); | |
curPage = (parseInt(($('.page-next').data('request-data')||"").toString().match(/\d+$/)) - 1) || (parseInt(($('.page-back').data('request-data')||"").toString().match(/\d+$/)) + 1) || 1; | |
if(curPage == 1){ | |
perPage = parseInt($('.page-iteration').text().match(/(\d+)\s+\d+\s*$/)) - parseInt($('.page-iteration').text().match(/(\d+)-\d+\s+\d+\s*$/)) + 1; | |
}else{ | |
perPage = (parseInt($('.page-iteration').text().match(/(\d+)-\d+\s+\d+\s*$/)) - 1) / (curPage-1); | |
} | |
totalPage = Math.ceil(total/perPage); | |
$('select.pagination-select').empty(); | |
var from = Math.max(1, curPage-1000); | |
var to = Math.min(totalPage, from+2000); | |
for(var i=from; i<= to; i++){ | |
$('<option/>').text('第 ' + i + ' 頁').val(i).appendTo('select.pagination-select').prop('selected', i == curPage); | |
} | |
$('select.pagination-select').change(); | |
history.pushState({},document.title, location.href.toString().replace(/\?page=\d+/, '') + '?page=' + curPage); | |
} | |
updatePagination(); | |
$(document).on('change', 'select.pagination-select', function(){ | |
if(this.value != curPage){ | |
$.request('list::onPaginate', { | |
data: {page: this.value}, | |
}); | |
updatePagination() | |
} | |
}); | |
$(document).ajaxSuccess(updatePagination); | |
$(document).on('click', 'tbody tr', function(event){ | |
event.preventDefault(); | |
return false; | |
}); | |
$('tbody tr *').unbind() | |
$('tbody tr').each(function(){ | |
var url = $(this).find('a').attr('href'); | |
$(this).find('td').on('click', function(){ | |
event.preventDefault(); | |
window.open(url, url); | |
return false; | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment