Skip to main content

Jquery Datatable with Keytable setting focus

Datatable will not have focus by default, we need to set the focus on datatable by using below code,
<script src="~/Scripts/js/core/libraries/jquery.min.js"></script>
 <script type="text/javascript" src="~/Scripts/js/plugins/tables/datatables/datatables.min.js"></script>
 <script src="~/Scripts/js/plugins/tables/datatables/extensions/key_table.min.js"></script>
//make sure you have included KeyTable plugin
 $(document).ready(function () {
   // initialise your datatable here, after that we are ready to set focus on datatable so that we can use arrow key for navigation like excel
        var table = $('#PurchaseorderList').DataTable();

            table.cell(':eq(0)').focus();
            table.cell(':eq(0)').click();

  });

Comments