|
Template:MindTouch > Reports > Controls > SearchPaging
SearchPagingTable of contentsNo headers/** * Search Paging Control * * @param uri $uri - base uri (default: page.uri) * @param map $params - query params to preserve * @param num $total - total number of results queried * @param num $perPage - number of results shown per page (default: 10) * @param str $key - query param to use for paging (default: "page") * @param num $page - current page being viewed (default: __request.args[$key]) * @param str $showingKey - custom resource key to use for "showing results" */ var uri = $uri ?? page.uri; var params = $params; // required! var total = $total; // required! var perPage = $perPage ?? 10; var pageKey = $key ?? "page"; var currentPage = $page ?? __request.args[pageKey]; var localizeShowing = $showingKey ?? "MindTouch.Reports.paging.results"; // compute paging if (!currentPage || currentPage < 1) { let currentPage = 1; } var totalPages = num.ceiling(total / perPage); if (totalPages < 1) { let totalPages = 1; } var setStart = (currentPage - 1) * perPage; var setEnd = num.min(setStart + perPage, total); <form class=("mt-search-paging" .. (total < 1 ? " ui-no-results": "")) method="get" action=(uri)> foreach (var paramName:paramValue in params) { <input type="hidden" name=(paramName) value=(paramValue) /> } <div class="summary"> if (total < 1) { wiki.localize("MindTouch.Reports.paging.noresults"); } else { wiki.localize(localizeShowing, [ (setStart+1), setEnd ]); } </div> <div class="paging"> if (currentPage > 1) { <span class="prev"> <a href=(uri & params & {(pageKey): (currentPage-1)})> wiki.localize("MindTouch.Reports.paging.prev"); </a> </span> } else { <span class="prev ui-state-disabled">wiki.localize("MindTouch.Reports.paging.prev")</span> } <span class="jump">wiki.localize("MindTouch.Reports.paging.jump")</span> <input class="jump" type="text" name=(pageKey) value=(currentPage) size="2" /> if (currentPage < totalPages) { <span class="next"> <a href=(uri & params & {(pageKey): (currentPage+1)})> wiki.localize("MindTouch.Reports.paging.next"); </a> </span> } else { <span class="next ui-state-disabled">wiki.localize("MindTouch.Reports.paging.next")</span> } </div> </form> |