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

[BUG] sorting negative numbers #357

Closed
2 tasks done
NSV-dev opened this issue Dec 5, 2023 · 2 comments
Closed
2 tasks done

[BUG] sorting negative numbers #357

NSV-dev opened this issue Dec 5, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@NSV-dev
Copy link

NSV-dev commented Dec 5, 2023

  • I have looked through the documentation to try to see if this behavior is documented.
  • I have looked at the demos to see if one of them handles this, but none of them did.

Describe the bug
Negative numbers sorts like they are positive

i'm using vue.js

html table:

<table class="table table-min-width" id="events-table">
    <thead>
        <tr>
            <th scope="col" class="col-3">{{ $t('message.userActivity.productivity.project') }}</th>
            <th scope="col" class="col-3">{{ $t('message.shared.utils.user') }}</th>
            <th data-sortable="false" scope="col" class="col-2">{{ $t('message.userActivity.productivity.task') }}</th>
            <th scope="col" class="col-2">{{ $t('message.shared.utils.activityType') }}</th>
            <th scope="col" class="col-2">{{ $t('message.shared.utils.timePeriod') }}</th>
            <th v-for="i in getIndicators()">{{ i.title }}</th>
        </tr>
    </thead>
    <tbody>
        <tr scope="row" v-for="item in resultArr">
            <td>{{item.project}}</td>
            <td>{{item.user}}</td>
            <td>{{item.task}}</td>
            <td>{{item.activityType}}</td>
            <td>{{moment.utc(item.from).local().format('YYYY-MM-DD')}}<br>
                {{moment.utc(item.from).local().format('HH:mm')}} - {{moment.utc(item.to).local().format('HH:mm')}}</td>
            <td v-for="i in getIndicators()">{{ item.kinds.filter(k => k.kind === i.kind)[0] ? item.kinds.filter(k => k.kind === i.kind)[0].value.toFixed(1) : '' }}</td>
        </tr>
    </tbody>
</table>

DataTable creation:

this.dataTable = new simpleDatatables.DataTable("#events-table", {
    searchable: false,            
    labels: {
        placeholder: this.$t('message.shared.placeholders.search'),
        perPage: '',
        info: '{start}-{end}/{rows}'
    },
    template: (options, dom) => 
`<div class='${options.classes.top}'></div>
<div class='${options.classes.container}'${options.scrollY.length ? ` style='height: ${options.scrollY}; overflow-Y: auto;'` : ""}></div>
<div class='d-flex justify-content-between align-items-center'>
    <div class='${options.classes.dropdown}'>
        <label>
            <select class='${options.classes.selector}'></select> ${options.labels.perPage}
        </label>
    </div>
    <div class='${options.classes.info}'></div>
    <nav class='${options.classes.pagination}'></nav>
</div>`
});
this.dataTable.update();

in result i get this:
image

i've tried:

  • data-type="number",
  • providing content as string in data-content and setting only numbers inside td,
  • numeric for whole table
  • wraping td value in parseFloat

item examle:
image

@NSV-dev NSV-dev added the bug Something isn't working label Dec 5, 2023
@clayton256
Copy link
Contributor

Maybe this is related... I have a column with 15 mins, 8.1 hours, 2.3 days, and 5.5 days. It gets sorted in alphanumeric order (15 mins, 2.3 days, 5.5 days, 8.1 hours). Of course even numerical order would not be correct. Is there some way to specify a custom sort function for a particular column?

@Timmmm
Copy link

Timmmm commented Feb 11, 2024

There's a ignorePunctuation option, maybe setting it to false would fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants