How Can I correct sort the column
How Can I correct sort the column
Volrecon
Posts: 8Questions: 1Answers: 0
Description of problem:
Hello,
I have the problem with second column. I have to sort the column but sort doesnt work correcly.
How can i do this?
Columns are type "string".
This discussion has been closed.
Answers
You can create a sorting plugin to custom sort that column. There may be a sorting plugin that might be close and help you get started. Take a look at natural, num-html and numString.
Guessing you only want to sort on the first number you could use Orthogonal data and return the leading number (or other data point) for the sorting operation.
Kevin
I created data-order="4534523" attribute in the td. Is that work?
Attribute was created in createdRow: function (row, data, dataIndex).
If your table is sourced from the DOM then it should work according to this:
https://datatables.net/manual/data/orthogonal-data#HTML-5
Kevin
thead is defined in HTLM but tbody is created from ajax API
data-order doesnt work
Thats correct. You can use
columns.render
. The example hasif ( type === 'display' || type === 'filter' )
. Instead useif ( type === 'order' )
.Kevin
The code doesnt work
Can you provide a running test case so we can help you debug the code?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I Will try send link tomorrow. Thx for help
Link to problem: live.datatables.net/hoteseyu/5/edit
No. Doesnt work. I have to create function to sort? How can i do that?
I didn't realize that your string is a Polish datetime format
I would use the Date time sorting solution documented in this blog. I updated your example to show this:
http://live.datatables.net/veqecoti/1/edit
The console log is outputting the format that Datatables automatically finds for the datetime column in both tables. Note that the first table works and sets the moment type but the second table its a string. The problem is with your first array element:
3 sekund
should be03 sekund
to match the format found in the other rows. Change it in the example then the sorting will work.Kevin
I thing it`s work Thx