Menu

Show / hide columns in DataTable

2022-12-15
2022-12-15
  • Domen Dolar

    Domen Dolar - 2022-12-15

    You have two steps to activate show/hide columns in RASD tables (using DataTables).

    1.Put somewhere into HTML part (label ob block, ON_UI field, ...). On click on this item the column will show or hide.

    <a class="toggle-vis" data-column="0">Col1</a> 
    <a class="toggle-vis" data-column="2">Col3</a>
    

    2.Add conntent into FORM_JS part:

    $(document).ready(function () {
    
        --Create new DataTable with custom properties!
        var newDT1 = JSON.parse(JSON.stringify(_rasd_dataTableProperties));
        --Your custom preferences. If no chanege tehn don't add any.
        newDT1.bFilter=false;
        -- 
        newDT1.destroy = true;
        $("#B10_TABLE").removeClass( "rasdTableN" ); 
        var xTable1 = $("#B10_TABLE").DataTable(newDT1);
    
        --Create function that triggers for new DataTable
        $('a.toggle-vis').on('click', function (e) {
            e.preventDefault();  
           // Get the column API object
            var column = xTable1.column($(this).attr('data-column'));
    
            // Toggle the visibility
            column.visible(!column.visible());
        });
    });
    

    More documentation on: https://datatables.net/examples/api/show_hide.html

     

    Last edit: Domen Dolar 2022-12-15
  • Domen Dolar

    Domen Dolar - 2022-12-15

    At inicialisation of DataTable be sure that name is DataTable and not dataTable

    dataTable - you will get old object of datatable
    DataTable - you will get new version

    https://stackoverflow.com/questions/24325786/table-columns-is-not-a-function-in-datatable-js

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.