javascript - How to sort a boolean column in antd table? - Stack Overflow

In my antd table , one of the column is boolean. I want to sort that column. How to do that?sorter: (a

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.

Share Improve this question edited Jul 6, 2020 at 10:59 Jane Fred asked Jul 6, 2020 at 10:10 Jane FredJane Fred 1,4898 gold badges26 silver badges49 bronze badges 2
  • 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 and false . If true dispaly Yes , else displays No in the column – Jane Fred Commented Jul 6, 2020 at 10:54
Add a ment  | 

2 Answers 2

Reset to default 4

In 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),

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745585430a4634508.html

相关推荐

  • javascript - How to sort a boolean column in antd table? - Stack Overflow

    In my antd table , one of the column is boolean. I want to sort that column. How to do that?sorter: (a

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信