Created
September 21, 2012 22:35
-
-
Save DazWilkin/3764315 to your computer and use it in GitHub Desktop.
Simple wrapper for Table bindings in JavaScript API for Office using jQuery deferred/promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Table = (function () { | |
function Table(name) { | |
var self = this; | |
self.$def = $.Deferred(); | |
Office.context.document.bindings.addFromNamedItemAsync(name, Office.BindingType.Table, null, function (asyncResult) { | |
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { | |
return self.$def.resolve(asyncResult.value); | |
} else { | |
return self.$def.reject(); | |
} | |
}); | |
self.$def.promise(); | |
} | |
Table.prototype.addRows = function (rows) { | |
this.$def.done(function (binding) { | |
binding.addRowsAsync(rows); | |
}); | |
}; | |
Table.prototype.delRows = function () { | |
this.$def.done(function (binding) { | |
binding.deleteAllDataValuesAsync(); | |
}); | |
}; | |
Table.prototype.getRows = function () { | |
var $get = $.Deferred(); | |
this.$def.done(function (binding) { | |
binding.getDataAsync(function (asyncResult) { | |
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { | |
$get.resolve(asyncResult.value.rows); | |
} else { | |
$get.reject(); | |
} | |
}); | |
}); | |
return $get.promise(); | |
}; | |
return Table; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update to use jQuery deferred/promises.