Sorting issue
Sorting issue
![Uzairkhan92](https://secure.gravatar.com/avatar/950e90a84d0b790133f751e35eb25826/?default=https%3A%2F%2Fvanillicon.com%2F950e90a84d0b790133f751e35eb25826_200.png&rating=g&size=120)
in General
Link to test case:
https://jsfiddle.net/z5rnv7mh/8/
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Hi, Above I have attached my demo grid.
I am unable to sort my grid although gird sorting was working fine and still having issues in the sorting of the last column *Todays Gain/Loss" in the grid.
Answers
You are getting this error:
Which is caused by this statement:
That suggests the
[4]
array index is out of bounds. Not sure what you goal is but you should validate the result ofdata.split(' ')
before trying to access the resulting array.The error is causing the Datatables functions to no work.
Kevin
Can you plz fix the problem in JS fiddle file, actually the last column of the grid is not sortable, It's not sorting properly grid data?
I did the exact work on other places its working fine.
As I said I don't know what you are trying to do with the above statements. I commented them out here and sorting works:
https://jsfiddle.net/j2du3ga6/
If any of the columns isn't sorting as you want then tell us how you expect it to sort.
Kevin
https://jsfiddle.net/osqaLc92/2/
Here is the URL of my DT grid. The last 3 columns are not sorted properly.
In the columns, there are mixed data, strings, numbers, and special characters, and also some negative values are there in the grid as well.
But Datatable default sorting is not working.
Can you plz check it out and guide me to the solution or fix the issue of the sorting.
You're going along the right path with
columns.render
, you just need to determine what you want to sort by. The "Cash" column appears to work, but the others are returning values like "(2.15%)" which would be treated like a string,Colin
So can you plz set a demo example? So that would be easy for me to understand.
You have data like this in the last two columns:
21,457 (2.15%)
. As I asked before what do you want to sort by? Its just a matter of using Javascript tools to parse the string the return the data you want sort by in this block of code:Kevin
I want to sort in Ascending and descending order, positive and negative values as well. The problem I am facing right now last column of the grid is not sorting orderly.
In negative values its showing the wrong sorting order.
The question is you have two numbers
21,457
and2.15%
in those columns. Which do you want to sort by?Kevin
I want to sort From 1st number 21,457.
I want to sort from 21,457
The first thing to do is to use regex101.com to build the proper regex expression to extract the data you want. You need to use everything in the cell including the
i
tag. For example:https://regex101.com/r/FqGOrP/1
The matched group has your number. For example:
https://jsfiddle.net/5bpxzja2/
Kevin