render.select() but not for all rows

render.select() but not for all rows

itajackassitajackass Posts: 162Questions: 48Answers: 3

Hi, is it possible to exclude some rows from being selectable, by NOT RENDERING the checkbox?

Actually I use this piece of code:

      {
                orderable: false,
                render: DataTable.render.select(),
                className: 'dt-select',
                targets: 0
            }, ...

But this code create a checkbox for ALL rows.
I'd like instead NOT RENDERING the checkbox when a row has a specific class, for example ("hide-select" class):

<tr><td></td><td>Some data</td></tr>
<tr><td></td><td>Some data</td></tr>
<tr class="hide-select"><td></td><td>This is a non checkable row</td></tr>
<tr><td></td><td>Some data</td></tr>

Then workaround is using this, but the checkbox is rendered and disabled then:

table.on('select', function(e, dt, type, indexes) {
  if (type === 'row') {
    var rows = table.rows(indexes).nodes().to$();
    $.each(rows, function() {
      if ($(this).hasClass('hide-select')) table.row($(this)).deselect();
    })
  }
});

Answers

  • rf1234rf1234 Posts: 2,975Questions: 87Answers: 421

    Use "rowCallback" and hide the checkbox whenever the row has class 'hide-select'.

    Here is an example which is slightly different. I don't use a checkbox for select but I also want to exclude certain rows from being selected.

    select: {
        style: 'single',
        selector: 'tr.selectRow td:not(:first-child)'
    },
    
    rowCallback: function (row, data) {
        //if it is not the summation row the row should be selectable
        if ( data.cashflow.position !== 'L' ) {
            $(row).addClass('selectRow');
        }
    }
    
Sign In or Register to comment.