You must Sign In to post a response.
  • Category: JQuery

    Disable sorting if no record in table

    Hello.
    I have one single page application with binding data to table.
    For sorting, searching, paging I have used

    $('#tblActionHistory').DataTable({
    "autoWidth": false,
    "processing": true,
    "paging": true,
    "pageLength": 5,
    //"ordering": true,
    "ordering": true,
    columnDefs: [
    { type: 'date-uk', targets: 3 }
    ],
    "info": true,
    "bFilter": false
    });

    Here, I have requirement that, if record count is 0, sorting and other events gets disabled.
    How to do that.
  • #768683
    Hi,

    First you can check the rows whether the dataset is empty or full. If it has values then we can direct it to some foreach loop like below.


    foreach (DataGridViewColumn column in dataGridView.Columns)
    {
    // Logic for displaying the data
    }


    If your dataset or DataGridColumn is empty then you can disable the sorting option. using the below single line code.

    column.SortMode = DataGridViewColumnSortMode.NotSortable;

    Thanks,
    Mani

  • #768684
    No.
    This is c# code you given.
    You can check jquery's datatable property.
    I given code as well.

  • #768685
    Hi,

    Can you try this code and let us know if it is performing as you expect.

    $('#tblActionHistory').DataTable({
    "aoColumnDefs": [
    { "bSortable": false, "aTargets": [ 0 ] }
    ] } );
    });

    Thanks,
    Mani


  • Sign In to post your comments