Applying a sort or filter to a dataset

I have a handful of input elements linked to a dataset on my page, which is connected to a database table. I also have buttons to scroll through the data. This all works as expected. When I open the page the first record is displayed.
What I’d like to do is allow the user to apply a sort. However, when I try to apply a sort from an event handler, such as this:
export function sortButton_click(event) {
$w( “#ContractorsDataset” ).onReady(() => {
$w( “#ContractorsDataset” ).setSort( wixData.sort()
.ascending( “City” ))…
then the display changes to show a different row, and I can’t figure out why it is showing the row it does. It doesn’t seem to be sorted, as I scroll through it. Calling refresh() doesn’t seem to help.

Additionally, I’d like to allow the user to apply a filter. For example,
export function filterButton_click(event) {
$w( “#ContractorsDataset” ).onReady(() => {
$w("# ContractorsDataset ").setFilter( wixData.filter().startsWith(‘City’, ‘A’))…
The behavior here is even worse. All input elements are disabled, and when I query the count of dataset items after applying the filter, it is 0. Am I doing something wrong? Is this functionality not supported? Do I have to write the table / dataset interface and hand-roll the queries?

Any insight appreciated.

Try " c ity" instead of " C ity".

J.D.,

Thank you for that quick and insightful response. Sure enough, I was confusing the Field Name with the Field Key. That did the trick on both counts. I wish I had asked earlier! Thanks again!