Check for grid row selected in App Studio

I’m new to App Studio and trying to convert our Classic customizations to Kinetic layers in the browser (2023.2).
I have a custom grid that I’ve populated with some rows of data and when my Apply button is clicked, I want to check if the user has selected a row in the grid so I can process it. If no rows selected, I want to display an error message.
In Classic, we used this statement to make that determination:

if (gridShippingRates.Selected.Rows.Count > 0 && gridShippingRates.Selected.Rows.Count < 2)

In App Studio, I created an event (Type=Control, Hook=On Click, Target=myApplybutton) starting with a condition widget with these Properties:


When I select a row in the grid then click my Apply button, I get the following error:

main.35e9416eee557e18.js:348 function body gridShippingRates.selectedRows.length thrown exception TypeError: Cannot read properties of undefined (reading 'length')
    at eval (eval at evaluate (main.35e9416eee557e18.js:348:2704064), <anonymous>:3:39)
    at b.evaluate (main.35e9416eee557e18.js:348:2704112)
    at b.evaluateJavaScriptExpression (main.35e9416eee557e18.js:348:2710905)
    at b.parseValue (main.35e9416eee557e18.js:348:2711450)
    at x0.execute (main.35e9416eee557e18.js:348:3260588)
    at N._subscribe (main.35e9416eee557e18.js:348:2741592)
    at N._trySubscribe (main.35e9416eee557e18.js:345:193042)
    at main.35e9416eee557e18.js:345:192985
    at l (main.35e9416eee557e18.js:345:225208)
    at N.subscribe (main.35e9416eee557e18.js:345:192895)
    at main.35e9416eee557e18.js:345:215348
    at l.<anonymous> (main.35e9416eee557e18.js:345:227023)
    at main.35e9416eee557e18.js:345:192947
    at l (main.35e9416eee557e18.js:345:225208)
    at N.subscribe (main.35e9416eee557e18.js:345:192895)
    at f (main.35e9416eee557e18.js:345:212271)

main.35e9416eee557e18.js:1899 ERROR Cannot read properties of undefined (reading 'length')

In condition > Param > Expression, I have also tried replacing ## with ~~ and with %…%. Both of those give me SyntaxError: Unexpected token ‘~’/‘%’, respectively.
I also tried using == 1 instead of === 1 on all of those but received same errors.

This is what my custom grid looks like:

Does anyone have any suggestions on the correct syntax in the Condition Expression for what I’m trying to accomplish? Or maybe I’m going about this all wrong?!
Thanks for any insight,
Kelly

You could add a selector to the grid and check if any =true

AFAIK this still doesn’t work if you are using the provider model. I just tried adding the Selected column in my Grid Model → Columns and the grid just doesn’t populate anymore.

Cool, thanks for the suggestion and the links Troy! Since I’m new at this, it will take me a little time to digest all that but I will reply back when I get it working.
Thanks again for taking the time to read and reply!!
Kelly

After adding the “Selected” column to my grid, my grid now looks like this after I populate the data view.

I think that’s because I didn’t explicitly define columns in my data view (originally) that’s bound to the grid. A dataset I’m returning from a function I wrote has the columns defined instead and it’s linked to my data view in the Response Parameters on the Function call.

So, do I need to go back to the data view and explicitly define all of my columns there so they will display correctly in the grid? I just want to follow best practices and also understand what and why I’m doing it.
Thanks for any additional feedback,
Kelly

Alrighty, I got it to work by adding my other columns to the grid (not to the data view). Now working on the processing of the selected row. Baby steps!
Thanks @tjlmonty1 for pointing me in the right direction!
Kelly