Hide several columns for "colvis" button list

Hide several columns for "colvis" button list

VasiliiVasilii Posts: 9Questions: 1Answers: 0

I need to hide several columns from the list of the colvis button.

columns: ':gt(2)' - works, but it hides all 3 columns before the column #3 (and I just need to hide column #3). Is there a way to pass an array of the columns that must be hidden to this funtion? For example, I want to hide columns #3, #5, #9

This question has an accepted answers - jump to answer

Answers

  • MSLtdMSLtd Posts: 56Questions: 5Answers: 4

    Hello @Vasilii , could you post the section of code where you are setting this so that I can look through it. Thanks :)

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

    Hi @Vasilii ,

    This example here should do trick. It shows how to only add specific columns to the colvis button,

    Cheers,

    Colin

  • VasiliiVasilii Posts: 9Questions: 1Answers: 0

    @colin @MSLtd This is what I have:

    "buttons": [{
    extend: 'colvis',
    className: 'btn', 
    text: 'Columns',
    //columns: ':not(.noVis)'
    columns: ':gt(2)'
    }],
    ...
    "columns": [{
    title: '',
    responsivePriority: 0,
    className: "column-0 table-icon no-border-right noVis",
    width: '0',
    data: 'registr',
    orderable: false,
    searchable: false,
    render: {
    _: '_',
    sort: 'sort',
    },
    },
    

    If I use ':gt()' it hides some columns that I do not want to hide. If I use ':not(.noVis)' it doesn't work - I still see the empty button in the list of colvis.

  • MSLtdMSLtd Posts: 56Questions: 5Answers: 4
    Answer ✓

    What ":gt(Nth)" does is it gets all of the elements after the specified (nth) element.

    If Colin can't find the solution to your .noVis problem, I'd recommend using ":eq(Nth)" or "slice()" instead.

    :eq() documentation:
    https://www.w3schools.com/jquery/traversing_eq.asp

    slice() documentation:
    http://api.jquery.com/slice/
    https://stackoverflow.com/questions/185966/how-to-select-a-range-of-elements-in-jquery

    If you need any assistance with these, just let me know :smile:

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

    The best would be to create a test case/fiddle, then we can have a look live.

  • VasiliiVasilii Posts: 9Questions: 1Answers: 0

    @colin @MSLtd thank you for your help, but I think, that I've found a solution:

    columns: ':eq(3),:eq(5),:eq(9)'
    

    Works perfect

  • lingleelinglee Posts: 1Questions: 0Answers: 0

    Check with this interactive...jQuery Tutorial

This discussion has been closed.