Selecting ColVis Groups by name

Selecting ColVis Groups by name

redlum7redlum7 Posts: 2Questions: 2Answers: 0

Hello,

To start i'm still new to DataTables and not the most advanced programmer but i'm trying to select columns by name(or label).

So i tried the following,

colVis: {
            exclude: [],
            groups: [
                {
                    title: "talen",
                    columns: [ { name: "naamNL" } ]
                }
            ]
        },

My whole code looks like this:

        <script type="text/javascript" language="javascript" class="init">  
        
var editor; // use a global for the submit and return data rendering in the examples

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "http://www.3dincorporated.nl/orion/editor/examples/php/staff.php",
        table: "#Tartikelen1",
        fields: [ {
                    label: "Art.Nummer",
                    name: "nummer"
                }, {
                    label: "Naam NL",
                    name: "naamNL"
                }, {
                    label: "Naam DE",
                    name: "naamDE"
                }, {
                    label: "Naam EN",
                    name: "naamEN"
                }, {
                    label: "Naam FR",
                    name: "naamFR"
                }, {
                    label: "Naam SE",
                    name: "naamSE"
                }, {
                    label: "Omschrijving",
                    name: "omschrijving"
                }, {
                    label: "Voorraad",
                    name: "voorraad"
                }, {
                    label: "Min.Voorraad",
                    name: "minimum_voorraad"
                }, {
                    label: "Gereserveerd",
                    name: "gereserveerd"
                }, {
                    label: "Besteld",
                    name: "besteld"
                }, {
                    label: "Inkoopprijs",
                    name: "inkoop_prijs"
                }, {
                    label: "Verkoopprijs",
                    name: "verkoop_prijs",
                }, {
                    label: "Art.Groep",
                    name: "art_groep",
                }, {
                    label: "BTW",
                    name: "btw",
                }, {
                    label: "Gewicht",
                    name: "gewicht",
                }, {
                    label: "Hoogte",
                    name: "hoogte",
                }, {
                    label: "Lengte",
                    name: "lengte",
                }, {
                    label: "Breedte",
                    name: "breedte",
                }
            ]
    } );

    $('#Tartikelen1').DataTable( {
        stateSave:        false,
        "autoWidth":     false,
        "scrollY":        400,
        dom: 'TCRlfrtip',
        colVis: {
            exclude: [],
            groups: [
                {
                    title: "talen",
                    columns: [ { "name": "naamNL" } ]
                }
            ]
        },
        ajax: "http://www.3dincorporated.nl/orion/editor/examples/php/staff.php",
        columns: [
                        { data: 'nummer' },
                        { data: 'naamNL' },
                        { data: 'naamDE' },
                        { data: 'naamEN' },
                        { data: 'naamFR' },
                        { data: 'naamSE' },
                        { data: 'omschrijving' },
                        { data: 'voorraad' },
                        { data: 'minimum_voorraad' },
                        { data: 'gereserveerd' },
                        { data: 'besteld' },
                        { data: 'inkoop_prijs' },
                        { data: 'verkoop_prijs' },
                        { data: 'art_groep' },
                        { data: 'btw' },
                        { data: 'gewicht' },
                        { data: 'hoogte' },
                        { data: 'lengte' },
                        { data: 'breedte' }
                    ],
        tableTools: {
            sRowSelect: "os",
            aButtons: [
                { sExtends: "editor_create", editor: editor },
                { sExtends: "editor_edit",   editor: editor },
                { sExtends: "editor_remove", editor: editor }
            ]
        }
    } );
} );



    </script>

Everything is tested and works without the name part, also selecting columns on their order( 1, 2 ,3 etc) works just fine. I have no idea what im doing wrong here

i searched the forums and tried workign with the following;
https://datatables.net/reference/option/columns.name

my project can be seen here:
http://www.3dincorporated.nl/orion/artikelen.php

Thanks in advance!

Answers

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    columns: [ { name: "naamNL" } ]

    There is no option to do that in ColVis. The columns array should be integers.

    I'm working on a replacement for ColVis that will be available in the next few weeks that will allow easier column selection.

    Allan

This discussion has been closed.