Open khaledh opened 11 years ago
please attach the patch here for review or send a pull request
--- packages/JayData.1.2.6/content/Scripts/jaydatamodules/knockout.js Thu Jan 17 01:39:14 2013
+++ packages/JayData.1.2.6/content/Scripts/jaydatamodules/knockout.js Thu Jan 24 00:58:28 2013
@@ -384,13 +384,15 @@
};
var queryableToArray = $data.Queryable.prototype.toArray;
- $data.Queryable.prototype.toArray = function (onResult_items) {
+ $data.Queryable.prototype.toArray = function (onResult_items, onResult_totalCount) {
if (ko.isObservable(onResult_items)) {
if (typeof onResult_items.push !== 'undefined') {
var callBack = $data.typeSystem.createCallbackSetting();
return this.toArray(function (results) {
- onResult_items([]);
+ if (typeof results.totalCount === 'number' && ko.isObservable(onResult_totalCount))
+ onResult_totalCount(results.totalCount);
+ onResult_items([]);
results.forEach(function (result, idx) {
if (result instanceof $data.Entity) {
onResult_items.push(result.asKoObservable());
JayData 1.2.6 introduced support for inline counts with OData, using the
withInlineCount()
method, which adds atotalCount
property to the returned items array.Unfortunately the knockout.js module does not have similar support.
I was able to modify the knockout.js extension a little to support inline counts by adding a second parameter to its
toArray()
method, which should be an observable. The method checks iftotalCount
exists on the results array, and if it exists it sets the observable parameter to its value.