Giter VIP home page Giter VIP logo

Comments (5)

07akioni avatar 07akioni commented on June 19, 2024 1

corresponding PR merged

from naive-ui.

jizai1125 avatar jizai1125 commented on June 19, 2024

If the sorter prop is set to default, it will use Array.sort() by employing a built-in compare function.

function getDefaultSorterFn (
columnKey: ColumnKey
): (row1: InternalRowData, row2: InternalRowData) => number {
return (row1: InternalRowData, row2: InternalRowData) => {
const value1 = row1[columnKey]
const value2 = row2[columnKey]
if (typeof value1 === 'number' && typeof value2 === 'number') {
return value1 - value2
} else if (typeof value1 === 'string' && typeof value2 === 'string') {
return value1.localeCompare(value2)
}
return 0
}
}

So in your case, when null is compared with other numeric values, it will return 0, which means it will maintain the original order.

from naive-ui.

Vringe avatar Vringe commented on June 19, 2024

Thank you, I understand. I would like to discuss if this behavior is really desired or if this should be changed in the default sorter? In my opinion, columns with null values should be at the very bottom or top when sorting.

from naive-ui.

jizai1125 avatar jizai1125 commented on June 19, 2024

Thank you, I understand. I would like to discuss if this behavior is really desired or if this should be changed in the default sorter? In my opinion, columns with null values should be at the very bottom or top when sorting.

The sorter prop also accepts your custom compare function if you don't use the built-in compare function.
Ref Uncontrolled filter and sorter.

from naive-ui.

Vringe avatar Vringe commented on June 19, 2024

Yes, I saw that. Of course, it is convenient to be able to use your own sorter functions.
However, I think that the default behavior should be changed as suggested.

How would you solve that with a custom sorter function without defining it every time? I would like to define it once globally and reference to it. But as far as I can see in the docs, only the whole row is passed to my function without knowing the actual column which makes it impossible to use it in that way.

from naive-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.