Skip to content

Support custom sort functions #26

@m-mujica

Description

@m-mujica

Sometimes you have to use a custom sort function on Lists, being unable to use this function in can-query-logic means that unexpected insertion/removals will happen when using real-time.

// sorter
function sortByName(item1, item2) {
  var val1 = item1.name.toLowerCase();
  var val2 = item2.name.toLowerCase()
 ...
}

// adding the symbol to the list
...
list.sort(sortByName);
list[canSymbol.for('can.listQuery')] = { sort: 'name' };

When real-time tries to figure where a new (or existing) item should be placed on the lists it calls getIndex which will sometimes not match the position where the instance "should be placed" based on the sortByName comparator logic.

Ideally we should be able to pass sortByName so can-query-logic can determine the position correctly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions