What version are you using?
2.4.4
What browser?
Chrome Version 66.0.3359.139 (Official Build) (64-bit)
What did you expect to happen?
I expected to be able to sort a column by a boolean value.
What actually happened?
Clicking the column header of my boolean value logged an error to the console and broke sorting on all columns until table refresh.
Please detail your steps here
The error, TypeError: d.toLowerCase is not a function, makes sense-- the sorting algorithm runs by lowercasing the text before evaluation so we're comparing apples and apples. This fails on boolean values however, because true.toLowerCase() isn't a thing. Simplest solution I can think of is to cast the values to string before lowercasing them.
ah! good catch @mgd722 I think we need a type boolean for vgt column. I'll work on it. out of curiousity, how do you show boolean on the table? string "true"/"false"?
Yeah, my current workaround is to cast the boolean to string (just "true"/"false") by passing a function to the field instead of the field name: https://jsfiddle.net/gn5ubo8a/3/. This works alright, but prevents me from passing the field name to initialSortBy since there isn't really a field name. This isn't a big deal for my use case, but I could see that getting in the way somewhere else.
column type boolean now added in v2.5.5
closing.
Awesome! Thanks for all the work you put into this; it's much appreciated!
@xaksis does it make sense to add the type "array" and "object" also? I am trying to sort on a column that is an array of objects containing an id) and I get the same error.
sortFn(x, y) {
if (!x && !y) {
return 0
} else if (x && !y) {
return 1
} else if (!x && y) {
return -1
} else {
x = x[0]
y = y[0]
return x.id < y.id ? -1 : x.id > y.id ? 1 : 0
}
}
hey @LeCoupa! Do you mind opening up a new ticket? It's better for me to keep a record of current discussion if it's not on closed tickets.
Most helpful comment
column type
booleannow added in v2.5.5closing.