mirror of
https://github.com/moodle/moodle.git
synced 2025-07-25 00:02:18 +02:00
MDL-68288 core_table: support pagination bar for dynamic tables
This commit is contained in:
@@ -3085,6 +3085,7 @@ class paging_bar implements renderable, templatable {
|
||||
$data->label = get_string('page');
|
||||
$data->pages = [];
|
||||
$data->haspages = $this->totalcount > $this->perpage;
|
||||
$data->pagesize = $this->perpage;
|
||||
|
||||
if (!$data->haspages) {
|
||||
return $data;
|
||||
|
2
lib/table/amd/build/dynamic.min.js
vendored
2
lib/table/amd/build/dynamic.min.js
vendored
@@ -1,2 +1,2 @@
|
||||
define ("core_table/dynamic",["exports","core_table/local/dynamic/repository","core_table/local/dynamic/selectors"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=a.setLastInitial=a.setFirstInitial=a.setSortOrder=a.setFilters=a.updateTable=a.refreshTableContent=void 0;c=function(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}(c);function d(a){return g(a)||f(a)||e()}function e(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function f(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function g(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++){c[b]=a[b]}return c}}var h=!1,i=function(a){if(!a){throw new Error("The table specified is not a dynamic table and cannot be updated")}if(!a.matches(c.main.region)){throw new Error("The table specified is not a dynamic table and cannot be updated")}return!0},j=function(a){return JSON.parse(a.dataset.tableFilters)},k=function(a){var c=j(a);return(0,b.fetch)(a.dataset.tableHandler,a.dataset.tableUniqueid,{sortBy:a.dataset.tableSortBy,sortOrder:a.dataset.tableSortOrder,joinType:c.jointype,filters:c.filters,firstinitial:a.dataset.tableFirstInitial,lastinitial:a.dataset.tableLastInitial}).then(function(b){var c=document.createElement("div");c.innerHTML=b.html;a.replaceWith.apply(a,d(c.childNodes));return b})};a.refreshTableContent=k;var l=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},c=b.sortBy,d=void 0===c?null:c,e=b.sortOrder,f=void 0===e?null:e,g=b.filters,h=void 0===g?null:g,j=b.firstInitial,l=void 0===j?null:j,m=b.lastInitial,n=void 0===m?null:m,o=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;i(a);if(d&&f){a.dataset.tableSortBy=d;a.dataset.tableSortOrder=f}if(null!==l){a.dataset.tableFirstInitial=l}if(null!==n){a.dataset.tableLastInitial=n}if(h){a.dataset.tableFilters=JSON.stringify(h)}if(o){return k(a)}else{return Promise.resolve()}};a.updateTable=l;a.setFilters=function setFilters(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{filters:b},c)};var m=function(a,b,c){var d=3<arguments.length&&arguments[3]!==void 0?arguments[3]:!0;return l(a,{sortBy:b,sortOrder:c},d)};a.setSortOrder=m;var n=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{firstInitial:b},c)};a.setFirstInitial=n;var o=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{lastInitial:b},c)};a.setLastInitial=o;var p=function(){if(h){return}h=!0;document.addEventListener("click",function(a){var b=a.target.closest(c.main.region);if(!b){return}var d=a.target.closest(c.table.links.sortableColumn);if(d){a.preventDefault();m(b,d.dataset.sortby,d.dataset.sortorder)}var e=a.target.closest(c.initialsBar.links.firstInitial);if(null!==e){a.preventDefault();n(b,e.dataset.initial)}var f=a.target.closest(c.initialsBar.links.lastInitial);if(null!==f){a.preventDefault();o(b,f.dataset.initial)}})};a.init=p});
|
||||
define ("core_table/dynamic",["exports","core_table/local/dynamic/repository","core_table/local/dynamic/selectors"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=a.setLastInitial=a.setFirstInitial=a.setPageSize=a.setPageNumber=a.setSortOrder=a.setFilters=a.updateTable=a.refreshTableContent=void 0;c=function(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}(c);function d(a){return g(a)||f(a)||e()}function e(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function f(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function g(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++){c[b]=a[b]}return c}}var h=!1,i=function(a){if(!a){throw new Error("The table specified is not a dynamic table and cannot be updated")}if(!a.matches(c.main.region)){throw new Error("The table specified is not a dynamic table and cannot be updated")}return!0},j=function(a){return JSON.parse(a.dataset.tableFilters)},k=function(a){var c=j(a);return(0,b.fetch)(a.dataset.tableHandler,a.dataset.tableUniqueid,{sortBy:a.dataset.tableSortBy,sortOrder:a.dataset.tableSortOrder,joinType:c.jointype,filters:c.filters,firstinitial:a.dataset.tableFirstInitial,lastinitial:a.dataset.tableLastInitial,pageNumber:a.dataset.tablePageNumber,pageSize:a.dataset.tablePageSize}).then(function(b){var c=document.createElement("div");c.innerHTML=b.html;a.replaceWith.apply(a,d(c.childNodes));return b})};a.refreshTableContent=k;var l=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},c=b.sortBy,d=void 0===c?null:c,e=b.sortOrder,f=void 0===e?null:e,g=b.filters,h=void 0===g?null:g,j=b.firstInitial,l=void 0===j?null:j,m=b.lastInitial,n=void 0===m?null:m,o=b.pageNumber,p=void 0===o?null:o,q=b.pageSize,r=void 0===q?null:q,s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;i(a);if(d&&f){a.dataset.tableSortBy=d;a.dataset.tableSortOrder=f}if(null!==l){a.dataset.tableFirstInitial=l}if(null!==n){a.dataset.tableLastInitial=n}if(null!==p){a.dataset.tablePageNumber=p}if(null!==r){a.dataset.tablePageSize=r}if(h){a.dataset.tableFilters=JSON.stringify(h)}if(s){return k(a)}else{return Promise.resolve()}};a.updateTable=l;a.setFilters=function setFilters(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{filters:b},c)};var m=function(a,b,c){var d=3<arguments.length&&arguments[3]!==void 0?arguments[3]:!0;return l(a,{sortBy:b,sortOrder:c},d)};a.setSortOrder=m;var n=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{pageNumber:b},c)};a.setPageNumber=n;a.setPageSize=function setPageSize(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{pageSize:b,pageNumber:0},c)};var o=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{firstInitial:b},c)};a.setFirstInitial=o;var p=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{lastInitial:b},c)};a.setLastInitial=p;var q=function(){if(h){return}h=!0;document.addEventListener("click",function(a){var b=a.target.closest(c.main.region);if(!b){return}var d=a.target.closest(c.table.links.sortableColumn);if(d){a.preventDefault();m(b,d.dataset.sortby,d.dataset.sortorder)}var e=a.target.closest(c.initialsBar.links.firstInitial);if(null!==e){a.preventDefault();o(b,e.dataset.initial)}var f=a.target.closest(c.initialsBar.links.lastInitial);if(null!==f){a.preventDefault();p(b,f.dataset.initial)}var g=a.target.closest(c.paginationBar.links.pageItem);if(g){a.preventDefault();n(b,g.dataset.pageNumber)}})};a.init=q});
|
||||
//# sourceMappingURL=dynamic.min.js.map
|
||||
|
File diff suppressed because one or more lines are too long
@@ -1,2 +1,2 @@
|
||||
define ("core_table/local/dynamic/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.fetch=void 0;a.fetch=function fetch(a,c){var d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:{},e=d.sortBy,f=void 0===e?null:e,g=d.sortOrder,h=void 0===g?null:g,i=d.joinType,j=void 0===i?null:i,k=d.filters,l=void 0===k?{}:k,m=d.firstinitial,n=void 0===m?null:m,o=d.lastinitial,p=void 0===o?null:o;return(0,b.call)([{methodname:"core_table_dynamic_fetch",args:{handler:a,uniqueid:c,sortby:f,sortorder:h,jointype:j,filters:l,firstinitial:n,lastinitial:p}}])[0]}});
|
||||
define ("core_table/local/dynamic/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.fetch=void 0;a.fetch=function fetch(a,c){var d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:{},e=d.sortBy,f=void 0===e?null:e,g=d.sortOrder,h=void 0===g?null:g,i=d.joinType,j=void 0===i?null:i,k=d.filters,l=void 0===k?{}:k,m=d.firstinitial,n=void 0===m?null:m,o=d.lastinitial,p=void 0===o?null:o,q=d.pageNumber,r=void 0===q?null:q,s=d.pageSize,t=void 0===s?null:s;return(0,b.call)([{methodname:"core_table_dynamic_fetch",args:{handler:a,uniqueid:c,sortby:f,sortorder:h,jointype:j,filters:l,firstinitial:n,lastinitial:p,pagenumber:r,pagesize:t}}])[0]}});
|
||||
//# sourceMappingURL=repository.min.js.map
|
||||
|
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/dynamic/repository.js"],"names":["fetch","handler","uniqueid","sortBy","sortOrder","joinType","filters","firstinitial","lastinitial","methodname","args","sortby","sortorder","jointype"],"mappings":"yKAsCqB,QAARA,CAAAA,KAAQ,CAACC,CAAD,CAAUC,CAAV,CAQhB,8DADG,EACH,KAPGC,MAOH,CAPGA,CAOH,YAPY,IAOZ,OANGC,SAMH,CANGA,CAMH,YANe,IAMf,OALGC,QAKH,CALGA,CAKH,YALc,IAKd,OAJGC,OAIH,CAJGA,CAIH,YAJa,EAIb,OAHGC,YAGH,CAHGA,CAGH,YAHkB,IAGlB,OAFGC,WAEH,CAFGA,CAEH,YAFiB,IAEjB,GACD,MAAO,WAAU,CAAC,CACdC,UAAU,2BADI,CAEdC,IAAI,CAAE,CACFT,OAAO,CAAPA,CADE,CAEFC,QAAQ,CAARA,CAFE,CAGFS,MAAM,CAAER,CAHN,CAIFS,SAAS,CAAER,CAJT,CAKFS,QAAQ,CAAER,CALR,CAMFC,OAAO,CAAPA,CANE,CAOFC,YAAY,CAAZA,CAPE,CAQFC,WAAW,CAAXA,CARE,CAFQ,CAAD,CAAV,EAYH,CAZG,CAaV,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * A javascript module to handle calendar ajax actions.\n *\n * @module core_calendar/repository\n * @class repository\n * @package core_calendar\n * @copyright 2017 Simey Lameze <lameze@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {call as fetchMany} from 'core/ajax';\n\n/**\n * Fetch table view.\n *\n * @method fetch\n * @param {String} handler The name of the handler\n * @param {String} uniqueid The unique id of the table\n * @param {Object} filters The filters to apply when searching\n * @param {String} firstinitial The first name initial to filter on\n * @param {String} lastinitial The last name initial to filter on\n * @param {Number} params parameters to request table\n * @return {Promise} Resolved with requested table view\n */\nexport const fetch = (handler, uniqueid, {\n sortBy = null,\n sortOrder = null,\n joinType = null,\n filters = {},\n firstinitial = null,\n lastinitial = null,\n } = {}\n) => {\n return fetchMany([{\n methodname: `core_table_dynamic_fetch`,\n args: {\n handler,\n uniqueid,\n sortby: sortBy,\n sortorder: sortOrder,\n jointype: joinType,\n filters,\n firstinitial,\n lastinitial,\n },\n }])[0];\n};\n"],"file":"repository.min.js"}
|
||||
{"version":3,"sources":["../../../src/local/dynamic/repository.js"],"names":["fetch","handler","uniqueid","sortBy","sortOrder","joinType","filters","firstinitial","lastinitial","pageNumber","pageSize","methodname","args","sortby","sortorder","jointype","pagenumber","pagesize"],"mappings":"yKAwCqB,QAARA,CAAAA,KAAQ,CAACC,CAAD,CAAUC,CAAV,CAUhB,8DADG,EACH,KATGC,MASH,CATGA,CASH,YATY,IASZ,OARGC,SAQH,CARGA,CAQH,YARe,IAQf,OAPGC,QAOH,CAPGA,CAOH,YAPc,IAOd,OANGC,OAMH,CANGA,CAMH,YANa,EAMb,OALGC,YAKH,CALGA,CAKH,YALkB,IAKlB,OAJGC,WAIH,CAJGA,CAIH,YAJiB,IAIjB,OAHGC,UAGH,CAHGA,CAGH,YAHgB,IAGhB,OAFGC,QAEH,CAFGA,CAEH,YAFc,IAEd,GACD,MAAO,WAAU,CAAC,CACdC,UAAU,2BADI,CAEdC,IAAI,CAAE,CACFX,OAAO,CAAPA,CADE,CAEFC,QAAQ,CAARA,CAFE,CAGFW,MAAM,CAAEV,CAHN,CAIFW,SAAS,CAAEV,CAJT,CAKFW,QAAQ,CAAEV,CALR,CAMFC,OAAO,CAAPA,CANE,CAOFC,YAAY,CAAZA,CAPE,CAQFC,WAAW,CAAXA,CARE,CASFQ,UAAU,CAAEP,CATV,CAUFQ,QAAQ,CAAEP,CAVR,CAFQ,CAAD,CAAV,EAcH,CAdG,CAeV,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * A javascript module to handle calendar ajax actions.\n *\n * @module core_calendar/repository\n * @class repository\n * @package core_calendar\n * @copyright 2017 Simey Lameze <lameze@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {call as fetchMany} from 'core/ajax';\n\n/**\n * Fetch table view.\n *\n * @method fetch\n * @param {String} handler The name of the handler\n * @param {String} uniqueid The unique id of the table\n * @param {Object} filters The filters to apply when searching\n * @param {String} firstinitial The first name initial to filter on\n * @param {String} lastinitial The last name initial to filter on\n * @param {String} pageNumber The page number\n * @param {Number} pageSize The page size\n * @param {Number} params parameters to request table\n * @return {Promise} Resolved with requested table view\n */\nexport const fetch = (handler, uniqueid, {\n sortBy = null,\n sortOrder = null,\n joinType = null,\n filters = {},\n firstinitial = null,\n lastinitial = null,\n pageNumber = null,\n pageSize = null,\n } = {}\n) => {\n return fetchMany([{\n methodname: `core_table_dynamic_fetch`,\n args: {\n handler,\n uniqueid,\n sortby: sortBy,\n sortorder: sortOrder,\n jointype: joinType,\n filters,\n firstinitial,\n lastinitial,\n pagenumber: pageNumber,\n pagesize: pageSize,\n },\n }])[0];\n};\n"],"file":"repository.min.js"}
|
@@ -1,2 +1,2 @@
|
||||
define ("core_table/local/dynamic/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={main:{region:"[data-region=\"core_table/dynamic\"]"},table:{links:{sortableColumn:"a[data-sortable=\"1\"]"}},initialsBar:{links:{firstInitial:".firstinitial [data-initial]",lastInitial:".lastinitial [data-initial]"}}};return a.default});
|
||||
define ("core_table/local/dynamic/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={main:{region:"[data-region=\"core_table/dynamic\"]"},table:{links:{sortableColumn:"a[data-sortable=\"1\"]"}},initialsBar:{links:{firstInitial:".firstinitial [data-initial]",lastInitial:".lastinitial [data-initial]"}},paginationBar:{links:{pageItem:".pagination [data-page-number]"}}};return a.default});
|
||||
//# sourceMappingURL=selectors.min.js.map
|
||||
|
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/dynamic/selectors.js"],"names":["main","region","table","links","sortableColumn","initialsBar","firstInitial","lastInitial"],"mappings":"8JAuBe,CACXA,IAAI,CAAE,CACFC,MAAM,CAAE,sCADN,CADK,CAIXC,KAAK,CAAE,CACHC,KAAK,CAAE,CACHC,cAAc,CAAE,wBADb,CADJ,CAJI,CASXC,WAAW,CAAE,CACTF,KAAK,CAAE,CACHG,YAAY,CAAE,8BADX,CAEHC,WAAW,CAAE,6BAFV,CADE,CATF,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Dynamic table selectors.\n *\n * @module core_table/selectors\n * @package core_table\n * @copyright 2020 Simey Lameze <simey@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n main: {\n region: '[data-region=\"core_table/dynamic\"]',\n },\n table: {\n links: {\n sortableColumn: 'a[data-sortable=\"1\"]',\n },\n },\n initialsBar: {\n links: {\n firstInitial: '.firstinitial [data-initial]',\n lastInitial: '.lastinitial [data-initial]',\n },\n },\n};\n"],"file":"selectors.min.js"}
|
||||
{"version":3,"sources":["../../../src/local/dynamic/selectors.js"],"names":["main","region","table","links","sortableColumn","initialsBar","firstInitial","lastInitial","paginationBar","pageItem"],"mappings":"8JAuBe,CACXA,IAAI,CAAE,CACFC,MAAM,CAAE,sCADN,CADK,CAIXC,KAAK,CAAE,CACHC,KAAK,CAAE,CACHC,cAAc,CAAE,wBADb,CADJ,CAJI,CASXC,WAAW,CAAE,CACTF,KAAK,CAAE,CACHG,YAAY,CAAE,8BADX,CAEHC,WAAW,CAAE,6BAFV,CADE,CATF,CAeXC,aAAa,CAAE,CACXL,KAAK,CAAE,CACHM,QAAQ,CAAE,gCADP,CADI,CAfJ,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Dynamic table selectors.\n *\n * @module core_table/selectors\n * @package core_table\n * @copyright 2020 Simey Lameze <simey@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n main: {\n region: '[data-region=\"core_table/dynamic\"]',\n },\n table: {\n links: {\n sortableColumn: 'a[data-sortable=\"1\"]',\n },\n },\n initialsBar: {\n links: {\n firstInitial: '.firstinitial [data-initial]',\n lastInitial: '.lastinitial [data-initial]',\n },\n },\n paginationBar: {\n links: {\n pageItem: '.pagination [data-page-number]'\n }\n },\n};\n"],"file":"selectors.min.js"}
|
@@ -75,6 +75,8 @@ export const refreshTableContent = tableRoot => {
|
||||
filters: filterset.filters,
|
||||
firstinitial: tableRoot.dataset.tableFirstInitial,
|
||||
lastinitial: tableRoot.dataset.tableLastInitial,
|
||||
pageNumber: tableRoot.dataset.tablePageNumber,
|
||||
pageSize: tableRoot.dataset.tablePageSize,
|
||||
}
|
||||
)
|
||||
.then(data => {
|
||||
@@ -92,6 +94,8 @@ export const updateTable = (tableRoot, {
|
||||
filters = null,
|
||||
firstInitial = null,
|
||||
lastInitial = null,
|
||||
pageNumber = null,
|
||||
pageSize = null,
|
||||
} = {}, refreshContent = true) => {
|
||||
checkTableIsDynamic(tableRoot);
|
||||
|
||||
@@ -110,6 +114,14 @@ export const updateTable = (tableRoot, {
|
||||
tableRoot.dataset.tableLastInitial = lastInitial;
|
||||
}
|
||||
|
||||
if (pageNumber !== null) {
|
||||
tableRoot.dataset.tablePageNumber = pageNumber;
|
||||
}
|
||||
|
||||
if (pageSize !== null) {
|
||||
tableRoot.dataset.tablePageSize = pageSize;
|
||||
}
|
||||
|
||||
// Update filters.
|
||||
if (filters) {
|
||||
tableRoot.dataset.tableFilters = JSON.stringify(filters);
|
||||
@@ -146,6 +158,28 @@ export const setFilters = (tableRoot, filters, refreshContent = true) =>
|
||||
export const setSortOrder = (tableRoot, sortBy, sortOrder, refreshContent = true) =>
|
||||
updateTable(tableRoot, {sortBy, sortOrder}, refreshContent);
|
||||
|
||||
/**
|
||||
* Set the page number.
|
||||
*
|
||||
* @param {HTMLElement} tableRoot
|
||||
* @param {String} pageNumber
|
||||
* @param {Bool} refreshContent
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export const setPageNumber = (tableRoot, pageNumber, refreshContent = true) =>
|
||||
updateTable(tableRoot, {pageNumber}, refreshContent);
|
||||
|
||||
/**
|
||||
* Set the page size.
|
||||
*
|
||||
* @param {HTMLElement} tableRoot
|
||||
* @param {Number} pageSize
|
||||
* @param {Bool} refreshContent
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export const setPageSize = (tableRoot, pageSize, refreshContent = true) =>
|
||||
updateTable(tableRoot, {pageSize, pageNumber: 0}, refreshContent);
|
||||
|
||||
/**
|
||||
* Update the first initial to show.
|
||||
*
|
||||
@@ -205,5 +239,12 @@ export const init = () => {
|
||||
|
||||
setLastInitial(tableRoot, lastInitialLink.dataset.initial);
|
||||
}
|
||||
|
||||
const pageItem = e.target.closest(Selectors.paginationBar.links.pageItem);
|
||||
if (pageItem) {
|
||||
e.preventDefault();
|
||||
|
||||
setPageNumber(tableRoot, pageItem.dataset.pageNumber);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@@ -33,6 +33,8 @@ import {call as fetchMany} from 'core/ajax';
|
||||
* @param {Object} filters The filters to apply when searching
|
||||
* @param {String} firstinitial The first name initial to filter on
|
||||
* @param {String} lastinitial The last name initial to filter on
|
||||
* @param {String} pageNumber The page number
|
||||
* @param {Number} pageSize The page size
|
||||
* @param {Number} params parameters to request table
|
||||
* @return {Promise} Resolved with requested table view
|
||||
*/
|
||||
@@ -43,6 +45,8 @@ export const fetch = (handler, uniqueid, {
|
||||
filters = {},
|
||||
firstinitial = null,
|
||||
lastinitial = null,
|
||||
pageNumber = null,
|
||||
pageSize = null,
|
||||
} = {}
|
||||
) => {
|
||||
return fetchMany([{
|
||||
@@ -56,6 +60,8 @@ export const fetch = (handler, uniqueid, {
|
||||
filters,
|
||||
firstinitial,
|
||||
lastinitial,
|
||||
pagenumber: pageNumber,
|
||||
pagesize: pageSize,
|
||||
},
|
||||
}])[0];
|
||||
};
|
||||
|
@@ -36,4 +36,9 @@ export default {
|
||||
lastInitial: '.lastinitial [data-initial]',
|
||||
},
|
||||
},
|
||||
paginationBar: {
|
||||
links: {
|
||||
pageItem: '.pagination [data-page-number]'
|
||||
}
|
||||
},
|
||||
};
|
||||
|
34
lib/table/classes/external/dynamic/fetch.php
vendored
34
lib/table/classes/external/dynamic/fetch.php
vendored
@@ -98,6 +98,18 @@ class fetch extends external_api {
|
||||
VALUE_REQUIRED,
|
||||
null
|
||||
),
|
||||
'pagenumber' => new external_value(
|
||||
PARAM_INT,
|
||||
'The page number',
|
||||
VALUE_REQUIRED,
|
||||
null
|
||||
),
|
||||
'pagesize' => new external_value(
|
||||
PARAM_INT,
|
||||
'The number of records per page',
|
||||
VALUE_REQUIRED,
|
||||
null
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -112,6 +124,9 @@ class fetch extends external_api {
|
||||
* @param string $jointype The join type.
|
||||
* @param string $firstinitial The first name initial to filter on
|
||||
* @param string $lastinitial The last name initial to filter on
|
||||
* @param int $pagenumber The page number.
|
||||
* @param int $pagesize The number of records.
|
||||
* @param string $jointype The join type.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -123,7 +138,9 @@ class fetch extends external_api {
|
||||
?array $filters = null,
|
||||
?string $jointype = null,
|
||||
?string $firstinitial = null,
|
||||
?string $lastinitial = null
|
||||
?string $lastinitial = null,
|
||||
?int $pagenumber = null,
|
||||
?int $pagesize = null
|
||||
) {
|
||||
|
||||
global $PAGE;
|
||||
@@ -141,6 +158,8 @@ class fetch extends external_api {
|
||||
'jointype' => $jointype,
|
||||
'firstinitial' => $firstinitial,
|
||||
'lastinitial' => $lastinitial,
|
||||
'pagenumber' => $pagenumber,
|
||||
'pagesize' => $pagesize,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'handler' => $handler,
|
||||
'uniqueid' => $uniqueid,
|
||||
@@ -150,6 +169,8 @@ class fetch extends external_api {
|
||||
'jointype' => $jointype,
|
||||
'firstinitial' => $firstinitial,
|
||||
'lastinitial' => $lastinitial,
|
||||
'pagenumber' => $pagenumber,
|
||||
'pagesize' => $pagesize,
|
||||
]);
|
||||
|
||||
$filterset = new \core_user\table\participants_filterset();
|
||||
@@ -173,13 +194,20 @@ class fetch extends external_api {
|
||||
$instance->set_last_initial($lastinitial);
|
||||
}
|
||||
|
||||
$context = $instance->get_context();
|
||||
if ($pagenumber !== null) {
|
||||
$instance->set_page_number($pagenumber);
|
||||
}
|
||||
|
||||
if ($pagesize === null) {
|
||||
$pagesize = 20;
|
||||
}
|
||||
|
||||
$context = $instance->get_context();
|
||||
self::validate_context($context);
|
||||
$PAGE->set_url($instance->get_base_url());
|
||||
|
||||
ob_start();
|
||||
$instance->out(20, true);
|
||||
$instance->out($pagesize, true);
|
||||
$participanttablehtml = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
|
@@ -549,7 +549,10 @@ class flexible_table {
|
||||
$this->baseurl = $PAGE->url;
|
||||
}
|
||||
|
||||
$this->currpage = optional_param($this->request[TABLE_VAR_PAGE], 0, PARAM_INT);
|
||||
if ($this->currpage == null) {
|
||||
$this->currpage = optional_param($this->request[TABLE_VAR_PAGE], 0, PARAM_INT);
|
||||
}
|
||||
|
||||
$this->setup = true;
|
||||
|
||||
// Always introduce the "flexible" class for the table if not specified
|
||||
@@ -1406,6 +1409,15 @@ class flexible_table {
|
||||
$this->ilast = $initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the page number.
|
||||
*
|
||||
* @param int $pagenumber The page number.
|
||||
*/
|
||||
public function set_page_number(int $pagenumber): void {
|
||||
$this->currpage = $pagenumber - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the HTML for the sort icon. This is a helper method used by {@link sort_link()}.
|
||||
* @param bool $isprimary whether an icon is needed (it is only needed for the primary sort column.)
|
||||
@@ -1505,6 +1517,8 @@ class flexible_table {
|
||||
'data-table-sort-order' => $sortdata['sortorder'],
|
||||
'data-table-first-initial' => $this->prefs['i_first'],
|
||||
'data-table-last-initial' => $this->prefs['i_last'],
|
||||
'data-table-page-number' => $this->currpage + 1,
|
||||
'data-table-page-size' => $this->pagesize,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -1810,6 +1824,7 @@ class table_sql extends flexible_table {
|
||||
$this->define_columns(array_keys((array)$onerow));
|
||||
$this->define_headers(array_keys((array)$onerow));
|
||||
}
|
||||
$this->pagesize = $pagesize;
|
||||
$this->setup();
|
||||
$this->query_db($pagesize, $useinitialsbar);
|
||||
$this->build_table();
|
||||
|
@@ -1,8 +1,8 @@
|
||||
{{#haspages}}
|
||||
<nav aria-label="{{label}}" class="pagination pagination-centered justify-content-center">
|
||||
<ul class="mt-1 pagination ">
|
||||
<ul class="mt-1 pagination " data-page-size="{{pagesize}}">
|
||||
{{#previous}}
|
||||
<li class="page-item">
|
||||
<li class="page-item" data-page-number="{{page}}">
|
||||
<a href="{{url}}" class="page-link" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
<span class="sr-only">{{#str}}previous{{/str}}</span>
|
||||
@@ -10,15 +10,15 @@
|
||||
</li>
|
||||
{{/previous}}
|
||||
{{#first}}
|
||||
<li class="page-item">
|
||||
<li class="page-item" data-page-number="{{page}}">
|
||||
<a href="{{url}}" class="page-link">{{page}}</a>
|
||||
</li>
|
||||
<li class="page-item disabled">
|
||||
<li class="page-item disabled" data-page-number="{{page}}">
|
||||
<span class="page-link">…</a>
|
||||
</li>
|
||||
{{/first}}
|
||||
{{#pages}}
|
||||
<li class="page-item {{#active}}active{{/active}}">
|
||||
<li class="page-item {{#active}}active{{/active}}" data-page-number="{{page}}">
|
||||
<a href="{{#url}}{{.}}{{/url}}{{^url}}#{{/url}}" class="page-link">
|
||||
{{page}}
|
||||
{{#active}}
|
||||
@@ -28,15 +28,15 @@
|
||||
</li>
|
||||
{{/pages}}
|
||||
{{#last}}
|
||||
<li class="page-item disabled">
|
||||
<li class="page-item disabled" data-page-number="{{page}}">
|
||||
<span class="page-link">…</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<li class="page-item" data-page-number="{{page}}">
|
||||
<a href="{{url}}" class="page-link">{{page}}</a>
|
||||
</li>
|
||||
{{/last}}
|
||||
{{#next}}
|
||||
<li class="page-item">
|
||||
<li class="page-item" data-page-number="{{page}}">
|
||||
<a href="{{url}}" class="page-link" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
<span class="sr-only">{{#str}}next{{/str}}</span>
|
||||
|
Reference in New Issue
Block a user