Disallow selection on first and last column.

Disallow selection on first and last column.

mnash1579mnash1579 Posts: 5Questions: 2Answers: 0

Link to test case: n/a
Debugger code (debug.datatables.net): n/a
Error messages shown: n/a
Description of problem: I'm trying to figure out how to disable the row selection on the first and last column. I can successfully disable it on either but not both.

Referencing the docs here: https://datatables.net/reference/option/select.selector

select: {
    style: 'single',
    selector: 'td:not(:last-child)' // no row selection on last column
},

OR

select: {
    style: 'single',
    selector: 'td:not(:first-child)' // no row selection on first column
},

Both of these work as expected but I want to combine them. I have tried:

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

but that breaks it completely. What am I missing, any thoughts? Thanks!

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,261Questions: 26Answers: 4,934
    Answer ✓

    How about this:

    selector: 'td:not(:first-child, :last-child)
    

    http://live.datatables.net/begecowu/1/edit

    Kevin

  • mnash1579mnash1579 Posts: 5Questions: 2Answers: 0

    Amazing. Thanks for the help!

  • mnash1579mnash1579 Posts: 5Questions: 2Answers: 0
    edited November 2022

    Hi again,

    What if I also wanted to disallow selection for a row with a certain style like:

    selector: 'tr:not(.row-disabled)'
    

    Basically, I want to combine my previous request and this. So something like:

    selector: 'td:not(:first-child, :last-child) OR tr:not(.row-disabled)'
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    You can combine those into a single selector:

          selector: 'tr:not(.noExport) td:not(:first-child, :last-child)'
    

    See Ashton Cox in the example here, the class is set in the HTML,

    Colin

  • mnash1579mnash1579 Posts: 5Questions: 2Answers: 0

    Absolutely incredible. Thank you very much!

Sign In or Register to comment.