# Retrieve data from selected table row

**URL:** <https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [August 6, 2018, 12:22am UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154 "2018-08-06T00:22:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![roncarran](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roncarran/32/5534_2.png) [@roncarran](https://forum.wixstudio.com/u/roncarran)\
**Post date:** [August 6, 2018, 12:22am UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/1 "2018-08-06T00:22:05Z")

</div>

Hi. I have a collection with data, a dataset connected to that collection, and a table connected to that dataset. When a user clicks on a row of the table, I would like to retrieve the data from each of the fields of the clicked row. How do I do that? Thanks.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 6, 2018, 8:09am UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/2 "2018-08-06T08:09:21Z")

</div>

Hi,

You will need to use the [onRowSelect() event handler](https://www.wix.com/code/reference/$w.Table.html#onRowSelect) to catch the user’s click of a row. From there, you can extract the data you need. See the usage examples in the documentation.

I hope this helps,

Yisrael

---

<div class="post-metadata">

**Author:** ![roncarran](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roncarran/32/5534_2.png) [@roncarran](https://forum.wixstudio.com/u/roncarran)\
**Post date:** [August 6, 2018, 1:23pm UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/3 "2018-08-06T13:23:37Z")

</div>

Thanks, Yisrael. I find that if I use onRowSelect(), I get data from the wrong row, The only way it seems to get the correct data is by using the onClick() event handler. But, in that case, even though I get the correct data, the row doesn’t actually get highlighted and the table scrolls back to the beginning. Is there some way to visually stay on the selected row and show the user what row was selected by highlighting it?

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 6, 2018, 2:02pm UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/4 "2018-08-06T14:02:02Z")

</div>

Well, I don’t really know what you’re doing, but I tried the following code for a table and it works fine:

```javascript
export function table1_rowSelect(event, $w) {
   //Add your code for this event here:
   let rowData = event.rowData;
   console.log(rowData);
   let rowIndex = event.rowIndex;   
   console.log(rowIndex);
}

```

I put some console.log() statements in to check that I was in fact retrieving the correct row and its information. It worked perfectly.

Can you supply more information on what you’re doing (and how)?

---

<div class="post-metadata">

**Author:** ![roncarran](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roncarran/32/5534_2.png) [@roncarran](https://forum.wixstudio.com/u/roncarran)\
**Post date:** [August 6, 2018, 2:22pm UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/5 "2018-08-06T14:22:55Z")

</div>

Hi Yisrael. Yes, that’s what I’m doing, and it does select the correct data. I just wanted the table to scroll to the selected record, which I can’t get it to do. It always goes back to the first record, even if I scroll down hundreds of items and click on a row. The scrollTo() doesn’t seem to work.

export function tblBookList\_rowSelect(event, $w) {  
**let** rowData = event.rowData.title;  
**let** rowIndex = event.rowIndex;

$w(“#BookData”).text = rowData; //text box on form  
$w(“#tblBookList”).scrollTo(rowIndex); //table  
console.log(rowData);  
console.log(rowIndex);  
}

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 7, 2018, 10:10am UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/6 "2018-08-07T10:10:54Z")

</div>

The code snippet that I posted before works just fine without the need to scroll. I tried the following:

- scroll down the table

- click on a row

- the console.log() shows the data for the selected row

- the table display remains on the location of the selected row  
If you continue to have problems, please post the URL of your site. _Only authorized Wix personnel can get access to your site in the editor._

---

<div class="post-metadata">

**Author:** ![roncarran](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roncarran/32/5534_2.png) [@roncarran](https://forum.wixstudio.com/u/roncarran)\
**Post date:** [August 7, 2018, 1:03pm UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/7 "2018-08-07T13:03:24Z")

</div>

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![yaron](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yaron/32/16638_2.png) [@yaron](https://forum.wixstudio.com/u/yaron)\
**Post date:** [January 7, 2020, 11:30am UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/8 "2020-01-07T11:30:37Z")

</div>

hey Yisrael, how do i get only the value as a string instead of an object?

i want to use this string to filter another dataset, is that possible?

---

<div class="post-metadata">

**Author:** ![mauricerobson36](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mauricerobson36/32/4974_2.png) [@mauricerobson36](https://forum.wixstudio.com/u/mauricerobson36)\
**Post date:** [August 23, 2020, 10:32pm UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/9 "2020-08-23T22:32:18Z")

</div>

I have made my page and a dataset table, I am able to get the data I need from Row-1 only. So how do I select the data I want to display on my page from Row-2 and Row-3, etc.

---

<div class="post-metadata">

**Author:** ![roncarran](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roncarran/32/5534_2.png) [@roncarran](https://forum.wixstudio.com/u/roncarran)\
**Post date:** [August 24, 2020, 12:00am UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/10 "2020-08-24T00:00:48Z")

</div>

Fixed the issue. Table had wrong protection. My bad.

---

<div class="post-metadata">

**Author:** ![tdb7942](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tdb7942/32/28913_2.png) [@tdb7942](https://forum.wixstudio.com/u/tdb7942)\
**Post date:** [May 13, 2022, 11:28pm UTC](https://forum.wixstudio.com/t/retrieve-data-from-selected-table-row/3154/11 "2022-05-13T23:28:04Z")

</div>

I had a similar challenge - I would prefer a repeater nested in a repeater for several reasons including the adjusting row size. However, until that is available here is a solution that will work for me. I hope it is useful to others who use tables but struggle with the fact that the amount of data in each record varies (so it row size is never perfect for all rows). I decided I would commit to a row height of two courses (two rows of text) then use a pop-up box for those that want to read more. I used the cellSelect() event because my issue was cell by cell.

Elements I needed  
Table  
Box (text element and button go in here)  
Text Element (or rich text box in my case)  
Button

Element States  
Table: under settings → clicking selects cells  
Box: hidden, collapsed, and pinned to the center of the screen  
Text Element: disabled because mine was a rich text box and I didn’t want editing

```javascript
export function Table_cellSelect(event) {
let cellData = event.cellData;  

  $w('#box').show();
  $w('#box').expand();
  $w('#richTextBox').value = cellData; 
}
 
export function closeBox_click(event) {
    $w('#box').hide();
    $w('#box').collapse();
}

```
