Updating a datatable: how get find an existing entry?

Assuming I have a datatable instance with a column defined like this

{ id: “index”, header: “Index”, width: 60 },

I send an update via JSON like this:

{ “index”: 2, “x”: 0.0, “y”: 0.0 }

How do I get the rowid of the row containing the index value of 2?

TIA

Amazing. I post a question then find a work-around. This works if the row index == record id. However it would be nice to have an efficient ‘find()’ function explained. TIA

// jdata is row of data as JSON.
let uid = table.getIdByIndex(jdata.recid);
if (uid === undefined)
{
// new
table.add(jdata);
}
else
{
// exists so simply update
table.updateItem(uid,jdata);
}

there is find method in datatable
https://docs.webix.com/api__link__ui.datatable_find.html

let old = table.find(obj=>obj.index == jdata.index, true/*first*/);
if(old){
    table.updateItem(old.id, jdata);
}else{
    table.add(jdata);
}
1 Like

@intregal very good to know thank you. Adding that to the find() example would be helpful I think.

so should that actually be:

let old =
table.find(function(obj){ obj=>obj.index == jdata.index, true/first/});

?