clde clde - 2 months ago 9
jQuery Question

DataTables: Pressing enter key in order to use pagination with a textbox

I have succesfully implemented the DataTables (version 1.10+) pagination plugin with textbox but I would like to allow the user to first enter a page number and then to press the enter key. By default, instantly the user is taken to the page but, as stated above, I would like to allow to write first a number with in the textbox and then jump to the page by using the enter key. Any ideas on how to do this?

Answer

You can use the input pagination plugin :

var table = $('#example').DataTable({
   pagingType: "input"
}) 

example -> http://jsfiddle.net/bqpt85LL/

It does not support "jump to the page by using the enter key" out of the box, but you can easily refactor the code. Look at the source around line #164 (in function $(nInput).keyup(function (e) {.. ). Change

fnCallbackDraw(oSettings);

to

if (e.which === 13) fnCallbackDraw(oSettings);

That should be it. Have not tested it but this is certainly the way to go.