Data Grid, onChangeItem GridItemChangeEvent - why no dataIndex?

1 Answer 67 Views
Grid
Brent
Top achievements
Rank 1
Brent asked on 13 Sep 2024, 11:18 PM

I threw together the easy "patch-package" on latest v8.2.0 below and it worked.

But it seems like the developers must have excluded this value for a reason that i should watch out for?

Or if not, any chance we can get it added officially?

my underlying motivation: I see in all the onItemChange demos the suggested "change item" approach is to iterate the data array via .map() and change the corresponding object item based on matching a unique id property... of course this is a longstanding pattern that honors React's need for immutability, but once lists get large, there's a performance hit that could be avoided by directly targeting the item by index along with other immutability/copying approaches, e.g. toSpliced() is now available in modern browsers.

I have an active license and I could submit bug/feature if this is better requested thru that channel.

diff --git a/node_modules/@progress/kendo-react-grid/Grid.mjs b/node_modules/@progress/kendo-react-grid/Grid.mjs
index ff03785..3f6cb09 100644
--- a/node_modules/@progress/kendo-react-grid/Grid.mjs
+++ b/node_modules/@progress/kendo-react-grid/Grid.mjs
@@ -191,7 +191,8 @@ const z = class z extends r.Component {
           ...this.getArguments(e.syntheticEvent),
           dataItem: e.dataItem,
           field: e.field,
-          value: e.value
+          value: e.value,
+          dataIndex: e.dataIndex
         }
       );
     }, this.onHeaderSelectionChange = (e) => {


1 Answer, 1 is accepted

Sort by
0
Accepted
Yanko
Telerik team
answered on 17 Sep 2024, 08:40 AM

Hi, Brent,

Thank you for the shared information and code.

There is no particular reason why the `dataIndex` has not been included as an argument of the GridItemChangeEvent. Upon your request, we will expose it in a future release. You can follow our change log for changes made in the next versions:

If you need further assistance with the matter, please let me know.

Regards,
Yanko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Brent
Top achievements
Rank 1
commented on 17 Sep 2024, 02:25 PM | edited

Very nice. Thank you.

Not to be too demanding, but maybe you could consider updating a demo to highlight the new possibility along with releasing this enhancement?

For others landing here, this enhancement will mean we can go from the following common array.map() pattern in the demos:

onItemChange = (event) => {
const editedItemID = event.dataItem.ProductID;
 const data = this.state.data.map(item =>
        item.ProductID === editedItemID ? {...item, [event.field]: event.value} : item
    );
    this.setState({ data });
};

To something like this:

onItemChange = e => this.setState({ data.with(e.dataIndex, { ...e.dataItem, [e.field]: e.value} });

references:

Yanko
Telerik team
commented on 18 Sep 2024, 07:36 AM

Hi, Brent,

Thank you very much for the suggestion, we highly appreciate it. I have logged this in our private repo to be planned and executed in a future release.

Tags
Grid
Asked by
Brent
Top achievements
Rank 1
Answers by
Yanko
Telerik team
Share this question
or