Setting the text/language for the colvis column list

Setting the text/language for the colvis column list

zecksteinzeckstein Posts: 16Questions: 6Answers: 0

It's possible there is something in the documentation for this, but I can't seem to find it, if so.

I'm defining one of my columns to display as an icon in the table but different in the searchBuilder, like so:

{
                    "data": "experiment_ids",
                    "name": "experiment_ids",
                    "title": '<i class="fa fa-flask"></i>',
                    "searchBuilderTitle": 'Has Experiment',
                    "searchBuilderType": "string",
                    "className": "idwiz_searchBuilder_enabled",
                    "type": "bool",
                    "render": function(data, type) {
                        if (type === 'display') {
                            return data ? '<i class="fa fa-flask"></i>' : '';
                        }
                        if (type === 'filter') {
                            return !data ? 'True' : 'False';
                        }
                        return data;
                    },
                    "searchBuilder": {
                        "orthogonal": {
                            "search": "filter",
                            "display": "filter",
                        }
                    }
                },

This works pretty well (although I can't seem to edit the filter types, I think because I'm on server-side?).

But, the last hurtle I'm facing is getting the column to show correctly in the ColVis dropdown. Currently, the select option shows blank with this setup.

Anyone know of a way to achieve that?

This question has an accepted answers - jump to answer

Answers

  • zecksteinzeckstein Posts: 16Questions: 6Answers: 0

    I did finally find the piece of documentation I was looking for and was able to do this to alter the button text for 2 of my columns:

    buttons: [ 
                            {   
                                extend: 'colvis',
                                columnText: function ( dt, idx, title ) {
                                    if (idx == 1) {
                                        return 'Info';
                                    }
                                    if (idx == 7) {
                                        return 'Has Experiment';
                                    } else {
                                        return title;
                                    }
                                }
                            },
    ]
    

    But, it doesn't work with col re-order because it relies on column index. Is there any other way to ID the columns in the columnText callback so the colvis settings "stick" to them when re-ordered?

  • kthorngrenkthorngren Posts: 21,339Questions: 26Answers: 4,954
    Answer ✓

    Try using colReorder.transpose(). Something like this might work:

                                columnText: function ( dt, idx, title ) {
                                    if ( idx == dt.colReorder.transpose( 1 ) ) {
                                        return 'Info';
                                    }
                                    if ( idx == dt.colReorder.transpose( 7 ) ) {
                                        return 'Has Experiment';
                                    } else {
                                        return title;
                                    }
                                }
    

    Kevin

  • zecksteinzeckstein Posts: 16Questions: 6Answers: 0

    Flipping amazing, works like a charm, thank you!

Sign In or Register to comment.