Topic: DataTables sort by numeric value and not string value
jasinskimathieu pro asked 2 weeks ago
I want to sort numeric value with html method, but it doesn't work. But, if I do the same with JS, it is word. Why ?
I use Datatables in HTML like this :
and if I try with JS, I have correct sort
This is due to the fact that in HTML all texts are always of type string. Even if you pass number or date it will be of type string. Look at this snippet: https://mdbootstrap.com/snippets/standard/grzegorz-bujanski/4619543#js-tab-view
Regardless of whether this data is provided - by HTML or added via JS, after checking the data type in HTML code, it will always be a string.
In datatables we do not change data types and it is also not possible to provide information about what type of data it is. Therefore, if you add data using HTML, for our datatable component all this data is a string. If you want to pass data of a type other than string, you have to pass it using JS.
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
- User: Pro
- Premium support: No
- Technology: MDB Standard
- MDB Version: MDB5 6.0.1
- Device: Pc
- Browser: Firefox
- OS: wINDOWS
- Provided sample code: No
- Provided link: No