No announcement yet.
  • Filter
  • Time
Clear All
new posts

    How to Select Newly Created Record in a ListGrid

    SmartClient Version: v12.1p_2020-05-04/Pro Deployment (built 2020-05-04)


    I'm having a hard time with what I assume has a simple answer, but I've scanned the docs and forums and haven't found a solution. We have a basic screen with a ListGrid of records, a DynamicForm for creating/editing a record, and buttons for new, edit, and save. When the new button is clicked, we are calling editNewReocrd() on the form. When save is clicked, we are calling saveData() on the form. All this is functioning as we'd expect.

    What we would like to do is set the ListGrid selection to the newly created record after the save button is clicked. I've seen the selectSingleRecord() method in the documentation and assume that is what we will need to use. My question is, how can I access the newly created record object to pass into selectSingleRecord()? Is this available from the form itself or will I need to fetch it explicitly from the DataSource using the primary key after the saveData() method fires?

    Any help would be greatly appreciated!


    Attached Files
    Last edited by jerickson; 5 Feb 2021, 07:13.

    What you need to do is find it within the newly updated ListGrid's data set so that you have something to pass to selectSingleRecord(). Fetching an additional copy for yourself doesn't do this. There are utility methods like findByKey(pkValue) that make this easy.


      Thanks for the help! That works out perfectly if the pkValue is manually entered and I can pull it from the form being saved, but what if the pkValue is auto-assigned on the back end when the record is saved? For instance, how would I be able to access an auto-generated ID field on a new record so I can plug it into findByKey()? Is this data available in the callback?


        Actually, I found out that I am able to pull the data from the DSResponse as an array of objects and parse out the ID from there. I think I'm good to go.

        Thanks again!