# (Help Needed) Code selects selection tag but the data is not sorted

**URL:** <https://forum.wixstudio.com/t/help-needed-code-selects-selection-tag-but-the-data-is-not-sorted/63368>\
**Category:** Ask the community\
**Tags:** question, code, wix-studio\
**Created:** [October 8, 2024, 5:40pm UTC](https://forum.wixstudio.com/t/help-needed-code-selects-selection-tag-but-the-data-is-not-sorted/63368 "2024-10-08T17:40:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Wagenblast](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@Andrew\_Wagenblast](https://forum.wixstudio.com/u/Andrew_Wagenblast)\
**Post date:** [October 8, 2024, 5:40pm UTC](https://forum.wixstudio.com/t/help-needed-code-selects-selection-tag-but-the-data-is-not-sorted/63368/1 "2024-10-08T17:40:43Z")

</div>

Wix studio, Redirecting to our work page after selecting a text category on the home page. The page loads and selects that corresponding selection tag but the repeaters are not filtered by the selection tag unless you select and reselect the selection tag.

```javascript
import { session } from "wix-storage-frontend";

$w.onReady(function () {

    let value = session.getItem("category");

    if (value) {
        console.log("session: " + value);

        $w("#dataset1").onReady(() => {
            console.log("The dataset projects is ready");
            // Get the current item in the dynamic dataset
            let currentItem = value;

            // Get the array of values from the selection tags
            let tagOptions = $w("#selectionTags1").options;

            // Find the index of the matching value in the selection tag options
            let selectedIndex = tagOptions.findIndex(option => option.value === currentItem);

            console.log("selectedIndex: " + selectedIndex);

            // If a match is found, set it as the selected index
            if (selectedIndex !== -1) {
                $w("#selectionTags1").selectedIndices = [selectedIndex];
            }
         });
    }

    $w("#selectionTags1").onChange((event) => {
        session.clear();
        let selectedIndices = $w("#selectionTags1").selectedIndices;
        if (selectedIndices.length > 1) {
            // Deselect all but the last selected tag
            $w("#selectionTags1").selectedIndices = [selectedIndices[selectedIndices.length - 1]];
        }
    });
});
```

---

<div class="post-metadata">

**Author:** ![Andrew\_Wagenblast](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@Andrew\_Wagenblast](https://forum.wixstudio.com/u/Andrew_Wagenblast)\
**Post date:** [October 8, 2024, 6:12pm UTC](https://forum.wixstudio.com/t/help-needed-code-selects-selection-tag-but-the-data-is-not-sorted/63368/4 "2024-10-08T18:12:55Z")

</div>

Solution found

$w(“#dataset1”).refresh().then(() =\> {  
console.log("Dataset refreshed to show the correct data for: " + currentItem);  
}).catch((err) =\> {  
console.log("Error refreshing dataset: " + err);
