简体   繁体   English

如何对antd表中的boolean列进行排序?

[英]How to sort a boolean column in antd table?

In my antd table, one of the column is boolean.在我的antd表中,其中一列是 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.我猜localeCompare仅适用于字符串。

In JavaScript we have:在 JavaScript 我们有:

true - false === 1
false - true === -1

So all you have to do is just subtracting booleans in your sorter function.所以你所要做的就是在你的分拣机 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."在我的情况下,出现错误消息“算术运算的左侧必须是 'any'、'number'、'bigint' 或枚举类型。” was shown in my VSCode.显示在我的 VSCode 中。

Here is my solution.这是我的解决方案。

sorter: (a, b) => Number(a.isPayment) - Number(b.isPayment),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM