fiduswriter / simple-datatables

DataTables but in TypeScript transpiled to Vanilla JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] sorting negative numbers

NSV-dev opened this issue · comments

  • 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

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?

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