Disable DataTable field on change

Hello,
I have a DataTable that auto populates a column with the current users name. I'd like that field/column to become disabled (or read only) once it is auto populated. Here's my current code for the Data Table:

fd.spRendered(function() {

fd.control('DataTable1').$on('change',

function(e) {

    var username = _spPageContextInfo.userDisplayName;

    fd.control('DataTable1').value[0].Column4 = username;

});

});

Hello @ParAvion,

To disable a column in a DataTable control, use the following code:

fd.control('DataTable0').columns[0].editable = function(){return false};

Where 0 in columns[0] is the column index.

So the code will be as below, just check that the column index is correct.


fd.spRendered(function() {

fd.control('DataTable1').$on('change',

function(e) {

    var username = _spPageContextInfo.userDisplayName;

    fd.control('DataTable1').value[3].Column4 = username;

    fd.control('DataTable1').columns[3].editable = function(){return false};

});
});

Please find more information about DataTable control in our documentation here.

Hi Margarita,

Could I ask two things:

  1. Why in your code are you returning the 'false' value as a function (why not just set the value to false?)
  2. Is there a way to hide the column from view?

Hello @abolam,

  1. fd.control('DataTable1').columns[3].editable is a funsction that should return the value.

  2. You can hide the column with the following code, where i is the column index.

fd.control('DataTable0').widget.hideColumn(i);