Columns and IDs Sorting

Columns and IDs Sorting

xtremer360xtremer360 Posts: 84Questions: 2Answers: 0
edited August 2013 in General
Is it possible to do an if statement that will only make certain columns sortable if they have certain ids? This is something I want to employ on a global scale for all of my tables so that I don't have to keep repeating the same code.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Not Ids, but classes - yes:

    [code]
    aoColumnDefs: [
    {
    aTargets: [ 'no-sortable' ],
    bSortable: false
    ]
    [/code]

    Allan
  • xtremer360xtremer360 Posts: 84Questions: 2Answers: 0
    edited August 2013
    So this is the correct way to perform this in a global js file.

    [code]
    /* DataTables */
    if ($('.dynamicTable').size() > 0)
    {
    $('.dynamicTable').dataTable({
    "sPaginationType": "bootstrap",
    "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
    "oLanguage": {
    "sLengthMenu": "_MENU_ records per page"
    },
    aoColumnDefs: [{
    aTargets: [ 'check', 'id', 'actions', 'created'],
    bSortable: false
    }]
    });
    }
    [/code]
  • xtremer360xtremer360 Posts: 84Questions: 2Answers: 0
    I'm worried that this won't do anything. I have 20+ tables and share similar table headers on some of them. I want it to look for each class and if it matches one to an array of classes then it makes that table header column nonsortable.
This discussion has been closed.