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

Sorting for file size with KB, MB...? #54

Closed
weilinzung opened this issue Feb 4, 2020 · 5 comments
Closed

Sorting for file size with KB, MB...? #54

weilinzung opened this issue Feb 4, 2020 · 5 comments

Comments

@weilinzung
Copy link

Sorting for file size with KB, MB...?

@johanneswilm
Copy link
Member

Is this a feature you would like to program @weilinzung ? If so, we could add it.

@mbucas
Copy link

mbucas commented Aug 22, 2020

I had the same problem, because file sizes where formatted server-side.
However I found looking at the sources of the sort function of Simple-DataTables [1] that it can use an attribute "data-content" to sort data instead of the content of the cell which includes KB, MB, ...
So I've put the bytes file size in this attribute and now the sort uses it (note that I count 1024 bytes in 1 KB) :

 <td data-content="162155197" align="right">154.6&nbsp;MB</td>

It'd be nice if it appeared in the wiki !

[1] https://github.com/fiduswriter/Simple-DataTables/blob/db3671f2a5c43c16122e0a48b19c85d3a7f5cc10/src/columns.js#L364

@Stoakes
Copy link

Stoakes commented Jul 24, 2021

Hello,

I've been dealing with similar issue for an hour before eventually finding this thread, which greatly helped me. Thanks to you all.

So commenting here for search engines: data-content in Simple-Datatables is equivalent to DataTables data-sort or data-order

EDIT April 2024: The answer above was valid for simple-datatables < 6.0.0

When using a version >= 7.0.3, you must use data-order, as described in Getting started

@teemue
Copy link

teemue commented Aug 28, 2021

How do you actually set the data-content-value? I tried to set it after datatable.rows().add() but it gets cleared after sorting the column.

@Stoakes
Copy link

Stoakes commented Sep 5, 2021

My HTML is generated server side, so data-content come from there.

rhoit pushed a commit to beta-analytics/sdt that referenced this issue May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants