Javascript 如何对antd表中的布尔列进行排序?
在我的表中,其中一列是布尔值。我想对那个专栏进行排序。怎么做Javascript 如何对antd表中的布尔列进行排序?,javascript,reactjs,antd,Javascript,Reactjs,Antd,在我的表中,其中一列是布尔值。我想对那个专栏进行排序。怎么做 sorter: (a, b) => a.isPayment.localeCompare(b.isPayment), render: (val)=><div className="text_overlap">{val ? 'Yes':'No'}</div> sorter:(a,b)=>a.isPayment.localeCompare(b.isPayment), render:(
sorter: (a, b) => a.isPayment.localeCompare(b.isPayment),
render: (val)=><div className="text_overlap">{val ? 'Yes':'No'}</div>
sorter:(a,b)=>a.isPayment.localeCompare(b.isPayment),
render:(val)=>{val?'Yes':'No'}
我猜localeCompare
只适用于字符串。在JavaScript中,我们有:
true-false==1
假-真===-1
所以你所要做的就是在你的分类器函数中减去布尔值
分拣机:(a,b)=>a-b
代码中表示的布尔列的值是多少?我假设它们只有2个值,因此localCompare工作正常。true
和false
。如果true dispaly Yes,else在列中显示No,这与语法更改sorter:(a,b)=>a.isPayment-b.isPayment,