selecting a Datatable item from data->onStoreLoad doesn't work

https://snippet.webix.com/tlg3h5pz

I found a workaround using setTimeout, but that’s a hack, and stepping through the code shows that as is, the code does select the first item, but then the selection is erased.

Hey @dandv, you are essentially syncing your datatable with a DataCollection. In this case, the datatable gets populated with the data without calling the methods that would trigger the events from your snippet, and all of the operations on data will be performed in the DataCollection.

You can either explicitly call the select method - https://snippet.webix.com/tiqeidtg, or you can listen for an onSyncApply event - https://snippet.webix.com/ee2vf9xw.

Thanks @Dzmitry, but I posted by mistake the wrong snippet URL. Here’s the correct one (I’ve also updated the initial post):

https://snippet.webix.com/tlg3h5pz

The data->onStoreLoad even is triggered, as evidenced by the webix.message.

this.select(this.getFirstId()); does select the first element if you step through the code, but something else clears the selection immediately, so it doesn’t remain visible.

Why does the setTimeout() line make the select work?

Hey @dandv, sorry for the delayed response. I recommend you use an onSyncApply event instead, which will fire at the very end of the sync process: https://snippet.webix.com/ytlyqa40.

The reason the selection gets reset is because the component gets rerendered in-between.