Select plugin - selection on all columns, except the first one

Select plugin - selection on all columns, except the first one

Marek_OptimaMarek_Optima Posts: 32Questions: 7Answers: 0

I would like to ask you for advice and to get know.
What is the proper selector, if I am using the selection in the Select plugin to work on all columns, except the first one?
I have tried to use different combinations and I could not find the right one.

By the way, I would like to point out that you probably have an error in your documentation:

https://datatables.net/reference/option/select.selector
Allow selection on all but the last column:

$('#example').DataTable( {
    select: {
        style:    'os',
        selector: ':not(:last-child)'
    }
} );

Example: https://jsfiddle.net/rq320vfb/1/
This selector does not select the last row in the table correctly.

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,141Questions: 26Answers: 4,918
    Answer ✓

    This selector does not select the last row in the table correctly.

    Instead of selector: ':not(:last-child)' the selector should be selector: 'td:not(:last-child)'.

    @allan will need to fix the docs.

    The same if you want to enable select on all but the first column:
    selector: 'td:not(:first-child)'.

    Kevin

  • rf1234rf1234 Posts: 2,937Questions: 87Answers: 415
    edited February 2018 Answer ✓

    Hi Marek!

    select: {
            style: 'os',
            selector: 'td:not(:first-child)'
        },
    

    I am surprised your code above works without the "td" in it. Maybe you want to try it with "td" and also the last row will be selected properly?! Because in your example the last row can be selected ONLY on the last column while all other rows can be selected ONLY on all columns EXCEPT for the last column. That leads me to the assumption that the selector isn't specific enough. ':not(:last-child)' seems to be interpreted as a "td" element in all rows but the last and as a "tr" element in the last row.

    So you might also want to try this:

    select: {
            style: 'single',
            selector: 'tr:not(:last-child) td:not(:first-child)'
        },
    

    That should exclude all columns but the first one. And it should completely exclude the last row, I guess. Or it will exclude the last row except for its first column. Well, you'll figure it out!
    Roland

  • Marek_OptimaMarek_Optima Posts: 32Questions: 7Answers: 0

    Thanks for your help. I did not mean that the last line to be excluded. Anyway, based on the advice, I wrote the correct selector:

    selector: 'tr td:not(:first-child)'

    Unfortunately, the error in documentation, misled me. I hope Allan will make a correction soon. Thanks again.

  • rf1234rf1234 Posts: 2,937Questions: 87Answers: 415

    :smiley: :+1:

This discussion has been closed.