Skip to content

Instantly share code, notes, and snippets.

@DazWilkin
Created September 21, 2012 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DazWilkin/3764315 to your computer and use it in GitHub Desktop.
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
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;
}());
@DazWilkin
Copy link
Author

Update to use jQuery deferred/promises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment