我正在使用
Syncfusion
Angular
ejs-grid
我想制作一个专栏 required/unrequired
当我 check/uncheck
另一个复选框列。
我该如何解决这个问题?
我设置复选框列的
editparams
和其中的更改字段,以便另一列的validationRules
变为{required: true}
或{required: false}
。每次我选中或取消选中复选框列时,其他列 validationRules
应该更新。但它不起作用。
检查复选框列的编辑参数设置是否正确。它应该包括一个更改事件,该事件更新另一列的验证规则,如下面的代码。
{ field: 'checkbox', headerText: 'Checkbox', textAlign: 'Center', editType: 'booleanedit', editParams: { params: { change: (args) => { const otherColumn = args.rowData['otherColumn']; if (args.value) { otherColumn.validationRules = { required: true }; } else { otherColumn.validationRules = { }; } } } } }
复选框列是触发验证规则更改的列。选中该复选框后,所需规则将添加到 otherColumn 的 validationRules 中。取消选中时,将删除所需的规则。
检查选中或取消选中复选框时更改事件是否正确触发。你可以在 change 事件中添加一个 console.log 语句来查看它是否被调用:
{ params: { change: (args) => { console.log('Checkbox changed'); ... } } }
确保当您选中或取消选中该复选框时,console.log 语句出现在您的浏览器控制台中。
检查其他列的 validationRules 是否正确更新。选中或取消选中该复选框后,您可以检查另一列的 validationRules 以查看它是否已正确更新。您可以使用 ejs-grid 的 getColumns 方法来获取对另一列的引用:
const grid = document.querySelector('#grid').ej2_instances[0];
const otherColumn = grid.getColumnByField('otherColumn');
console.log(otherColumn.validationRules);
确保当您选中或取消选中复选框时,validationRules 正在按预期更新。
如果您仍然遇到问题,可以发帖到 Syncfusion 论坛或支持站点以获得进一步帮助。