Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set focus on first cell of jquery datatable after page loading?
My given code is below:-

What I have tried:

JavaScript
$(document).ready(function () {
    var dataTable = $('#hsnGrid').DataTable({
        processing: true,
        serverSide: true,
        orderMulti: false, // for disable multiple column at once
        searching: false,
        paging: false,
        scrollX: 200,
        scrollY: 300,
        keys: true,
        ajax: {
            url: "/HSN_SAC/LoadItemData",
            type: "POST",
            datatype: "json",
            data: function (data) {
                var name = $('#ipTxtSearch').val();
                // Append to data
                data.ipTxtSearch = name;
            },
            complete: function (data) {
                if (data.responseJSON.hasRowInTable == false)
                    window.location.href = '/HSN_SAC/Create'; // your action should return an object after complete process of datatable
            }
        },
        columnDefs:
            [
                {
                    targets: [0],//CodeID
                    visible: false,
                    searchable: false
                },
                {
                    targets: [1],//Code
                    searchable: true,
                    orderable: true,
                    width: "50px"
                },
                {
                    targets: [2],//Name
                    searchable: true,
                    orderable: true,
                    width:"200px"
                },
                {
                    targets: [3],//Type
                    searchable: false,
                    orderable: false,
                    width: "30px"
                }
            ],
        columns:
            [
                { data: "CodeID", name: "CodeID" },
                { data: "Code", name: "Code" },
                { data: "Name", name: "Name" },
                { data: "Type", name: "Type" }
            ]
    });
});
Posted
Updated 6-Jul-20 2:27am
v2

1 solution

You can use dataTables cell.focus function -

Java
table.cell( ':columnname(0)' ).focus();


See dataTables.net for more information.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900