Disable row selection

Disable row selection

nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

Hi!
One more question.... I have the following conditional code:
```{

                    "data": "cdi_calendar_changes.active",
                           "render": function (val, type, row) {
                               return val == 0 ?
                                  "<font color=red><b>LOCKED</b></font>"  : "<input type=checkbox className=select-checkbox>"

                               orderable: false
                           }
                       },```

Problem is that the row that displays the Locked message can still be selected. But I need the selection functionality disabled.
Any suggestion?

Thanks!

Answers

  • HPBHPB Posts: 73Questions: 2Answers: 18
    edited June 2017

    In your event listener for row selection you can add something like:

    if (row.data().cdi_calendar_changes.active == 0)
      return false;
    
  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    select.style() can be used to disable the selection of rows by setting it to be none.

    Allan

  • nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

    Hi Allan,

    I get a style undefined error. Tried:
    ```{

                        "data": "cdi_calendar_changes.active",
    
                               "render": function (val, type, row) {
                                   return val == 0 ?
                                       select.style('none') : select.style('os')
    
                                   orderable: false
                               }
                           },```
    
  • nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

    Ok, think I am close with what I was trying to do HPB's suggestion. :)

    ```"rowCallback": function (row, data, dataIndex) {

                        if (data.cdi_address_book_relationships.active == "0") {
                            $('td', row).css('backgroundColor', '#f8c4c4');
                            $('td', row).removeClass('select-checkbox');
    
                        }
                    },```
    

    That code removes the checkbox. But I can still select the row. Tried to use the select style suggestion but it just makes the row not visible in my table. Also tried disable.

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Oh I see! You want to do it on a per row basis, depending on the data in the row, rather than disabling row selection for the whole table?

    If so, then the user-select event is the way to do it.

    Allan

  • nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

    Hi Allan,

    Yes. I want to disable selection if the content in the cell that contains the value for cdi_address_book_relationships.active is 0

    Please excuse my ignorance but I don't really understand the user-select function.

    The example has a disable if 'img' is contained but its not really what I am after. Once I strip the class on the rowcallback, there isn't anything there but I can still select the cell and open the editor.

    Based on your suggestion, I tried:

    table.on('user-select', function (e, dt, type, cell, originalEvent) {
               if (originalEvent.target.nodeName.toLowerCase() === '') {
                   e.preventDefault();
               }
           });
    

    But it still allowed me to select the empty cell and open the editor.

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Try:

    table.on('user-select', function (e, dt, type, cell, originalEvent) {
      var row = dt.row( cell.index().row );
    
      if ( row.data().cdi_address_book_relationships.active == 0 ) {
        e.preventDefault();
      }
     });
    

    Allan

  • nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

    Hi Allan,

    Sorry, I should have posted that one too. I did try that before. Still allowed me to select the cell.

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    If you post a link to the page showing the issue I can take a look into it.

    Thanks,
    Allan

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Is the page available online somewhere so I can see it running including all required resources please?

    Allan

  • nicoledramirez@hotmail.comnicoledramirez@hotmail.com Posts: 60Questions: 14Answers: 2

    No. I can't make the live version available. It's confidential info.

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Can you send me it as a PM so that it isn't public?

    Allan

This discussion has been closed.