Disable a row based off of data

Disable a row based off of data

mikedmasonmikedmason Posts: 39Questions: 12Answers: 0

Hi Guys,
I have been looking for the proper way to disable or make read-only a row if it matches my criteria. So for example I have a form that will submit the pricelistid to the where clause and only returns the data that matches.

->where($key = "pricelistid",$value = $pricelistid,$op = '=')

What I would like to do is rather than filter them out with a where clause I would like to return all the rows but only allow rows that match a criteria to be edited. Still show the others but don't allow them to to be edited. If i was building the table manually I would use a variable that would pass a disable on the input field. Can this be done in datatables editor?

Thanks
Mike Mason

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    Somewhere in your code you are applying in on click event that triggers Editor, right? If so, add a class to the rows that should be read only and then use that as a way to remove the on Click event or whatever class you are using to assign the click event.

    In my case, I have inline editing on 3 columns. They get a class added call "dt-edit".

    I make them clickable with this (I call this on the dt.draw event):

        $('#example td.dt-edit').on( 'click', '', function (e) {
            var myRow = this.parentNode;
            dtEditor.inline( this,{
                buttons: { label: 'OK', fn: function () { this.submit(); }
                }
            } );
        } );
    

    and set some to read only with this.

        $("td.dt-edit-select:contains('N/A')").nextAll().removeClass("dt-edit");
    

    "dt-edit-select" is a class I put on one column that determines if it should be read only. Items that are "N/A" are read only.

  • mikedmasonmikedmason Posts: 39Questions: 12Answers: 0

    Perfect. Thanks I will give this a go.

    Thanks
    Mike Mason

This discussion has been closed.