How to detect column type in order to apply sort() by number or by string ?
How to detect column type in order to apply sort() by number or by string ?

Hi
I need to sort() column to prepare my select filter order by number. the default sort is by string. So, in this case: 104, 200, 1004, the sort result is:
1004, 104,200
I'm thinking to get column.type to choose which sort() to apply. Unfortunatly there is not API to get the column type.
Another idea?
thanks
Monica
This discussion has been closed.
Replies
Do you know the column types in advance? You could have your own detection on it.
The fact that there isn't external sorting for the data in a column is a limitation I'm aware of and something that I hope to address in future. I'm just not sure what the best way to do it is yet.
Allan
Yes, I define the column.type= num on initialization of the dataTable.
How can I detect it? Suggestions?
thanks
Monica
Can you show me that code? Since you are initialising it in an array, perhaps the best way is just to loop over that array and determine when you want to use the given type.
Allan
Here I define my column
{ targets:[6], data: 'posizione', type:'num'},
and here, in sort() I would like to put a function to sort number or string
column.cache('search').map(function(cached){ return cached.toLowerCase() }).sort().unique().each( function ( d, j ) {
select.append( '<option value="'+d+'" >' + ( d == '' ? aLanguage.sEmptyString : d ) + '</option>' );
});
thanks
You can pass a regular Javascript sort function to the
sort()
method.Allan
Sure. I already done
but my question was about to use the same code block for every type of sort.
In sort( ) I would like to derive the type of column to apply sort by num, string, others
Tahmks
I see what you mean - sorry I misunderstood. I agree, I think there should be a way to do this via the API, but currently I'm sorry to say that there isn't. It is something I plan to look at in future.
Allan
thaks a lot