updateData always adds but never updates records

Answered
Nikita asked on October 8, 2024

I defined resultid key in mapping to be an id key. This is not a unique key but I need it to identify groups of records:

var mapping = {
resultid: {
type: "id"
}
};

But when I try updating it, it never does that, instead always adding to the end of the data array:

me.flexview.updateData({ data: [{...}] }, { partial: true })

The full code is provided below:

scil.Registration.ajax("flexview.getimagestructures", function (ret) {
ret.data.forEach((imgData) => {
var { resultid, compoundid, structureimage } = imgData;
var currdata = me.flexview.getReport().dataSource.data;
var entityidcolname = me.flexview.getReport().slice.rows[0].uniqueName;
var dataForUpdate = currdata.find(d => {
if (resultid > 0)
return d.resultid == resultid
else
return d[entityidcolname] == compoundid;
});
if (!scil.Utils.isNullOrEmpty(dataForUpdate)) {
dataForUpdate["structureimage"] = structureimage;
me.flexview.updateData({ data: [dataForUpdate] }, { partial: true });
}
else
console.error(`Could not find item with resultid: ${resultid} and compoundid: ${compoundid}`);
});
me.flexview.refresh();
}, { compoundids: newCompoundIdsStr });

What I am trying to do is just updating "structureimage" key for all keys "resultid" when expanding a row.

3 answers

Public
Nadia Khodakivska Nadia Khodakivska Flexmonster October 9, 2024

Hello,

Thank you for reaching out to us.

We understand your concerns and want to clarify a few things about the behavior of the partial updateData method.

Currently, this approach has limitations when updating multiple records that share the same id. In these cases, only the first matching record in the dataset will be updated, while others remain unchanged. Additionally, when using the { partial: true } option, the behavior where records are added to the end of the array happens because the partial update doesn't replace or modify existing records directly. Instead, it adds new records to the dataset if no match is found.

A possible solution would be to preprocess the data to ensure all relevant records are updated with the correct "structureimage" value. Afterward, you can use the updateData method without { partial: true } to avoid appending and ensure proper updating of all records.

You are welcome to contact us if other questions arise.

Kind regards,
Nadia

Public
Nikita October 15, 2024

The proposed solution without using { partial: true } worked great and the issue is solved!

Thank you!

Public
Maksym Diachenko Maksym Diachenko Flexmonster October 16, 2024

Hello, Nikita!

Thank you for your feedback.
We are glad to hear that the proposed solution works for you.
Please let us know if any other questions arise.

Best Regards,
Maksym

Please login or Register to Submit Answer