alfajango / jquery-dynatable

A more-fun, semantic, alternative to datatables
http://www.dynatable.com
Other
2.77k stars 363 forks source link

Integer sorting not working 0.3.1 #226

Open Samuel1989 opened 8 years ago

Samuel1989 commented 8 years ago

Hey Guys,

I have read the previous issues around this and I have been unable to get this to work.

I have tried the following readers:

                                readers: {
                    'name': function(el, record) {
                        return Number(el.innerHTML);
                    }
                }

And the following writers:

                                writers: {
                    'name': function(record) {
                        return record.name.toString();
                    }
                }

But when I click the on the headers it still sorts them as if they were a string (9 being higher than 100 for e.g.).

Any help would be greatly appreciated.

Sam

kmilligan commented 7 years ago

I know this is an old thread, but I just ran into this issue; not sure that this applies to your case, but in my case, I discovered that if I am providing the records "manually" via dataset.records (instead of reading the data from an existing table) that the reader functions are not called -- so I ended up having to pre-process my JSON to convert the values to numbers before giving the records to dynatable.

cameraki commented 6 years ago

Same as @kmilligan.

My server side code is in PHP so I just converted the values before it was sent to dynatable.

In my case it was this: (int)$order->getOrderId();

Using (int) to convert the values to an integer.

I did not use readers or writers, just added the (int) and it worked.