Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all (most) tables sortable #117

Merged
merged 2 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -77161,7 +77161,21 @@ const applyDatatables = () => {
const doNotProcess = element.querySelectorAll('[colspan],[rowspan]').length;

// Don't process anything with less than 40 rows
if (rows < 40 || doNotProcess) return;
if (doNotProcess) return;

// Bootstrap style tables, with responsive table
let dom = `<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>><'row table-responsive'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 text-center'p>>`;
// How many items per page
let pageLength = 25;
// How to order our pages
let order = [[0, 'asc']];

// If we have less than 40 rows, we don't need pagination, but table will still be sortable
if (rows < 40) {
pageLength = 40;
dom = `<'row'<'col-sm-12 col-md-6'><'col-sm-12 col-md-6'>><'row table-responsive'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'><'col-sm-12 col-md-7 text-center'>>`
order = [];
}

$(element).DataTable({
// Remember page/search/order
Expand All @@ -77178,12 +77192,11 @@ const applyDatatables = () => {
stateLoadCallback: function(settings) {
return JSON.parse(sessionStorage.getItem(`DataTables_${Wiki.pageType()}_${Wiki.pageName()}_${i}`) || '{}');
},
// Bootstrap style tables, with responsive table
dom: `<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>><'row table-responsive'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 text-center'p>>`,
// Our custom page implementation
dom,
pageLength,
order,
// Our custom page implementation
pagingType: 'simple_numbers_no_ellipses',
// How many items per page
pageLength: 25,
// Adjust text
language: {
paginate: {
Expand Down Expand Up @@ -77937,6 +77950,7 @@ onhashchange = (event) => {
pageElementCustom.html('');
}
}).always(() => {
applyDatatables();
if (other == 'edit') {
// Initialise markdown editor
createMarkDownEditor('custom-edit', customContentFileName);
Expand All @@ -77959,6 +77973,7 @@ onhashchange = (event) => {
pageElementCustomDescription.html('');
}
}).always(() => {
applyDatatables();
if (other == 'edit') {
// Initialise markdown editor
createMarkDownEditor('custom-edit-desc', customContentDescFileName);
Expand All @@ -77980,6 +77995,7 @@ $(document).ready(() => {
ko.applyBindings({}, document.getElementById('breadcrumbs'));
ko.applyBindings({}, document.getElementById('settings-modal'));
ko.applyBindings({}, document.getElementById('footer'));

applyBindings.subscribe((v) => {
// Unbind and re-bind knockout
if (v) {
Expand Down
25 changes: 19 additions & 6 deletions scripts/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ const applyDatatables = () => {
const doNotProcess = element.querySelectorAll('[colspan],[rowspan]').length;

// Don't process anything with less than 40 rows
if (rows < 40 || doNotProcess) return;
if (doNotProcess) return;

// Bootstrap style tables, with responsive table
let dom = `<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>><'row table-responsive'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 text-center'p>>`;
// How many items per page
let pageLength = 25;
// How to order our pages
let order = [[0, 'asc']];

// If we have less than 40 rows, we don't need pagination, but table will still be sortable
if (rows < 40) {
pageLength = 40;
dom = `<'row'<'col-sm-12 col-md-6'><'col-sm-12 col-md-6'>><'row table-responsive'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'><'col-sm-12 col-md-7 text-center'>>`
order = [];
}

$(element).DataTable({
// Remember page/search/order
Expand All @@ -25,12 +39,11 @@ const applyDatatables = () => {
stateLoadCallback: function(settings) {
return JSON.parse(sessionStorage.getItem(`DataTables_${Wiki.pageType()}_${Wiki.pageName()}_${i}`) || '{}');
},
// Bootstrap style tables, with responsive table
dom: `<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>><'row table-responsive'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 text-center'p>>`,
// Our custom page implementation
dom,
pageLength,
order,
// Our custom page implementation
pagingType: 'simple_numbers_no_ellipses',
// How many items per page
pageLength: 25,
// Adjust text
language: {
paginate: {
Expand Down
3 changes: 3 additions & 0 deletions scripts/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ onhashchange = (event) => {
pageElementCustom.html('');
}
}).always(() => {
applyDatatables();
if (other == 'edit') {
// Initialise markdown editor
createMarkDownEditor('custom-edit', customContentFileName);
Expand All @@ -133,6 +134,7 @@ onhashchange = (event) => {
pageElementCustomDescription.html('');
}
}).always(() => {
applyDatatables();
if (other == 'edit') {
// Initialise markdown editor
createMarkDownEditor('custom-edit-desc', customContentDescFileName);
Expand All @@ -154,6 +156,7 @@ $(document).ready(() => {
ko.applyBindings({}, document.getElementById('breadcrumbs'));
ko.applyBindings({}, document.getElementById('settings-modal'));
ko.applyBindings({}, document.getElementById('footer'));

applyBindings.subscribe((v) => {
// Unbind and re-bind knockout
if (v) {
Expand Down