"Page on scroll" plugin
"Page on scroll" plugin
Hey all,
I just wrote this little guy as I had a really long table that i figured would be a lot easier to scroll through.
Feel free to use and if you have any improvements (I literally wrote this 10 minutes ago and it works well enough for my use case), please feel free to leave them here and I'll update the original accordingly:
[code]
(function ($) {
$.fn.dataTableScroller = function () {
var dt;
//throw if we call this on something that isn't a dataTable. Won't have 'fnPageChange' method available
if (!('fnGetData' in this)) { throw "Initialized on something that isn't a DataTable"; }
//cache the dataTable so we don't have to look it up every time the event fires
dt = $(this).dataTable();
dt.on('mousewheel', function (ev) {
if (ev.originalEvent.wheelDelta) {
if (ev.originalEvent.wheelDelta < 1) {
dt.fnPageChange('next');
} else {
dt.fnPageChange('previous');
}
ev.preventDefault();
}
});
}
}(jQuery));
[/code]
I just wrote this little guy as I had a really long table that i figured would be a lot easier to scroll through.
Feel free to use and if you have any improvements (I literally wrote this 10 minutes ago and it works well enough for my use case), please feel free to leave them here and I'll update the original accordingly:
[code]
(function ($) {
$.fn.dataTableScroller = function () {
var dt;
//throw if we call this on something that isn't a dataTable. Won't have 'fnPageChange' method available
if (!('fnGetData' in this)) { throw "Initialized on something that isn't a DataTable"; }
//cache the dataTable so we don't have to look it up every time the event fires
dt = $(this).dataTable();
dt.on('mousewheel', function (ev) {
if (ev.originalEvent.wheelDelta) {
if (ev.originalEvent.wheelDelta < 1) {
dt.fnPageChange('next');
} else {
dt.fnPageChange('previous');
}
ev.preventDefault();
}
});
}
}(jQuery));
[/code]
This discussion has been closed.
Replies
Thanks very much for sharing this with us!
Regards,
Allan