volosoft / jtable

A JQuery plugin to create AJAX based CRUD tables.
http://www.jtable.org
1.1k stars 506 forks source link

Checkbox problem #2279

Open jnbearon opened 1 year ago

jnbearon commented 1 year ago

I have a table with selection check boxes enabled.

My problem is that I do not really want the check boxes to appear on every row. So, dependent on the value in a particular column, I would like the checkbox to be either not present, or disabled.

In practice (because of the nature of the data) this will actually be every alternate row, so a "cheat" could be just to enable on alternate rows rather than by column value.

Is there a way that I can achieve this behaviour?

Thanks

Norman B

jnbearon commented 1 year ago

I managed to do it by setting checkboxes on the individual fields, rather than the whole table.

misterparsons commented 1 year ago

You can use the recordsLoaded event, which executes when the DOM for the html table has been constructed so that you can manipulate rows depending on the record data.

Here is a template for you

    recordsLoaded: function(event, data) { // executes when tha table is added to the dom before ndisplaying
    // NOTE. $(this) => "div#PeopleTableContainer(n)
        $(this).find('tbody tr').each(function () {
            record = $(this).data('record');
            if (record.your_field) == your_test ) {
                var td = $(this).find('td.jtable-selecting-column');
                td.attr('title','Selection disabled because your_reason'); // optional to show why disabled
                td.find('input').attr('disabled', true);
            }
        });
        $(this).tooltip();
    }

Just edit your_field, your_test and your_reason to make it suitable for your context.

There is more description in my tutorial