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

Feature request: Ability to sort assets by size in chunk view #28

Open
QuentinFchx opened this issue Feb 21, 2017 · 2 comments
Open

Feature request: Ability to sort assets by size in chunk view #28

QuentinFchx opened this issue Feb 21, 2017 · 2 comments

Comments

@QuentinFchx
Copy link

It's currently only possible in the main view

@a-r-d
Copy link
Contributor

a-r-d commented May 16, 2017

@QuentinFchx OK I marked this as an enhancement, I will merge this in if anyone can do the work and create a PR!

@davityavryan
Copy link

Before this will be merged.

Just open console and run

const dataTablesScript = document.createElement('script');
dataTablesScript.src = "https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js";
dataTablesScript.onload = function () {
    jQuery.fn.dataTable.ext.type.order["file-size-pre"] = function ( data ) {
        var matches = data.match( /^(\d+(?:\.\d+)?)\s*([a-z]+)/i );
    
        var multipliers = {
            b:  1,
            bytes: 1,
            kb: 1000,
            kib: 1024,
            mb: 1000000,
            mib: 1048576,
            gb: 1000000000,
            gib: 1073741824,
            tb: 1000000000000,
            tib: 1099511627776,
            pb: 1000000000000000,
            pib: 1125899906842624
        };
     
        if (matches) {
            var multiplier = multipliers[matches[2].toLowerCase()];
            return parseFloat( matches[1] ) * multiplier;
        } else {
            return -1;
        };
    };
    
    $('.table').eq(1).DataTable({
        columnDefs: [
           	{ type: "file-size", targets: 2 },
            { className: "sortable-th size-th", targets: [ 2 ] }
        ],
        order: [[ 2, "desc" ]],
        paging: false,
  		searching: false,
    });
};
document.body.appendChild(dataTablesScript);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants