0

I am working Jquery data table where I need to sorting icon and sorting/search false for one column

Here is my code

$(document).ready(function () {
        $('#tblUsers').DataTable({
            "searching": true,
            "ordering": true,
            "pagingType": "full_numbers",
            "ajax": "GetUsers",
            "columnDefs": [{
                "targets": 0,
                "data": "Id",
                "orderable": false,
                "searchable": false,
                "render": function (data, type, full, meta) {
                    return '<a href="MangeUser/' + data + '">Edit User</a>';
                }
            }],
            "columns": [
                {
                    "data": "Id"
                },
                { "data": "FirstName" },
                { "data": "LastName" },
                { "data": "UserName" },
                { "data": "RoleName" }
            ]
        });
    });

and html is as below

<table id="tblUsers" class="table table-striped table-bordered" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th></th>
                    <th>FirstName</th>
                    <th>LastName</th>
                    <th>Email Id</th>
                    <th>RoleName</th>
                </tr>
            </thead>
        </table>

Now even after setting orderable/searchable to false its still showing when page is loaded first time but when I click somewhere else then icon is gone

enter image description here

1 Answer 1

1

Just add order in your datatable options to empty array, like this

order: []

because by default it applies order for 0th column and so it shows the sorting icon even though we have made it non sortable. By setting this property you are overriding this behavior

 $('#tblUsers').DataTable({
            "order" : [], // this new option
            "searching": true,
            "ordering": true,
            "pagingType": "full_numbers",
             ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.