disabling selection checkboxes on certain rows only

disabling selection checkboxes on certain rows only

gib65gib65 Posts: 29Questions: 13Answers: 0

Hello,

I have a datatable with selection checkbox at the front of each row:

Some rows need to be disabled, meaning that the user should not be able to check the selection checkboxes. I'm not sure how to do this.

My first attempt was to do this:

    var table = $('#projectTable');
        for (var index = 1; index < table[0].rows.length; index++)
        {
            var row = table[0].rows[index];
            var phaCheckbox = $(row.cells[11]).find('input');
            var profilerCheckbox = $(row.cells[12]).find('input');

            if (!phaCheckbox.is(':checked') || !profilerCheckbox.is(':checked'))
            {
                $(row.cells[0]).removeClass('select-checkbox');
            }
        }

...but this only works on the rows on the current page. If I flip to another page, the checkboxes are still there on rows that shouldn't have them.

Then my next attempt was to do this:

    var table = $('#projectTable').DataTable();
        table.rows().every(function(index, tableLoop, rowLoop) {
            var phaCheckbox = $(this.data()[11]);
            var profilerCheckbox = $(this.data()[12]);
            if (!phaCheckbox.is(':checked') || !profilerCheckbox.is(':checked')) {
                this.cell(index,0).removeClass('select-checkbox');
            }
        });

...but this.cell(index,0) doesn't give me an object on which I can call removeClass(...).

What I'd like is this: to be able to remove or disable the selection checkboxes on rows that shouldn't have them, and for this to be done on all pages. Can anyone help?

Answers

  • felimartinafelimartina Posts: 4Questions: 0Answers: 0

    Hi! did you ever workaround this?

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    where are you creating the checkbox now? It should be part of the render function where you have access to the data for the row and can add the disabled property to the checkbox.

This discussion has been closed.