how can i sort a table i made with stacks?
You’ll need to introduce State variables to store the current sort state, and then in your dynamic value that is repeating the row elements based on the data array, sort the array by according to that sort state.
- At a text state variable called sortfield
- Let’s say your objects have a field called title. Add an on-click handler to the column header that sets sortfield to title
- Edit your repetition dynamic value on the rows to loop over […myDataArray].sort((a,b) => a[$state.sortfield].localeCompare(b[$state.sortfield]))