datatables 1.10 shifts sorting to previous col-index ? why ?
datatables 1.10 shifts sorting to previous col-index ? why ?
babablacksheep
Posts: 41Questions: 23Answers: 0
Hi,
In datatables 1.10, if click oon header to sort column and then turn that column visibility of by api and reload table,
table shifts that sort (asc or desc) from hidden col to previous col while sending ajax params.
it just shifts sort info but u can see no classes applied to previous indexed col.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Can you please link to a test case showing the issue, as noted in the forum rules.
Allan
@allan
See jsfiddle: http://jsfiddle.net/bababalcksheep/ntcwust8/
[Object { column=0, dir="asc"}]
FirstName
button to togglecolumn-index-0
reload table
button to trigger ajax reload of table and check console again.[Object { column=0, dir="asc"}]
which is wrong becausecolumn-index-0
was originally FirstName col and turned off.I wish datatables do not change index of columns it created for the first time.
even if column visibility is changed for any number of columns. this way we can ref to column-index.
but as soon as you reorder or turn off column, indexes are changed and there is no way to track back to actual cols.
Dear @allan
possible solutions would be
so if column 2 is hidden , its index is reserved and should only refer to its column
Dear @allan,
based on answer http://datatables.net/forums/discussion/79/column-name-instead-of-index-for-sorting-filtering
Is there a way i can get order data by name instead of indexes ?
I am creating columns like
is there a possibility that datatables give me ordering in form of
[{ column="_id", dir="asc"}]
based on column names ?This statement is incorrect. You are assuming that hidden columns cannot be sorted, which is wrong. They can be.
The
column()
selector method will use the column data index unless the:visible
pseudo selector is specified (in which case it uses the visible index).So where you have:
That is wrong - it should be
data-column="1"
if you want to target the last name column usingdata-column
.Allan
thank you.
But is it possible to get order() data based on names instead of col indexes
Secondly Correct me if I am wrong, if a column is at position 2 and if it is hidden, it will still have index 2 , right ?
Ok I found the solution.
in
```
'ajax': {
type: 'POST',
'url': url,
'data': function (d) {
console.log(d.order);
return JSON.stringify( d );
}
}
'''
data has 2 keys , columns and order.and order index refer to index state of columns which is array.
What I was doing wrong that I was searching dom for every index in found in order while I should search in data.columns array which holds current state of table.
indexes reffered in data.order refer to data.columns very nicely.
SOLVED
The order information is based on the column data indexes. If you want the column name you would need to convert it.
Correct. Changing the visibility of a column doesn't alter its data index.
Allan