I display locked fields on a editable subgrid, but it does not display in locked mode.

that's why I made a simple JavaScript code :

function gridRowSelected(context) {
context.getFormContext().getData().getEntity().attributes.forEach(function (attr) {
if (attr.getName() === "field1" || attr.getName() === "field2") {
attr.controls.forEach(function (c) {
c.setDisabled(true);
})
}
});
}

On Event : OnRecordSelected.

it work very well in subgrid but it does not work on the associated view, is there a solution ?