5 <link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
6 <meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
8 <title>KeyTable example - Events</title>
9 <link rel="stylesheet" type="text/css" href="../../../media/css/jquery.dataTables.css">
10 <link rel="stylesheet" type="text/css" href="../css/dataTables.keyTable.css">
11 <link rel="stylesheet" type="text/css" href="../../../examples/resources/syntax/shCore.css">
12 <link rel="stylesheet" type="text/css" href="../../../examples/resources/demo.css">
13 <style type="text/css" class="init">
16 <script type="text/javascript" language="javascript" src="../../../media/js/jquery.js"></script>
17 <script type="text/javascript" language="javascript" src="../../../media/js/jquery.dataTables.js"></script>
18 <script type="text/javascript" language="javascript" src="../js/dataTables.keyTable.js"></script>
19 <script type="text/javascript" language="javascript" src="../../../examples/resources/syntax/shCore.js"></script>
20 <script type="text/javascript" language="javascript" src="../../../examples/resources/demo.js"></script>
21 <script type="text/javascript" language="javascript" class="init">
24 function eventMsg ( msg ) {
25 var n = document.getElementById('info');
26 n.innerHTML += msg+"<br>";
27 n.scrollTop = n.scrollHeight;
30 $(document).ready(function() {
31 var table = $('#example').DataTable();
32 var keys = new $.fn.dataTable.KeyTable( table );
34 /* Focus handler for all cells in last column */
35 keys.event.focus( 4, null, function( node, x, y ) {
36 eventMsg( "Cell "+x+","+y+" focused ('live' event - column)" );
39 /* Focus handler for all cells in 8th row */
40 keys.event.focus( null, 7, function( node, x, y ) {
41 eventMsg( "Cell "+x+","+y+" focused ('live' event - row)" );
44 /* Focus using coords. */
45 keys.event.focus( 1, 0, function( node ) {
46 keys.event.remove.focus( node );
47 eventMsg( "Cell 1,0 focus - this event has now been removed" );
50 keys.event.focus( 1, 3, function() {
51 eventMsg( "Cell 1,3 focus" );
54 /* focus with a node */
55 keys.event.focus( $('#example tbody tr:eq(2) td:eq(0)')[0], function() {
56 eventMsg( "Cell 0,2 focus" );
59 /* Blur using a node */
60 keys.event.blur( $('#example tbody tr:eq(1) td:eq(2)')[0], function() {
61 eventMsg( "Cell 1,2 blur" );
64 /* Blur using coords */
65 keys.event.blur( 2, 4, function() {
66 eventMsg( "Cell 2,4 blur" );
70 keys.event.action( 2, 2, function( node ) {
71 eventMsg( "Cell 2,2 action" );
72 if ( node.style.fontWeight == "" || node.style.fontWeight == "normal" ) {
73 node.style.fontWeight = "bold";
76 node.style.fontWeight = "normal";
80 keys.event.action( 2, 5, function( node ) {
81 eventMsg( "Cell 2,5 action" );
82 if ( node.style.fontStyle == "" ) {
83 node.style.fontStyle = "italic";
86 node.style.fontStyle = "";
95 <body class="dt-example">
96 <div class="container">
98 <h1>KeyTable example <span>Events</span></h1>
101 <p>KeyTable provides the ability to listen for events such as <code>focus</code>, <code>blur</code>,
102 <code>esc</code> (the escape key) and 'return' (the return key) can be assigned event handling
103 functions through KeyTable's the API. This gives you the ability to take an action on a cell.</p>
105 <p>The example shown below has a few cells (selected at random, but near the top) with blur and focus
106 events assigned to them. You can also see the navigation around the table using arrow keys.</p>
109 <div id="info" class="box">
110 Event information:<br>
113 <table id="example" class="display" cellspacing="0" width="100%">
139 <td>System Architect</td>
146 <td>Garrett Winters</td>
155 <td>Junior Technical Author</td>
156 <td>San Francisco</td>
162 <td>Cedric Kelly</td>
163 <td>Senior Javascript Developer</td>
178 <td>Brielle Williamson</td>
179 <td>Integration Specialist</td>
186 <td>Herrod Chandler</td>
187 <td>Sales Assistant</td>
188 <td>San Francisco</td>
194 <td>Rhona Davidson</td>
195 <td>Integration Specialist</td>
202 <td>Colleen Hurst</td>
203 <td>Javascript Developer</td>
204 <td>San Francisco</td>
211 <td>Software Engineer</td>
219 <td>Office Manager</td>
227 <td>Support Lead</td>
234 <td>Charde Marshall</td>
235 <td>Regional Director</td>
236 <td>San Francisco</td>
242 <td>Haley Kennedy</td>
243 <td>Senior Marketing Designer</td>
250 <td>Tatyana Fitzpatrick</td>
251 <td>Regional Director</td>
258 <td>Michael Silva</td>
259 <td>Marketing Designer</td>
267 <td>Chief Financial Officer (CFO)</td>
274 <td>Gloria Little</td>
275 <td>Systems Administrator</td>
282 <td>Bradley Greer</td>
283 <td>Software Engineer</td>
291 <td>Personnel Lead</td>
298 <td>Jenette Caldwell</td>
299 <td>Development Lead</td>
307 <td>Chief Marketing Officer (CMO)</td>
314 <td>Caesar Vance</td>
315 <td>Pre-Sales Support</td>
322 <td>Doris Wilder</td>
323 <td>Sales Assistant</td>
330 <td>Angelica Ramos</td>
331 <td>Chief Executive Officer (CEO)</td>
346 <td>Jennifer Chang</td>
347 <td>Regional Director</td>
354 <td>Brenden Wagner</td>
355 <td>Software Engineer</td>
356 <td>San Francisco</td>
363 <td>Chief Operating Officer (COO)</td>
364 <td>San Francisco</td>
371 <td>Regional Marketing</td>
378 <td>Michelle House</td>
379 <td>Integration Specialist</td>
394 <td>Prescott Bartlett</td>
395 <td>Technical Author</td>
402 <td>Gavin Cortez</td>
404 <td>San Francisco</td>
410 <td>Martena Mccray</td>
411 <td>Post-Sales support</td>
418 <td>Unity Butler</td>
419 <td>Marketing Designer</td>
420 <td>San Francisco</td>
426 <td>Howard Hatfield</td>
427 <td>Office Manager</td>
428 <td>San Francisco</td>
434 <td>Hope Fuentes</td>
436 <td>San Francisco</td>
442 <td>Vivian Harrell</td>
443 <td>Financial Controller</td>
444 <td>San Francisco</td>
450 <td>Timothy Mooney</td>
451 <td>Office Manager</td>
458 <td>Jackson Bradshaw</td>
466 <td>Olivia Liang</td>
467 <td>Support Engineer</td>
475 <td>Software Engineer</td>
482 <td>Sakura Yamamoto</td>
483 <td>Support Engineer</td>
498 <td>Finn Camacho</td>
499 <td>Support Engineer</td>
500 <td>San Francisco</td>
506 <td>Serge Baldwin</td>
507 <td>Data Coordinator</td>
514 <td>Zenaida Frank</td>
515 <td>Software Engineer</td>
522 <td>Zorita Serrano</td>
523 <td>Software Engineer</td>
524 <td>San Francisco</td>
530 <td>Jennifer Acosta</td>
531 <td>Junior Javascript Developer</td>
538 <td>Cara Stevens</td>
539 <td>Sales Assistant</td>
546 <td>Hermione Butler</td>
547 <td>Regional Director</td>
555 <td>Systems Administrator</td>
562 <td>Jonas Alexander</td>
564 <td>San Francisco</td>
571 <td>Regional Director</td>
578 <td>Michael Bruce</td>
579 <td>Javascript Developer</td>
586 <td>Donna Snider</td>
587 <td>Customer Support</td>
597 <li class="active">Javascript</li>
601 <li>Server-side script</li>
606 <p>The Javascript shown below is used to initialise the table shown in this
607 example:</p><code class="multiline brush: js;">function eventMsg ( msg ) {
608 var n = document.getElementById('info');
609 n.innerHTML += msg+"<br>";
610 n.scrollTop = n.scrollHeight;
613 $(document).ready(function() {
614 var table = $('#example').DataTable();
615 var keys = new $.fn.dataTable.KeyTable( table );
617 /* Focus handler for all cells in last column */
618 keys.event.focus( 4, null, function( node, x, y ) {
619 eventMsg( "Cell "+x+","+y+" focused ('live' event - column)" );
622 /* Focus handler for all cells in 8th row */
623 keys.event.focus( null, 7, function( node, x, y ) {
624 eventMsg( "Cell "+x+","+y+" focused ('live' event - row)" );
627 /* Focus using coords. */
628 keys.event.focus( 1, 0, function( node ) {
629 keys.event.remove.focus( node );
630 eventMsg( "Cell 1,0 focus - this event has now been removed" );
633 keys.event.focus( 1, 3, function() {
634 eventMsg( "Cell 1,3 focus" );
637 /* focus with a node */
638 keys.event.focus( $('#example tbody tr:eq(2) td:eq(0)')[0], function() {
639 eventMsg( "Cell 0,2 focus" );
642 /* Blur using a node */
643 keys.event.blur( $('#example tbody tr:eq(1) td:eq(2)')[0], function() {
644 eventMsg( "Cell 1,2 blur" );
647 /* Blur using coords */
648 keys.event.blur( 2, 4, function() {
649 eventMsg( "Cell 2,4 blur" );
653 keys.event.action( 2, 2, function( node ) {
654 eventMsg( "Cell 2,2 action" );
655 if ( node.style.fontWeight == "" || node.style.fontWeight == "normal" ) {
656 node.style.fontWeight = "bold";
659 node.style.fontWeight = "normal";
663 keys.event.action( 2, 5, function( node ) {
664 eventMsg( "Cell 2,5 action" );
665 if ( node.style.fontStyle == "" ) {
666 node.style.fontStyle = "italic";
669 node.style.fontStyle = "";
674 <p>In addition to the above code, the following Javascript library files are loaded for use in this
678 <li><a href="../../../media/js/jquery.js">../../../media/js/jquery.js</a></li>
680 "../../../media/js/jquery.dataTables.js">../../../media/js/jquery.dataTables.js</a></li>
681 <li><a href="../js/dataTables.keyTable.js">../js/dataTables.keyTable.js</a></li>
686 <p>The HTML shown below is the raw HTML table element, before it has been enhanced by
692 <p>This example uses a little bit of additional CSS beyond what is loaded from the library
693 files (below), in order to correctly display the table. The additional CSS used is shown
694 below:</p><code class="multiline brush: js;"></code>
697 <p>The following CSS library files are loaded for use in this example to provide the styling of the
702 "../../../media/css/jquery.dataTables.css">../../../media/css/jquery.dataTables.css</a></li>
703 <li><a href="../css/dataTables.keyTable.css">../css/dataTables.keyTable.css</a></li>
708 <p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data
709 will update automatically as any additional data is loaded.</p>
713 <p>The script used to perform the server-side processing for this table is shown below. Please note
714 that this is just an example script using PHP. Server-side processing scripts can be written in any
715 language, using <a href="//datatables.net/manual/server-side">the protocol described in the
716 DataTables documentation</a>.</p>
724 <div class="gradient"></div>
727 <h2>Other examples</h2>
730 <div class="toc-group">
731 <h3><a href="./index.html">Examples</a></h3>
732 <ul class="toc active">
733 <li><a href="./simple.html">Basic initialisation</a></li>
734 <li class="active"><a href="./events.html">Events</a></li>
735 <li><a href="./scrolling.html">Scrolling table</a></li>
736 <li><a href="./html.html">Plain HTML table</a></li>
741 <div class="epilogue">
742 <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full
743 information about its API properties and methods.<br>
744 Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and
745 <a href="http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of
748 <p class="copyright">DataTables designed and created by <a href=
749 "http://www.sprymedia.co.uk">SpryMedia Ltd</a> © 2007-2014<br>
750 DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>