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

Support showing all rows as a length option in DataTables #868

Merged
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
1 change: 1 addition & 0 deletions Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@
'ext.srf.widgets'
],
'messages' => [
'allmessages-filter-all',
'srf-ui-datatables-label-conditions',
'srf-ui-datatables-label-parameters',
'srf-ui-datatables-label-filters',
Expand Down
8 changes: 8 additions & 0 deletions formats/datatables/resources/ext.srf.formats.datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,14 @@
});
}

// Replace -1 in lengthMenu with 'all' label
var showAll = options.lengthMenu.indexOf( -1 );
if ( showAll !== -1 ) {
var labels = options.lengthMenu.slice();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the slice()?

Copy link
Contributor Author

@alistair3149 alistair3149 Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to clone the array so that the original options.lengthMenu wouldn't be altered.

I'm not sure what is the stance on ES6 in the project so I didn't use spread operators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so that the original options.lengthMenu wouldn't be altered.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Line 566, we set two arrays to the lengthMenu. The first array is for the numerical values (-1 represents all, which is the original values), the second array is for the label (all represents -1).

labels[showAll] = mw.msg( 'allmessages-filter-all' ); // stealing MW core messages :D
options.lengthMenu = [ options.lengthMenu, labels ];
}

var query = data.query.ask;
var printouts = table.data("printouts");
var queryString = query.conditions;
Expand Down
Loading