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

    Disable sorting if no record in table

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

    "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

    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;


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

  • #768685

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

    "aoColumnDefs": [
    { "bSortable": false, "aTargets": [ 0 ] }
    ] } );


  • Sign In to post your comments