diff --git a/src/query/ExtenderHelper.js b/src/query/ExtenderHelper.js index d29aa8a..b553d70 100644 --- a/src/query/ExtenderHelper.js +++ b/src/query/ExtenderHelper.js @@ -130,7 +130,15 @@ define([ } else if (operation.type == 'sort') { if (blocks.isString(operation.sort)) { collection = blocks.clone(collection).sort(function (valueA, valueB) { - return valueA[operation.sort] - valueB[operation.sort]; + valueA = blocks.unwrap(valueA[operation.sort]); + valueB = blocks.unwrap(valueB[operation.sort]); + if (valueA > valueB) { + return 1; + } + if (valueA < valueB) { + return -1; + } + return 0; }); } else if (blocks.isFunction(operation.sort)) { collection = blocks.clone(collection).sort(operation.sort.bind(observable.__context__)); @@ -204,11 +212,13 @@ define([ break; case EXISTS: newConnections[index] = viewIndex; + if (view.__value__.indexOf(collection[index]) != index) { + view.move(view.__value__.indexOf(collection[index]), index); + } viewIndex++; break; } }); - view._connections = newConnections; view.update = update; view.update(); diff --git a/src/query/observable.js b/src/query/observable.js index 63617ba..4c964d7 100644 --- a/src/query/observable.js +++ b/src/query/observable.js @@ -517,7 +517,7 @@ define([ } for (var i = 0; i < elements.length; i++) { - element = elements[i].element; + element = elements[i].element = elements[i].element || ElementsData.byId(elements[i].elementId).dom; chunkManager.insertAt(element, targetIndex, chunkManager.getAt(element, sourceIndex)); }