Change colVis List text

Change colVis List text

csaba911csaba911 Posts: 17Questions: 4Answers: 0

I would like to change colvis list text, instead of CH, PCH, BC should be "Channel Number", "Physical Channel Number", "Back Office Channels"
Keeping table header column text short so wont extend column width.
Any example would be usefull.
Thanks

Answers

  • csaba911csaba911 Posts: 17Questions: 4Answers: 0
    edited February 2021

    Managed to get it working with buttons: collection, unfortunately cant find a way how to have already visible columns highlighted.
    Still looking for a way just to add/replace text in existing colVis:

    buttons:[{
                extend: 'collection',
                text: ['Show/Hide'],
                buttons: [
                 {
                    text: 'Channel Number',
                    action: function (e, dt, node, config) {
                        dt.column(-7).visible(!dt.column(-7).visible());
                    }
                },
                {
                    text: 'Physical Channel Number',
                    action: function (e, dt, node, config) {
                        dt.column(-6).visible(!dt.column(-6).visible());
                    }
                },
    .........
    
  • csaba911csaba911 Posts: 17Questions: 4Answers: 0

    Got it finally :)

    var names = ['Some Text', 'Some More Text', 'Even More Text', 'Another Text', 'One More Text', 'Not The Last Text', 'Last Text']
        $(document).ready(function () {
    
            $('#example').DataTable({
                processing: true,
                serverSide: false,
                paging: false,
                dom: 'Bfrtip',
                columnDefs: [
                    {
                        targets: [ 1, 2, 4, 5 ],
                        visible: false
                    }
                ],
                buttons:[{
                    extend: 'colvis',
                    text: 'Show/Hide',
                    columnText: function(dt, idx, title){
                        return names[idx];
                    }
                }],
                search: {
                    smart: true
                },
                order: [0, "asc"],            
                autoWidth: true,
            });
        });
    
    
    

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Excellent, glad all sorted,

    Colin

This discussion has been closed.