For navigation, how to get selected row index in q-table
-
Re: get the row index in q-table
I understand that one should not rely on the row index in order to update or work with data at all. However, my goal is to actually navigate through the q-table using arrow / page keys. I found a great example of how to do that here:
https://github.com/quasarframework/quasar/pull/6598/commits/06289f5b1a9d27ee5188b9f85cce3177b7bb3cb6
The problem is, it doesn’t work because computedData isn’t there any more, and there is no suitable replacement for “computedData.rowsNumber”.
I fully understand and appreciate the desire to encourage better coding practices by prompting developers to work with their rows by ID. However, not allowing one to get the index of the current selected row prevents the developer from providing any such navigational shortcuts. The ID of the row does not help me determine which row is shown before or after it on screen. I specifically want to know about the order in which the rows are displayed and change the current selection to the previous or next row.
Since I’m using virtual scrolling, I can’t simply move the user through the dom, because (particularly on next row it seems) the elements are rerendered and thereafter the element I scrolled into view is no longer there, or is assigned to a different row.
If quasar has decided it’s too dangerous to allow us to provide this navigational feature to our users, perhaps you could add keyboard navigation as a feature of the table so that we have no need to implement it ourselves? Or perhaps just put the row index back in so this example can work and let developers sink or swim with their own decisions?
-
I would posting this dilemma you face with selected row index in q-table on Quasar’s Github has more chance on being heard.
-
Alrighty, sure thing.
-
Posted to github:
-
@jove4015 create your own index ie.
this.data = rows.map((v,i)=>({...v, index:i}))
. https://forum.quasar-framework.org/topic/4723/quasar-v1-4-4-released?_=1614301132930 -
That index doesn’t help me - when someone sorts the data in a different direction or types into the search box to add a filter, the “data” array stays the same but the order of rows changes. I need the current row index in the UI, not the data set.