Skip to content

Instantly share code, notes, and snippets.

@davemo
Created April 4, 2011 15:52
Show Gist options
  • Save davemo/901869 to your computer and use it in GitHub Desktop.
Save davemo/901869 to your computer and use it in GitHub Desktop.
A way to short circuit the pagination action to add a custom hook to a YUI DataTable that uses a YUI Paginator.
// cache the old hook so you can call it later
var _oldDoBeforePaginatorChange = yuiTableInstance.doBeforePaginatorChange;
// reassign the doBeforePaginatorChange
// proposed state is a default arg passed by the calling function in the YUI stack.
yuiTableInstance.doBeforePaginatorChange = function(proposedState) {
if(!someCustomValidation) {
// returning false is important as the default doBeforePaginatorChange simply returns true.
// this will shortcircuit the paginator so it doesn't change pages.
return false;
}
// if your validation passes, just pass through the call to the original function
return _oldDoBeforePaginatorChange.call(yuiTableInstance, proposedState);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment