admin管理员组文章数量:1024016
In my antd table , one of the column is boolean. I want to sort that column. How to do that?
sorter: (a, b) => a.isPayment.localeCompare(b.isPayment),
render: (val)=><div className="text_overlap">{val ? 'Yes':'No'}</div>
I guess localeCompare
works only for string.
In my antd table , one of the column is boolean. I want to sort that column. How to do that?
sorter: (a, b) => a.isPayment.localeCompare(b.isPayment),
render: (val)=><div className="text_overlap">{val ? 'Yes':'No'}</div>
I guess localeCompare
works only for string.
- What's the value of that boolean column represented in your code? I assume they only have 2 values so localCompare works just fine. – Duc Nguyen Commented Jul 6, 2020 at 10:22
-
true
andfalse
. If true dispaly Yes , else displays No in the column – Jane Fred Commented Jul 6, 2020 at 10:54
2 Answers
Reset to default 4In JavaScript we have:
true - false === 1
false - true === -1
So all you have to do is just subtracting booleans in your sorter function.
sorter: (a, b) => a - b
In my case, a error message "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type." was shown in my VSCode.
Here is my solution.
sorter: (a, b) => Number(a.isPayment) - Number(b.isPayment),
In my antd table , one of the column is boolean. I want to sort that column. How to do that?
sorter: (a, b) => a.isPayment.localeCompare(b.isPayment),
render: (val)=><div className="text_overlap">{val ? 'Yes':'No'}</div>
I guess localeCompare
works only for string.
In my antd table , one of the column is boolean. I want to sort that column. How to do that?
sorter: (a, b) => a.isPayment.localeCompare(b.isPayment),
render: (val)=><div className="text_overlap">{val ? 'Yes':'No'}</div>
I guess localeCompare
works only for string.
- What's the value of that boolean column represented in your code? I assume they only have 2 values so localCompare works just fine. – Duc Nguyen Commented Jul 6, 2020 at 10:22
-
true
andfalse
. If true dispaly Yes , else displays No in the column – Jane Fred Commented Jul 6, 2020 at 10:54
2 Answers
Reset to default 4In JavaScript we have:
true - false === 1
false - true === -1
So all you have to do is just subtracting booleans in your sorter function.
sorter: (a, b) => a - b
In my case, a error message "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type." was shown in my VSCode.
Here is my solution.
sorter: (a, b) => Number(a.isPayment) - Number(b.isPayment),
本文标签: javascriptHow to sort a boolean column in antd tableStack Overflow
版权声明:本文标题:javascript - How to sort a boolean column in antd table? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745585428a2157563.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论