select only rows in the visible part of the table

select only rows in the visible part of the table

MaikelMaikel Posts: 75Questions: 18Answers: 1

Hey,

i have buttons like 'select all', 'deselect all', 'invert selection'
but i want these buttons to only work on the visible part of the tables, so after filtering and paging.

How do i do this?

Maikel

Replies

  • kthorngrenkthorngren Posts: 20,089Questions: 26Answers: 4,721

    Maybe something this will work in your button config:

    exportOptions: {
      rows: ':visible'
    }
    

    Kevin

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    what i currently have:

                    select: {
                        info:     true,
                        style:    'os',
                        selector: 'td:not(:has(div.details-control), .details-control), th'
                    },
    

    i tried adding :visible in there but it doesn not seem to work

  • allanallan Posts: 61,322Questions: 1Answers: 10,023 Site admin

    You'll need a custom button to do what you are looking for. Something like:

    {
      text: "Select visible",
      action: function ( dt ) {
        dt.rows( { page: 'current' } ).select();
      }
    }
    

    What Kevin was looking at was when exporting data with buttons such as excel.

    Allan

  • eJedeJed Posts: 1Questions: 0Answers: 0
    edited July 2018

    I had to modify allans code to get it to work. I'm not a javascript expert but maybe it will help someone.

    {
        text: "Select Page",
        action: function ( e, dt, button, config ) {
            dt.rows( { page: 'current' } ).select();
        }
    },
    
  • allanallan Posts: 61,322Questions: 1Answers: 10,023 Site admin

    Doh! I forgot about the e parameter. Thanks for pointing that out.

    Allan

  • shujaatkulvishujaatkulvi Posts: 1Questions: 0Answers: 0

    Thnx eJed. It works like magic :smiley:

  • JatinJatin Posts: 2Questions: 1Answers: 0

    Can you provide full example?

  • colincolin Posts: 15,103Questions: 1Answers: 2,582

    @Jatin : here you go,

    Colin

This discussion has been closed.