FluentUIEditableDetailsList icon indicating copy to clipboard operation
FluentUIEditableDetailsList copied to clipboard

onChange on TextField error

Open David-Rousselle opened this issue 4 years ago • 3 comments

Hello,

When i add a onChange event on my column, the whole grid crash.

Here is my column: { key: 'name', name: 'Name', text: 'Name', editable: true, dataType: 'string', minWidth: 100, maxWidth: 100, isResizable: true, includeColumnInExport: true, includeColumnInSearch: true, applyColumnFilter: true, inputType: EditControlType.TextField, onChange: this.newMethod },

and whatever I put in "newMethod", when I type something in the textbox, the grid disappear and in the console I got this error twice :

TypeError: Cannot read properties of undefined (reading 'forEach') at sg (timesheets-web-part_…2fe55e.js:2:1392297) at Xe (timesheets-web-part_…2fe55e.js:2:1432831) at We (timesheets-web-part_…2fe55e.js:2:1432291) at onChange (timesheets-web-part_…2fe55e.js:2:1442932) at t. (timesheets-web-part_…2fe55e.js:2:1203503) at dr (react-dom-16-bundle_…d7fd18cd.js:2:54474) at as (react-dom-16-bundle_…d7fd18cd.js:2:89482) at uc (react-dom-16-bundle_…7fd18cd.js:2:107135) at t.unstable_runWithPriority (react-dom-16-bundle_…dd7fd18cd.js:2:5230) at Bi (react-dom-16-bundle_…d7fd18cd.js:2:50948)

any clue ? Thanks

David-Rousselle avatar Feb 15 '22 18:02 David-Rousselle

Hello,

When i add a onChange event on my column, the whole grid crash.

Here is my column: { key: 'name', name: 'Name', text: 'Name', editable: true, dataType: 'string', minWidth: 100, maxWidth: 100, isResizable: true, includeColumnInExport: true, includeColumnInSearch: true, applyColumnFilter: true, inputType: EditControlType.TextField, onChange: this.newMethod },

and whatever I put in "newMethod", when I type something in the textbox, the grid disappear and in the console I got this error twice :

TypeError: Cannot read properties of undefined (reading 'forEach') at sg (timesheets-web-part_…2fe55e.js:2:1392297) at Xe (timesheets-web-part_…2fe55e.js:2:1432831) at We (timesheets-web-part_…2fe55e.js:2:1432291) at onChange (timesheets-web-part_…2fe55e.js:2:1442932) at t. (timesheets-web-part_…2fe55e.js:2:1203503) at dr (react-dom-16-bundle_…d7fd18cd.js:2:54474) at as (react-dom-16-bundle_…d7fd18cd.js:2:89482) at uc (react-dom-16-bundle_…7fd18cd.js:2:107135) at t.unstable_runWithPriority (react-dom-16-bundle_…dd7fd18cd.js:2:5230) at Bi (react-dom-16-bundle_…d7fd18cd.js:2:50948)

any clue ? Thanks

Hi @David-Rousselle Thanks for pointing this out. I have fixed the bug and you can find the fix in the latest PR https://github.com/microsoft/FluentUIEditableDetailsList/pull/87

However, column onChange method expects a (variablename : ICallBackParams) as argument and expects to return any[] as its return type. That was the primary reason why your UI broke. Let me explain the purpose of column onChange:- At times, as per requirements, a user may want the value of one field to change when the value of another field changes. Think of a scenario where you have 2 multiplication columns in the grid and a 3rd column called 'Result'. You may not want the Result column to be editable, but you may want its value to change on the fly when you change the values in multiplication columns. This was the reasoning behind introducing onChange functionality at column level. With this, your hooked method receives the details of the row and column that changed, and the data of your grid as a whole. Now, as a developer, you have complete flexibility to do whatever you want with the grid data/row data in the onChange method, and return the data back to the grid as a return parameter. To understand this better, you can hook the following arrow function to the onChange of your 'Name' column:-

onChange: (callbackRequestParamObj : ICallBackParams) => { callbackRequestParamObj.rowindex.forEach((index) => { callbackRequestParamObj.data.filter((item) => item.grid_row_id == index).map((item) => item.salary = 30000); }); return callbackRequestParamObj.data; }

When you run your code with this change, you will notice that when you change/edit the Name column, the Salary field for the same row becomes 30000. This is just to showcase how you can utilize the onChange. Please let me know if this helps and serves your purpose.

kushalmehrotra713 avatar Feb 16 '22 17:02 kushalmehrotra713

Thank you, I understand now better and it's a very useful possibility. However, how should I know this ? This grid seems wonderful, but I'm not sure where to find all the needed info. Thank you for "fixing" and explaining me all this so fast !

P.S: I want to use onChange to do an autocomplete, do you think it's a good way ?

David-Rousselle avatar Feb 16 '22 18:02 David-Rousselle

Thank you, I understand now better and it's a very useful possibility. However, how should I know this ? This grid seems wonderful, but I'm not sure where to find all the needed info. Thank you for "fixing" and explaining me all this so fast !

P.S: I want to use onChange to do an autocomplete, do you think it's a good way ?

Hi @David-Rousselle . Glad that you find the Grid useful. :-) For autocomplete, you can utilize the Picker control support in the Grid as it was built for just that requirement. You can explore PickerOptions to decide how you want to configure your picker.

In the example provided in this repository, you can look at column with key: 'employmenttype' to see how picker configuration works for autocomplete suggestions.

As for the documentation, there is definitely a need for in-depth feature-wise documentation. I have tried to cover most things with the Tutorial control on the demo https://editabledetailslist.azurewebsites.net/ which explains most of the features that the grid provides. The remainder of the implementation level details can be found in the repo in GridConsumer.tsx and gridConfig.tsx files to understand how the editable grid can be configured and consumed. Having said that, I do understand your requirement for having an in-depth documentation for the same. Let me try to bring something up quickly may-be on Github Wiki page. Till then, feel free to reach out if you need any help on utilization.

kushalmehrotra713 avatar Feb 18 '22 04:02 kushalmehrotra713